using Bro.Common.Helper; using Bro.Common.Interface; using System; using System.Reflection; using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; namespace Bro.UI.Model.Winform { public partial class MenuFrmBase : DockContent, IMenuNode, IProcessObserver, ILogOutput { public Action OnUploadProcess { get; set; } public Action 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(); 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 protected override string GetPersistString() { var attr = this.GetType().GetCustomAttribute(); if (attr == null) { return base.GetPersistString(); } return $"MenuFrm,{attr.MenuCode},{attr.MenuName}"; } } }