using PLCSharp.Models;
using Prism.Dialogs;
using Prism.Events;
using Prism.Ioc;
using Prism.Mvvm;
using System.ComponentModel.DataAnnotations.Schema;
namespace PLCSharp.Core.Prism
{
///
/// 模型Base
///
public class ModelBase : BindableBase
{
///
/// _EventAggregator
///
protected readonly IEventAggregator _EventAggregator;
///
/// 对话框服务
///
[NotMapped]
public readonly IDialogService _dialogService;
///
/// _container
///
[NotMapped]
public readonly IContainerExtension _container;
///
/// _DatasContext
///
[NotMapped]
public DatasContext _DatasContext { get; set; }
///
/// 模型Base
///
public ModelBase(IContainerExtension container, IEventAggregator ea, IDialogService dialogService)
{
_container = container;
_DatasContext = container.Resolve();
_EventAggregator = ea;
_dialogService = dialogService;
AppDomain.CurrentDomain.ProcessExit += OnExit;
}
///
/// OnExit
///
/// sender
/// e
protected virtual void OnExit(object sender, EventArgs e)
{
}
///
/// 发送消息到事件总线
///
/// 消息
/// 消息类型 1 记录 2 弹出 3 弹出并记录,4 弹出确认框
public void SendErr(string msg, ShowType type, ErrType errType)
{
_EventAggregator.GetEvent().Publish(new()
{
ErrType = errType,
Type = type,
Target = "errLog",
Content = msg
});
}
///
/// 发送故障信息
///
/// msg
public void SendErr(string msg )
{
SendErr(msg, ShowType.Record, ErrType.Error);
}
///
/// 发送弹出故障消息
///
/// msg
public void SendErrDialog(string msg)
{
SendErr(msg, ShowType.ShowDialogAndRecord, ErrType.Error);
}
///
/// 发送普通记录信息
///
/// msg
public void SendInfo(string msg)
{
SendErr(msg, ShowType.Record, ErrType.Info);
}
///
/// 发送弹出消息
///
/// msg
public void SendInfoDialog(string msg)
{
SendErr(msg, ShowType.ShowDialogAndRecord, ErrType.Info);
}
}
}