コード例 #1
0
        // 停止服务
        public string IsStopCoreHander(out string statusCode, out string errMsg)
        {
            statusCode = "0000";
            errMsg     = "";

            if (!ServiceToolEx.IsServiceRunning(serverName))
            {
                errMsg     = serverName + "服务未运行";
                statusCode = "4000";
                return("");
            }
            ServiceController service = ServiceToolEx.StopService(serverName);

            if (service == null)
            {
                errMsg     = serverName + "服务停止失败";
                statusCode = "4001";
                return("");
            }
            if (ServiceToolEx.IsServiceRunning(serverName))
            {
                errMsg     = serverName + "服务停止失败!" + ErrorPolicy;
                statusCode = "4005";
                return("");
            }
            string dispatchInfo = IsStopDispatchHander(out statusCode, out errMsg);

            return(serverName + "服务已停止;" + dispatchInfo);
        }
コード例 #2
0
        public string IsStopDispatchHander(out string statusCode, out string errMsg)
        {
            statusCode = "0000";
            errMsg     = "";

            if (!ServiceToolEx.IsServiceRunning(dispatchServerName))
            {
                errMsg     = dispatchServerName + "服务未运行";
                statusCode = "4000";
                return("");
            }
            ServiceController service = ServiceToolEx.StopService(dispatchServerName);

            if (service == null)
            {
                errMsg     = dispatchServerName + "服务停止失败";
                statusCode = "4001";
                return("");
            }
            if (!ServiceToolEx.IsServiceRunning(dispatchServerName))
            {
                return(dispatchServerName + "服务已停止");
            }
            else
            {
                errMsg     = dispatchServerName + "服务停止失败!" + ErrorPolicy;
                statusCode = "4005";
                return("");
            }
        }
コード例 #3
0
        private string IsInstalDispatchHander(out string statusCode, out string errMsg)
        {
            statusCode = "0000";
            errMsg     = "";

            if (!File.Exists(dispatchIotServerPath))
            {
                errMsg     = dispatchServerName + "注册失败:未找到服务文件" + dispatchIotServerPath;
                statusCode = "4104";
                return("");
            }
            if (ServiceToolEx.IsServiceExist(dispatchServerName))
            {
                errMsg     = dispatchServerName + "服务已存在";
                statusCode = "4100";
                return("");
            }
            ServiceController service = ServiceToolEx.InstallService(dispatchIotServerPath, dispatchServerName, dispatchServerName, dispatchServerDescribe, System.ServiceProcess.ServiceStartMode.Manual);

            if (service == null)
            {
                errMsg     = dispatchServerName + "服务注册失败";
                statusCode = "4101";
                return("");
            }
            if (!ServiceToolEx.IsServiceExist(dispatchServerName))
            {
                errMsg     = dispatchServerName + "服务注册失败!" + ErrorPolicy;
                statusCode = "4105";
                return("");
            }
            return(dispatchServerName + "服务注册成功");
        }
コード例 #4
0
 public bool IsDispatchServiceRun()
 {
     if (!ServiceToolEx.IsServiceExist(dispatchServerName))
     {
         return(false);
     }
     return(ServiceToolEx.IsServiceRunning(dispatchServerName));
 }
コード例 #5
0
 // 服务是否在运行
 public bool IsCoreServiceRun()
 {
     if (!ServiceToolEx.IsServiceExist(serverName))
     {
         return(false);
     }
     return(ServiceToolEx.IsServiceRunning(serverName));
 }
