You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
1.9 KiB
89 lines
1.9 KiB
using EC.UsingEventAggregator;
|
|
using Prism.Commands;
|
|
using Prism.Events;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using System.Collections.Specialized;
|
|
|
|
namespace ECMonitor.Code.Models
|
|
{
|
|
public class BaseModel : BindableBase
|
|
{
|
|
public IRegionManager _regionManager { get; set; }
|
|
public IEventAggregator _ea { get; set; }
|
|
|
|
private string _title = "";
|
|
|
|
public string Title
|
|
{
|
|
get { return _title; }
|
|
set { SetProperty(ref _title, value); }
|
|
}
|
|
|
|
public DelegateCommand<string> SendMessageCommand { get; private set; }
|
|
|
|
public BaseModel(IRegionManager regionManager, IEventAggregator ea)
|
|
{
|
|
_regionManager = regionManager;
|
|
_ea = ea;
|
|
_regionManager.Regions.CollectionChanged += Regions_CollectionChanged;
|
|
|
|
SendMessageCommand = new DelegateCommand<string>(SendMessage);
|
|
_ea.GetEvent<ShowMessageSentEvent>().Subscribe(MessageReceived);
|
|
}
|
|
|
|
public virtual void Regions_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
if (e.Action == NotifyCollectionChangedAction.Add)
|
|
{
|
|
var region = (IRegion)e.NewItems[0];
|
|
region.Views.CollectionChanged += Views_CollectionChanged;
|
|
}
|
|
}
|
|
|
|
public virtual void Views_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
if (e.Action == NotifyCollectionChangedAction.Add)
|
|
{
|
|
}
|
|
else if (e.Action == NotifyCollectionChangedAction.Remove)
|
|
{
|
|
}
|
|
}
|
|
|
|
public virtual void SendMessage(string message)
|
|
{
|
|
SendMessage(new LogModel(1, message));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送消息
|
|
/// </summary>
|
|
/// <param name="log"></param>
|
|
public virtual void SendMessage(LogModel log)
|
|
{
|
|
_ea.GetEvent<ShowMessageSentEvent>().Publish(log);
|
|
}
|
|
|
|
public virtual void MessageReceived(LogModel log)
|
|
{
|
|
//Messages.Add(message);
|
|
}
|
|
|
|
#region 日志
|
|
|
|
public void Debug(string message)
|
|
{
|
|
}
|
|
|
|
public void Info(string message)
|
|
{
|
|
}
|
|
|
|
public void Error(string message)
|
|
{
|
|
}
|
|
|
|
#endregion 日志
|
|
}
|
|
}
|