示例#1
0
        /// <summary>
        /// 构造函数。
        /// </summary>
        public CtrlSysEvents()
        {
            InitializeComponent();
            this.CreateHandle();

            GlobalMessageBus.SubscribeNewSystemEventGenerated(OnNewSystemEventGenerated);
        }
示例#2
0
        private void btnGenerateOperationLog_Click(object sender, EventArgs e)
        {
            try
            {
                Task.Factory.StartNew(() =>
                {
                    var log = new OperationLog();
                    // 新的操作记录,编号必须为零。
                    log.UserName             = GlobalServices.UAC.CurrentUserName;
                    log.IsManual             = DateTime.Now.Second % 2 == 0;
                    log.OperationDescription = "Operation X";
                    log.OperationType        = OperationType.OperationX;
                    log.TargetDeviceCode     = (uint)DateTime.Now.Second;
                    log.ResultDescription    = "已发送";

                    // 发布消息。
                    var args = new OpeationLogCreateOrUpdateEventArgs(log);
                    GlobalMessageBus.PublishOperationLogChanged(args);

                    // 延时2秒,产生一个确认。
                    Thread.Sleep(2000);
                    log.ResultDescription = "已执行";
                    log.ResultTimestamp   = log.Timestamp + TimeSpan.FromSeconds(10);
                    log.ResultType        = DateTime.Now.Second % 2 == 0 ? OperationResult.Success : OperationResult.Failure;
                    GlobalMessageBus.PublishOperationLogChanged(args);
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private void btnGenerateSysEvent_Click(object sender, EventArgs e)
        {
            try
            {
                // 模拟产生一个系统日志;系统将显示此日志并进行持久化。
                var log = new SysEventLog(EventType.CommRecovery, EventLevel.First, "节点 A 与节点 B 通信恢复。");
                GlobalMessageBus.PublishNewSystemEventGenerated(new NewSystemEventArgs(log));

                // 模拟产生一个系统日志;系统将显示此日志并进行持久化。
                log = new SysEventLog(EventType.CommInterruption, EventLevel.Third, "节点 A 与节点 B 通信中断。");
                GlobalMessageBus.PublishNewSystemEventGenerated(new NewSystemEventArgs(log));

                // 模拟产生一个通信中断消息;系统将显示此消息并自动产生一个系统日志;然后持久化。
                var args = new CommStateChangedEventArgs(false, NodeType.Node1, 16, NodeType.Node2, 18);
                GlobalMessageBus.PublishCommStateChanged(args);

                // 查询
                log = GlobalServices.Repository.Where <SysEventLog>(p => p.Code == log.Code).FirstOrDefault();
                LogUtility.Info("{0}", log);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#4
0
        private void CommStateChecker_DataValidityChanged(object sender, DataValidityChangedEventArgs <string> e)
        {
            try
            {
                if (this.PublishCommStateChanged)
                {
                    var tmpData    = e.Data.ToUInt32Array(10);
                    var localCode  = tmpData[0];
                    var remoteCode = tmpData[1];

                    var remoteType = this.GetRemoteType(remoteCode);

                    var args = new CommStateChangedEventArgs(e.Avaliable, this.LocalType, localCode, remoteType, remoteCode);
                    GlobalMessageBus.PublishCommStateChanged(args);

                    if (this.CommStateChanged != null)
                    {
                        this.CommStateChanged(this, args);
                    }
                }
            }
            catch (Exception /*ex*/)
            {
            }
        }
        private void OnCommStateChanged(object sender, CommStateChangedEventArgs args)
        {
            try
            {
                var remoteNode = GlobalServices.Repository.Where <SystemNode>(p => p.Code == args.RemoteNodeCode).FirstOrDefault();

                //  产生事件。
                var eventLog = new SysEventLog();
                eventLog.TypeCode = args.CommState.GetValueOrDefault() ? EventType.CommRecovery : EventType.CommInterruption;
                eventLog.Level    = GlobalServices.SEM.GetEventLevel(eventLog.TypeCode);

                var nodeName = remoteNode == null?string.Format("{0}", args.RemoteNodeCode) : string.Format("{0}_{1}", args.RemoteNodeCode, remoteNode.Name);

                if (args.CommState.GetValueOrDefault())
                {
                    eventLog.Description = string.Format("本节点与远程节点({0})通信恢复。", nodeName);
                }
                else
                {
                    eventLog.Description = string.Format("本节点与远程节点({0})通信中断。", nodeName);
                }

                // 发布事件
                GlobalMessageBus.PublishNewSystemEventGenerated(new NewSystemEventArgs(eventLog));
            }
            catch (System.Exception ex)
            {
                LogUtility.Error(ex);
            }
        }
示例#6
0
        /// <summary>
        /// 构造函数。
        /// </summary>
        public CtrlOperationRecord()
        {
            InitializeComponent();
            this.CreateHandle();

            this.InitalizeDataGridView();

            GlobalMessageBus.SubscribeOperationLogChanged(OnNewOperatonLog);
        }
        public TopMemuItemProvider(ILoginVerification loginVerify, IUserAccessControl uac, IUserManagement userManagement)
        {
            this.LoginVerify = loginVerify ?? throw new ArgumentException("登录验证接口不能为空引用。");
            this.UAC         = uac;
            _userManager     = userManagement;

            this.InitializeMenu();

            this.AddDisposable(GlobalMessageBus.SubscribeUserChanged(OnUserChanged));
        }
示例#8
0
 /// <summary>
 /// 工具 - 滚动日志
 /// </summary>
 private void OnMenuToolRolloverLog(object sender, EventArgs e)
 {
     try
     {
         GlobalMessageBus.PublishCommLogRollover(e, sender);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#9
0
        /// <summary>
        /// 构造函数。
        /// </summary>
        public CommStreamStorage(ushort logExpiredDays = 10)
        {
            this.LogExpiredDays = logExpiredDays;

            // 初始化缓存池。
            _logCache.ProductCreated += OnProductCreated;
            _logCache.Open();

            // 订阅菜单项消息
            GlobalMessageBus.SubscribeCommLogRollover(OnRolloverCommLog);
            GlobalMessageBus.SubscribeCommLogCreated(OnCommStreamCreated);
        }
示例#10
0
        protected void SetConnectionState(bool connected)
        {
            if (this.Connected != connected)
            {
                LogUtility.Info("数据源 {0} 状态发生变化,原连接状态= {1},新连接状态={2}。", this.DataSource.Name, this.Connected, connected);

                //
                var args = new DbSourceStateChangedEventArgs(this.DataSource.Name, connected);
                GlobalMessageBus.PublishDbSourceStateChanged(args);
            }

            //
            this.Connected = connected;
        }
示例#11
0
        private void OnOwnerViewLoad(object sender, EventArgs e)
        {
            try
            {
                // 订阅用户切换事件。
                GlobalMessageBus.SubscribeUserChanged(OnUserChanged);

                // 更新状态栏。
                this.UpdateStatusBar();
            }
            catch (Exception ex)
            {
                LogUtility.Error(ex);
            }
        }
示例#12
0
        private void PerformLoad()
        {
            //this.DesktopBounds = new Rectangle(0, 0, Screen.AllScreens.Sum(p => p.Bounds.Width),
            //    Screen.AllScreens.Min(p => p.Bounds.Height));

            // 设置主窗口标题
            if (string.IsNullOrWhiteSpace(GlobalServices.NodeContext.Name))
            {
                this.Text = GlobalServices.SysAttribute.ProjectChsName;
            }
            else
            {
                this.Text = string.Format("{0} - {1}", GlobalServices.NodeContext.Name, GlobalServices.SysAttribute.ProjectChsName);
            }

            // 构建需要优化的控件集
            _controlOptimizers = Workbench.MainWorkspace.SmartParts.OfType <IControlOptimizer>().ToList();

            // 构造DockContents
            this.CreateDockContents();

            // 订阅用户切换事件。
            GlobalMessageBus.SubscribeUserChanging(OnUserChanging);
            GlobalMessageBus.SubscribeUserChanged(OnUserChanged);

            // 显示DockContents。
            var configFile = BuildDockConfigFileName();

            if (File.Exists(configFile))
            {
                try
                {
                    _dockPanel.LoadFromXml(configFile, DeserializeDockContentCallback);
                }
                catch (Exception /*ex*/)
                {
                    File.Delete(configFile);
                    this.ResetWindowsLayout();
                }

                this.HideNonPermissionContents();
            }
            else
            {
                // 更新DockContent
                this.UpdateDockContents();
            }
        }
        public void Logoff()
        {
            if (_currentUser.Id == UserInfo.GuestID)
            {
                throw new Exception("无法注销Guest用户。");
            }

            // 发布用户将要切换事件。
            GlobalMessageBus.PublishUserChanging(new EventArgs());

            // 切换用户。
            _currentUser.Name = "Guest";
            _currentUser.Id   = UserInfo.GuestID;
            _currentUser.Privileges.Clear();

            // 发布用户切换事件。
            GlobalMessageBus.PublishUserChanged(new EventArgs());
        }
示例#14
0
        /// <summary>
        /// 在全局消息总线上发布通信日志产生事件。
        /// </summary>
        protected void PublishCommLogCreateEvent(NodeType localType, uint localCode,
                                                 NodeType remoteType,
                                                 uint remoteCode, bool isIncoming, byte[] data)
        {
            try
            {
                if (!this.PublishCommLogCreated)
                {
                    return;
                }

                var args = new CommLogCreatedEventArgs(localType, localCode, remoteType, remoteCode, isIncoming, data);
                GlobalMessageBus.PublishCommLogCreated(args);
            }
            catch (Exception)
            {
            }
        }
示例#15
0
 /// <summary>
 /// 在全局消息总线上发布数据传输事件。
 /// </summary>
 protected void PublishDataTransferEvent(NodeType localType, uint localCode,
                                         NodeType remoteType, uint remoteCode,
                                         bool isIncoming, byte[] data)
 {
     try
     {
         if (isIncoming && this.PublishDataIncoming)
         {
             var args = new DataIncomingEventArgs(data, localType, localCode, remoteType, remoteCode);
             GlobalMessageBus.PublishDataIncoming(args, this);
         }
         else if (!isIncoming && this.PublishDataOutgoing)
         {
             var args = new DataOutgoingEventArgs(data, localType, localCode, remoteType, remoteCode);
             GlobalMessageBus.PublishDataOutgoing(args, this);
         }
     }
     catch (Exception)
     {
     }
 }
        public void LogOn(string userName, byte[] pwdActual)
        {
            if (string.Equals(userName, _currentUser.Name, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("用户名相同,无需切换。");
            }

            //
            var theUser = _userMgr.GetUser(userName);

            if (theUser == null)
            {
                throw new Exception("指定的用户不存在。");
            }

            if (!HelperTool.BytesEquals(theUser.Password, pwdActual))
            {
                throw new Exception("密码不正确。");
            }

            // 发布用户将要切换事件。
            GlobalMessageBus.PublishUserChanging(new EventArgs());

            // 更新用户。
            _currentUser.Id   = theUser.Code;
            _currentUser.Name = theUser.Name;
            if (theUser.Privileges != null)
            {
                _currentUser.Privileges = theUser.Privileges.ToList();
            }
            else
            {
                _currentUser.Privileges.Clear();
            }

            // 发布用户切换事件。
            GlobalMessageBus.PublishUserChanged(new EventArgs());
        }
示例#17
0
        /// <summary>
        /// 运行
        /// </summary>
        private void Run()
        {
            try
            {
                SubscribeSystemEvents();

                // 系统预检查
                PreCheck();

                // 注册COM控件。
                RegisterCOM();

                InitializeLogSystem();

                GlobalMessageBus.SubscribeApplicationExiting(OnProcessKillingForcedly);

                _framework.Init();
                _framework.Start();
                _framework.WaitForStop();
            }
            catch (TargetInvocationException ex)
            {
                LogManager.GetLogger(LoggerNames.Platform).Error(ex.InnerException);
                MessageBox.Show(ex.InnerException.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(LoggerNames.Platform).Error(ex);
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                LocalMessageBus.Current.RemoveAll();
                ShutdownLogSystem();
                ThreadProxy.Shutdown();
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            }
        }
示例#18
0
        private void confirmAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var timeNow = DateTime.Now;
                var rows    = dataGridView.Rows;

                for (var i = 0; i < rows.Count; i++)
                {
                    var theLog         = rows[i].Tag as SysEventLog;
                    var confirmEnabled = GlobalServices.SEM.GetConfirmEnabled(theLog.TypeCode);
                    if (confirmEnabled && !theLog.IsConfirmed)
                    {
                        theLog.ConfirmTime = timeNow;
                        GlobalMessageBus.PublishNewSystemEventGenerated(new NewSystemEventArgs(theLog));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#19
0
        private void OnOwnerViewLoad(object sender, EventArgs e)
        {
            try
            {
                // 订阅用户切换事件。
                GlobalMessageBus.SubscribeUserChanged(OnUserChanged);

                // 加载插件菜单。
                this.LoadPluginsMenu();

                // 加载Debug菜单。
                this.LocadDebugMenu();

                // 创建View子菜单。
                this.CreateViewSubmenu();

                // 更新View子菜单。
                this.UpdateViewSubMenu();
            }
            catch (Exception ex)
            {
                LogUtility.Error(ex);
            }
        }
 public PersistenceProcessor()
 {
     this.AddDisposable(GlobalMessageBus.SubscribeNewSystemEventGenerated(OnNewSystemEventGenerated));
     this.AddDisposable(GlobalMessageBus.SubscribeOperationLogChanged(OnNewOperLogGenerated));
 }
示例#21
0
 private void OnProcessKilling()
 {
     GlobalMessageBus.PublishApplicationExiting(new ProcessExitingEventArgs(), null);
 }
 public NodeCommEventGenerator()
 {
     this.AddDisposable(GlobalMessageBus.SubscribeCommStateChanged(OnCommStateChanged));
 }