コード例 #6
0
        public void RefreshControlState()
        {
            Config.ServerIsRuning = false;
            if (!EnvIsOkay)
            {
                this.isInstal.Enabled   = false;
                this.isUnInstal.Enabled = false;
                this.iStart.Enabled     = false;
                this.isStop.Enabled     = false;
                this.IsRestart.Enabled  = false;

                return;
            }

            if (ServiceToolEx.IsServiceExist(Config.envConfigInfo.confProjectInfo.ServerName))
            {
                // 工具栏
                this.isInstal.Enabled   = false;
                this.isUnInstal.Enabled = true;
                this.IsRestart.Enabled  = true;
                // 菜单栏

                if (ServiceToolEx.IsServiceRunning(Config.envConfigInfo.confProjectInfo.ServerName))
                {
                    this.toolStripStatusLabel4.Text      = "正在运行";
                    this.toolStripStatusLabel4.ForeColor = Color.ForestGreen;
                    this.isStop.Enabled = true;
                    this.iStart.Enabled = false;

                    Config.ServerIsRuning = true;
                }
                else
                {
                    this.toolStripStatusLabel4.Text      = "已停止";
                    this.toolStripStatusLabel4.ForeColor = Color.Red;
                    this.iStart.Enabled = true;
                    this.isStop.Enabled = false;
                }
            }
            else
            {
                this.toolStripStatusLabel4.Text = "未注册";
                this.isInstal.Enabled           = true;
                this.isUnInstal.Enabled         = false;
                this.iStart.Enabled             = false;
                this.isStop.Enabled             = false;
                this.IsRestart.Enabled          = false;
            }
            this.textBoxTrace.BackColor = Color.FromArgb(0, 64, 0);
            this.textBoxTrace.ForeColor = Color.Lime;
            this.Text = GetTitleText();

            this.toolStripStatusProjectName.Text = Config.envConfigInfo.confProjectInfo.ProjectName;
        }
コード例 #7
0
        public string IsRestartDispatchHander(out string statusCode, out string errMsg)
        {
            statusCode = "0000";
            errMsg     = "";

            if (!ServiceToolEx.IsServiceExist(dispatchServerName))
            {
                errMsg     = dispatchServerName + "服务不存在请先注册";
                statusCode = "4000";
                return("");
            }
            ServiceController service;

            if (ServiceToolEx.IsServiceRunning(dispatchServerName))
            {
                service = ServiceToolEx.StopService(dispatchServerName);
                if (service == null)
                {
                    service    = null;
                    errMsg     = dispatchServerName + "服务停止失败";
                    statusCode = "4001";
                    return("");
                }
                if (ServiceToolEx.IsServiceRunning(dispatchServerName))
                {
                    errMsg     = dispatchServerName + "服务停止失败!" + ErrorPolicy;
                    statusCode = "4005";
                    return("");
                }
            }
            service = ServiceToolEx.StartService(dispatchServerName, new string[0]);
            if (service == null)
            {
                errMsg     = dispatchServerName + "服务启动失败";
                statusCode = "4002";
                return("");
            }
            if (ServiceToolEx.IsServiceRunning(dispatchServerName))
            {
                return(serverName + "服务已重新启动");
            }
            else
            {
                errMsg     = dispatchServerName + "服务启动失败!" + ErrorPolicy;
                statusCode = "4005";
                return("");
            }
        }
コード例 #8
0
        public string IsUnInstalDispatchHander(out string statusCode, out string errMsg)
        {
            statusCode = "0000";
            errMsg     = "";

            if (!ServiceToolEx.IsServiceExist(dispatchServerName))
            {
                errMsg     = dispatchServerName + "服务不存在";
                statusCode = "4100";
                return("");
            }
            if (!ServiceToolEx.UninstallService(dispatchServerName))
            {
                errMsg     = dispatchServerName + "服务卸载失败!" + ErrorPolicy;
                statusCode = "4101";
                return("");
            }
            return(dispatchServerName + "服务卸载成功");
        }
