Пример #1
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("");
            }
        }
Пример #2
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("");
            }
        }