Exemplo n.º 1
0
        public void Start(out string errMsg)
        {
            // 子服务启动失败,应该不影响其他子服务
            errMsg = "";

            try
            {
                // Pump-OPC通信子服务
                if (Config.configInfo.confSonOPCPumpDataService != null && Config.configInfo.confSonOPCPumpDataService.IsNeedRun)
                {
                    opcPumpService = new OPCPumpService(Config.configInfo.confSonOPCPumpDataService);
                    opcPumpService.Start(out errMsg);
                    if (opcPumpService.IsRuning)
                    {
                        TraceManagerForOPC.AppendInfo("Pump-OPC通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "Pump-OPC通信子服务启动失败:" + errMsg;
                        TraceManagerForOPC.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Pump-OPC通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // Scada-OPC通信子服务
                if (Config.configInfo.confSonOPCScadaDataService != null && Config.configInfo.confSonOPCScadaDataService.IsNeedRun)
                {
                    opcScadaService = new OPCScadaService(Config.configInfo.confSonOPCScadaDataService);
                    opcScadaService.Start(out errMsg);
                    if (opcScadaService.IsRuning)
                    {
                        TraceManagerForOPC.AppendInfo("Scada-OPC通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "Scada-OPC通信子服务启动失败:" + errMsg;
                        TraceManagerForOPC.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForOPC.AppendErrMsg("Scada-OPC通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // 二供WEB-pump通信子服务
                if (Config.configInfo.confSonWebPandaPumpDataService != null && Config.configInfo.confSonWebPandaPumpDataService.IsNeedRun)
                {
                    webPandaPumpService = new WEBPandaPumpService(Config.configInfo.confSonWebPandaPumpDataService);
                    webPandaPumpService.Start(out errMsg);
                    if (webPandaPumpService.IsRuning)
                    {
                        TraceManagerForWeb.AppendInfo("二供WEB通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "二供WEB通信子服务启动失败:" + errMsg;
                        TraceManagerForWeb.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("二供WEB通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // WEB-pump-Scada 通信子服务
                if (Config.configInfo.confSonWebPandaPumpScadaDataService != null && Config.configInfo.confSonWebPandaPumpScadaDataService.IsNeedRun)
                {
                    webPandaPumpScadaService = new WEBPandaPumpSCADAService(Config.configInfo.confSonWebPandaPumpScadaDataService);
                    webPandaPumpScadaService.Start(out errMsg);
                    if (webPandaPumpScadaService.IsRuning)
                    {
                        TraceManagerForWeb.AppendInfo("WEB-pandaPump_Scada 通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "WEB-pandaPump_Scada 通信子服务启动失败:" + errMsg;
                        TraceManagerForWeb.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("WEB-pandaPump_Scada 通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // SACADA—WEB-监测点通信子服务
                if (Config.configInfo.confSonWebPandaYLDataService != null && Config.configInfo.confSonWebPandaYLDataService.IsNeedRun)
                {
                    webPandaYLScadaService = new WEBPandaYLSacdaService(Config.configInfo.confSonWebPandaYLDataService);
                    webPandaYLScadaService.Start(out errMsg);
                    if (webPandaYLScadaService.IsRuning)
                    {
                        TraceManagerForWeb.AppendInfo("SACADA—WEB-监测点通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "SACADA—WEB-监测点通信子服务启动失败:" + errMsg;
                        TraceManagerForWeb.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-监测点通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // SACADA—WEB-综合测点通信子服务
                if (Config.configInfo.confSonWebPandaZHCDDataService != null && Config.configInfo.confSonWebPandaZHCDDataService.IsNeedRun)
                {
                    webPandaZHCDScadaServcice = new WEBPandaZHCDSacdaService(Config.configInfo.confSonWebPandaZHCDDataService);
                    webPandaZHCDScadaServcice.Start(out errMsg);
                    if (webPandaZHCDScadaServcice.IsRuning)
                    {
                        TraceManagerForWeb.AppendInfo("SACADA—WEB-综合测点通信子服务已经启动");
                    }
                    else
                    {
                        errMsg = "SACADA—WEB-综合测点通信子服务启动失败:" + errMsg;
                        TraceManagerForWeb.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForWeb.AppendErrMsg("SACADA—WEB-综合测点通信子服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // 二供报警服务
                if (Config.configInfo.confSonCityIoTPumpAlarm != null && Config.configInfo.confSonCityIoTPumpAlarm.IsNeedRun)
                {
                    pumpAlarmService = new PumpAlarmService(Config.configInfo.confSonCityIoTPumpAlarm);
                    pumpAlarmService.Start(out errMsg);
                    if (pumpAlarmService.IsRuning)
                    {
                        TraceManagerForPumpAlarm.AppendInfo("二供报警服务已经启动");
                    }
                    else
                    {
                        errMsg = "二供报警服务启动失败:" + errMsg;
                        TraceManagerForPumpAlarm.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForPumpAlarm.AppendErrMsg("二供报警服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // 历史抽稀服务
                if (Config.configInfo.confSonHisVacuateService != null && Config.configInfo.confSonHisVacuateService.IsNeedRun)
                {
                    hisVacuate = new HisVacuate(Config.configInfo.confSonHisVacuateService);
                    hisVacuate.Start(out errMsg);
                    if (hisVacuate.IsRuning)
                    {
                        TraceManagerForHisVacuate.AppendInfo("历史抽稀服务已经启动");
                    }
                    else
                    {
                        errMsg = "历史抽稀服务启动失败:" + errMsg;
                        TraceManagerForHisVacuate.AppendErrMsg(errMsg);
                    }
                }
            }
            catch (Exception e) { TraceManagerForHisVacuate.AppendErrMsg("历史抽稀服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            try
            {
                // 特殊项目子服务
                if (Config.configInfo.confSonProjectDataService != null && Config.configInfo.confSonProjectDataService.IsNeedRun)
                {
                    if (!Config.configInfo.confSonProjectDataService.EnvIsOkay)
                    {
                        TraceManagerForProject.AppendErrMsg("特殊项目动态库环境配置异常:" + Config.configInfo.confSonProjectDataService.ErrMsg);
                    }
                    else
                    {
                        caseManagerInjection = Interface.GetInjection(Config.configInfo.confSonProjectDataService.DllPath);
                        caseManagerInjection.Start(out errMsg);
                        if (caseManagerInjection.IsRuning)
                        {
                            TraceManagerForProject.AppendInfo(Config.configInfo.confSonProjectDataService.ProjectName + "服务已经启动");
                        }
                        else
                        {
                            errMsg = Config.configInfo.confSonProjectDataService.ProjectName + "服务启动失败:" + errMsg;
                            TraceManagerForProject.AppendErrMsg(errMsg);
                        }
                    }
                }
            }
            catch (Exception e) { TraceManagerForProject.AppendErrMsg(Config.configInfo.confSonProjectDataService.ProjectName + "服务启动失败:" + e.Message + "堆栈:" + e.StackTrace); }

            IsRuning = true;
        }
Exemplo n.º 2
0
        private void StartTestAlive()
        {
            _testAliveExit = new AutoResetEvent(false);
            _taskTestAlive = new Task(() =>
            {
                bool isReconnecting = false;
                int timeout         = 100;

                while (!_testAliveExit.WaitOne(timeout))  // 每秒检测一次
                {
                    try
                    {
                        lock (_client)
                        {
                            if (_client.ServerState == (int)OPCServerState.OPCRunning)  //状态码正常
                            {
                                continue;
                            }
                        }
                    }
                    catch { }

                    if (!isReconnecting)
                    {
                        _isOpcConnected = false;
                        isReconnecting  = true;

                        TraceManagerForOPC.AppendInfo("OPCServer 离线了自动重连中...");

                        _client = null;

                        lock (_tagNamedIndex)
                        {
                            _tagNamedIndex.Clear();
                        }

                        lock (_tagClientHandleIndex)
                        {
                            _tagClientHandleIndex.Clear();
                        }

                        lock (_tagServerHandleIndex)
                        {
                            _tagServerHandleIndex.Clear();
                        }
                    }

                    if (Connect(true))
                    {
                        TraceManagerForOPC.AppendInfo("OPCServer 离线重连成功");

                        isReconnecting = false;
                        timeout        = 100;
                    }
                    else
                    {
                        // 重连失败说明服务端可能正在启动, 适当延长重连周期
                        timeout = 2000;
                    }
                }
            }, TaskCreationOptions.LongRunning);

            _taskTestAlive.Start();
        }