using Bro.Common.Helper;
|
using Bro.Common.Interface;
|
//using Bro.UI.Config.Helper;
|
using System;
|
using System.Reflection;
|
using System.Windows.Forms;
|
using WeifenLuo.WinFormsUI.Docking;
|
|
namespace Bro.UI.Config.MenuForms
|
{
|
public interface IMenuNode
|
{
|
//IProcess Process { get; set; }
|
|
//void DownloadProcess(IProcess process);
|
//Action<IProcess> OnUploadProcess { get; set; }
|
}
|
|
public interface IProcessObserver
|
{
|
IProcess Process { get; set; }
|
|
void OnProcessUpdated();
|
void DownloadProcess(IProcess process);
|
}
|
|
public interface ILogOutput
|
{
|
Action<LogMsg> OnLogMsgOutput { get; set; }
|
void LogDisplay(LogMsg msg);
|
}
|
|
public partial class MenuFrmBase : DockContent, IMenuNode, IProcessObserver, ILogOutput
|
{
|
public Action<string, IProcess> OnUploadProcess { get; set; }
|
public Action<LogMsg> OnLogMsgOutput { get; set; }
|
public string Id { get; set; } = Guid.NewGuid().ToString();
|
|
private IProcess process = null;
|
|
public IProcess Process
|
{
|
get => process;
|
set
|
{
|
//if (process != value)
|
{
|
process = value;
|
OnProcessUpdated();
|
}
|
}
|
}
|
|
public MenuFrmBase()
|
{
|
InitializeComponent();
|
|
var dockAttr = GetType().GetCustomAttribute<DockOptionAttribute>();
|
if (dockAttr != null)
|
{
|
FormClosing += MenuFrmBase_FormClosing;
|
}
|
}
|
|
protected virtual void MenuFrmBase_FormClosing(object sender, FormClosingEventArgs e)
|
{
|
if (e.CloseReason != CloseReason.MdiFormClosing)
|
{
|
e.Cancel = true;
|
|
if (DockHandler.DockPanel != null)
|
Hide();
|
}
|
}
|
|
#region IProcessObserver
|
public virtual void OnProcessUpdated()
|
{
|
}
|
|
public virtual void DownloadProcess(IProcess process)
|
{
|
Process = process;
|
}
|
#endregion
|
|
#region ILogOutput
|
public virtual void LogDisplay(LogMsg msg)
|
{
|
}
|
|
protected virtual void LogAsync(LogMsg msg)
|
{
|
OnLogMsgOutput?.Invoke(msg);
|
}
|
|
protected virtual void LogAsync(DateTime dt, string prefix, string msg = "")
|
{
|
OnLogMsgOutput?.Invoke(new LogMsg(dt, prefix, msg));
|
}
|
#endregion
|
|
#region Login
|
protected bool IsLogin { get; set; }
|
|
public virtual void SetLoginStatus(bool isLogin)
|
{
|
IsLogin = isLogin;
|
}
|
#endregion
|
}
|
}
|