コード例 #9
0
        public string IsStartDispatchHander(out string statusCode, out string errMsg)
        {
            statusCode = "0000";
            errMsg     = "";
            if (!ServiceToolEx.IsServiceExist(dispatchServerName))
            {
                errMsg     = dispatchServerName + "服务不存在";
                statusCode = "4004";
                return("");
            }
            string curFilePath = ServiceToolEx.GetWindowsServiceInstallPath(dispatchServerName);

            if (curFilePath.ToUpper() != new DirectoryInfo(dispatchIotServerPath).Parent.FullName.ToUpper())
            {
                errMsg     = dispatchServerName + "服务路径不一致,请先卸载原来路径的服务:" + curFilePath;
                statusCode = "4007";
                return("");
            }
            if (ServiceToolEx.IsServiceRunning(dispatchServerName))
            {
                errMsg     = dispatchServerName + "服务已经在运行";
                statusCode = "4000";
                return("");
            }
            ServiceController service = ServiceToolEx.StartService(dispatchServerName, new string[0]);

            if (service == null)
            {
                errMsg     = dispatchServerName + "服务启动失败";
                statusCode = "4001";
            }
            if (ServiceToolEx.IsServiceRunning(dispatchServerName))
            {
                return(dispatchServerName + "服务已启动");
            }
            else
            {
                errMsg     = dispatchServerName + "服务启动失败!" + ErrorPolicy;
                statusCode = "4005";
                return("");
            }
        }
コード例 #10
0
        // 卸载服务--核心服务和调度服务
        public string IsUnInstalCoreHander(out string statusCode, out string errMsg)
        {
            statusCode = "0000";
            errMsg     = "";

            if (!ServiceToolEx.IsServiceExist(serverName))
            {
                errMsg     = serverName + "服务不存在";
                statusCode = "4000";
                return("");
            }
            if (!ServiceToolEx.UninstallService(serverName))
            {
                errMsg     = serverName + "服务卸载失败!" + ErrorPolicy;
                statusCode = "4001";
                return("");
            }
            string dispatchInfo = IsUnInstalDispatchHander(out statusCode, out errMsg);

            return(serverName + "服务卸载成功;" + dispatchInfo);
        }
コード例 #11
0
        public bool StopOPCServer(out string errMsg)
        {
            errMsg = "";
            if (!IsNeedOPCServer)
            {
                errMsg = "检测到核心服务不需要OPCServer,停止OPCServer失败";
                return(false);
            }
            string[]      services    = ServiceToolEx.GetLocalHostServerList();
            List <string> kepServices = new List <string>();

            foreach (string servicesName in services)
            {
                if (servicesName.ToUpper().Contains("KEPSERVEREX"))
                {
                    kepServices.Add(servicesName);
                }
            }
            if (kepServices.Count == 0)
            {
                errMsg = "检测到本地计算机没有安装KepServer,无法停止其服务";
                return(false);
            }
            errMsg = "";
            foreach (string servicesName in kepServices)
            {
                if (!ServiceToolEx.StopService(servicesName, out string err))
                {
                    errMsg = errMsg + err;
                }
            }
            if (string.IsNullOrWhiteSpace(errMsg))
            {
                return(true);
            }
            return(false);
        }
コード例 #12
0
        // 注册服务--核心服务和调度服务
        public string IsInstalCoreHander(out string statusCode, out string errMsg)
        {
            statusCode = "0000";
            errMsg     = "";

            if (!File.Exists(iotServerPath))
            {
                errMsg     = serverName + "注册失败:未找到服务文件" + iotServerPath;
                statusCode = "4004";
                return("");
            }
            if (ServiceToolEx.IsServiceExist(serverName))
            {
                errMsg     = serverName + "服务已存在";
                statusCode = "4000";
                return("");
            }

            ServiceController service = ServiceToolEx.InstallService(iotServerPath, serverName, serverName, serverDescribe, System.ServiceProcess.ServiceStartMode.Manual);

            if (service == null)
            {
                errMsg     = serverName + "服务注册失败";
                statusCode = "4001";
                return("");
            }
            if (!ServiceToolEx.IsServiceExist(serverName))
            {
                errMsg     = serverName + "服务注册失败!" + ErrorPolicy;
                statusCode = "4005";
                return("");
            }
            string dispatchInfo = IsInstalDispatchHander(out statusCode, out errMsg);

            return(serverName + "服务注册成功;" + dispatchInfo);
        }
コード例 #13
0
 public bool IsDispatchServiceExist()
 {
     return(ServiceToolEx.IsServiceExist(dispatchServerName));
 }
コード例 #14
0
 // 服务是否存在
 public bool IsCoreServiceExist()
 {
     return(ServiceToolEx.IsServiceExist(serverName));
 }