/// <summary>
        /// 执行
        /// </summary>
        public override RunCommandResult Execute()
        {
            try
            {
                RefreshCommandQueueStatus refreshStatus = RefreshCommandQueueStatus.Refreshing;

                if (CommandQueueScanManger.IsStopCommandQueue())
                {
                    refreshStatus = RefreshCommandQueueStatus.NoRefresh;
                }
                else
                {
                    bool isStop = CommandQueueScanManger.StopScanCommandQueue();
                    if (isStop)
                    {
                        refreshStatus = RefreshCommandQueueStatus.NoRefresh;
                    }
                    else
                    {
                        refreshStatus = RefreshCommandQueueStatus.Refreshing;
                    }
                }
                var r = NodeProxy.PostToServer <EmptyResponse, UpdateNodeRefreshCommandQueueStatusRequest>(ProxyUrl.UpdateNodeRefreshCmdQueueStatus_Url, new UpdateNodeRefreshCommandQueueStatusRequest()
                {
                    NodeId = int.Parse(this.AppConfig["nodeid"]), Source = (Source)int.Parse(this.AppConfig["source"]), RefreshStatus = refreshStatus
                });
                if (r.Status != ResponesStatus.Success)
                {
                    ShowCommandLog("停止节点刷新命令队列失败,服务器返回:" + JsonConvert.SerializeObject(r));
                }
                //添加日志
                ShowCommandLog("停止节点刷新命令队列成功");
                return(new RunCommandResult()
                {
                    ExecuteStatus = ExecuteStatus.ExecuteSucess
                });
            }
            catch (Exception ex)
            {
                ShowCommandLog("停止节点刷新命令队列失败,异常信息:" + JsonConvert.SerializeObject(ex));
                return(new RunCommandResult()
                {
                    ExecuteStatus = ExecuteStatus.ExecuteException, Ex = ex, Message = ex.Message
                });
            }
        }
Exemple #2
0
        public void Stop()
        {
            try
            {
                OnInit("----------------------" + DateTime.Now + ":停止节点开始-----------------------------------------");
                //1.停止所有监控扫描
                GlobalNodeConfig.Monitors.ForEach(x =>
                {
                    x.CancelRun();
                });
                OnInit(DateTime.Now + ":监控停止完成");
                //2.停止刷新命令队列
                CommandQueueScanManger.StopScanCommandQueue();
                OnInit(DateTime.Now + ":停止命令队列监听完成");
                //刷新节点运行状态
                var r2 = NodeProxy.PostToServer <EmptyResponse, UpdateNodeStatusRequest>(ProxyUrl.UpdateNodeStatus_Url, new UpdateNodeStatusRequest()
                {
                    NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, NodeStatus = Model.enums.NodeStatus.NoRun
                });

                if (r2.Status != ResponesStatus.Success)
                {
                    string msg = "更新节点运行状态失败,请求地址:" + ProxyUrl.UpdateNodeStatus_Url + ",服务器返回参数:" + JsonConvert.SerializeObject(r2);
                    OnInit(msg);
                    AlarmHelper.Alarm(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeID.ToString() + ")停止,更新运行状态失败", msg);
                }
                AlarmHelper.Alarm(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeID.ToString() + ")停止,请及时处理", DateTime.Now + ":当前节点(" + GlobalNodeConfig.NodeID.ToString() + ")已停止运行,如正常停止请忽略此预警");
                OnInit("节点服务停止");
            }
            catch (Exception ex)
            {
                string exemsg = "节点停止异常:" + JsonConvert.SerializeObject(ex);
                OnInit(exemsg);
                AlarmHelper.Alarm(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeID.ToString() + ")停止异常,请及时处理!", exemsg + ",节点停止日志:" + strLog.ToString());
            }
            finally
            {
                OnInit("----------------------" + DateTime.Now + ":停止节点结束-----------------------------------------");
                LogProxy.AddNodeLog(strLog.ToString(), LogType.NodeStopLog);
                strLog.Clear();
            }
        }