예제 #1
0
        /// <summary>
        /// 编辑当前服务
        /// </summary>
        private void EditCurrentService()
        {
            this.GetNowService();
            if (currentServer == null || string.IsNullOrEmpty(currentServer.ServerID))
            {
                MessageBox.Show("请先选择服务!");
                return;
            }
            //是否存在服务
            bool isExisted = ConfigService.IsServiceExisted(currentServer.ServerName);

            //存在服务先停止
            if (isExisted)
            {
                ConfigService.StopService(currentServer.ServerName);
            }
            frmEditWorkList frmEditWork = new frmEditWorkList(currentServer);

            frmEditWork.ShowDialog();
            if (frmEditWork.DialogResult == DialogResult.OK)
            {
                Model.ServerConfig newServerConfig = frmEditWork.EditServerConfig;
                //服务名或路径有变化则卸载重装
                if (currentServer.ServerName != newServerConfig.ServerName ||
                    currentServer.FileFloderName != newServerConfig.FileFloderName ||
                    !ConfigService.IsServiceExisted(newServerConfig.ServerName))
                {
                    //非新建且旧服务名存在则先卸载
                    if (!string.IsNullOrEmpty(currentServer.ServerName) && isExisted)
                    {
                        ConfigService.UninstallService(currentServer.FileFloderName);
                    }
                    currentServer = newServerConfig;
                    ConfigService.InstallService(currentServer.FileFloderName);
                    isExisted = true;
                }
                else
                {
                    currentServer = newServerConfig;
                }
            }
            if (isExisted)
            {
                Thread.Sleep(500);
                ConfigService.StartService(currentServer.ServerName);
            }
            this.RefreshForm();
        }
예제 #2
0
        /// <summary>
        /// 新增服务
        /// </summary>
        private void AddNewService()
        {
            Model.ServerConfig newServerConfig = new Model.ServerConfig();
            frmEditWorkList    frmEditWork     = new frmEditWorkList(newServerConfig);

            frmEditWork.ShowDialog();
            if (frmEditWork.DialogResult == DialogResult.OK)
            {
                newServerConfig = frmEditWork.EditServerConfig;
                //是否存在服务
                bool isExisted = ConfigService.IsServiceExisted(newServerConfig.ServerName);
                //非新建且旧服务名存在则先卸载
                if (isExisted)
                {
                    ConfigService.UninstallService(currentServer.FileFloderName);
                }
                currentServer = newServerConfig;
                ConfigService.InstallService(newServerConfig.FileFloderName);
                Thread.Sleep(500);
                ConfigService.StartService(newServerConfig.ServerName);
            }
            this.RefreshForm();
        }