private void MakeGUI(bool reportErrors) { #region Tab Status try { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); _serviceStatus = sc.Status; lblStatus.Text = "Service Status: " + _serviceStatus.ToString(); _installed = true; btnInstall.Text = "Uninstall Windows Service..."; switch (_serviceStatus) { case ServiceControllerStatus.Stopped: btnStart.Text = "Start Service"; btnStart.Image = global::gView.Desktop.MapServer.Admin.Properties.Resources._16_arrow_right; picStatus.Image = global::gView.Desktop.MapServer.Admin.Properties.Resources._16_square_red; break; case ServiceControllerStatus.Running: btnStart.Text = "Stop Service"; btnStart.Image = global::gView.Desktop.MapServer.Admin.Properties.Resources._16_square_red; picStatus.Image = global::gView.Desktop.MapServer.Admin.Properties.Resources._16_arrow_right; break; } btnStart.Enabled = true; btnInstall.Visible = false; ServiceStartMode mode = ServiceHelper.GetServiceStartMode("gView.MapServer.Tasker"); cmbStartType.SelectedItem = mode; } catch (Exception ex) { if (reportErrors) { MessageBox.Show(lblStatus.Text = ex.Message, "Error"); } btnStart.Enabled = false; btnInstall.Text = "Install Windows Service..."; btnInstall.Visible = true; picStatus.Image = global::gView.Desktop.MapServer.Admin.Properties.Resources._16_message_warn; } #endregion #region Tab Config btnRefreshConfig_Click(this, new EventArgs()); #endregion #region Tab Logging try { string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\gView.MapServer.Instance.exe.config"; XmlDocument config = new XmlDocument(); config.Load(path); XmlNode node = config.SelectSingleNode("configuration/appSettings/add[@key='log_requests']"); chkLogRequests.Enabled = (node != null); chkLogRequests.Checked = (node == null || node.Attributes["value"] == null) ? false : node.Attributes["value"].Value.ToLower() == "true"; node = config.SelectSingleNode("configuration/appSettings/add[@key='log_request_details']"); chkLogRequestDetails.Enabled = (node != null); chkLogRequestDetails.Checked = (node == null || node.Attributes["value"] == null) ? false : node.Attributes["value"].Value.ToLower() == "true"; node = config.SelectSingleNode("configuration/appSettings/add[@key='log_errors']"); chkLogErrors.Enabled = (node != null); chkLogErrors.Checked = (node == null || node.Attributes["value"] == null) ? false : node.Attributes["value"].Value.ToLower() == "true"; chkLogRequests.CheckedChanged += new EventHandler(chkLog_CheckedChanged); chkLogRequestDetails.CheckedChanged += new EventHandler(chkLog_CheckedChanged); chkLogErrors.CheckedChanged += new EventHandler(chkLog_CheckedChanged); } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception"); } #endregion }
private void FormInstallService_Shown(object sender, EventArgs e) { string path = SystemVariables.ApplicationDirectory + @"\gView.MapServer.Tasker.exe"; FileInfo fi = new FileInfo(path); if (fi.Exists) { ServiceInstaller c = new ServiceInstaller(); if (_action == Action.Install || _action == Action.Install_forced) { if (_action != Action.Install_forced) { try { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); ServiceControllerStatus status = sc.Status; // Serive already installed!! txtOutput.Text = "Service 'gView.MapServer.Tasker' allready installed..."; _succeeded = true; this.Refresh(); Thread.Sleep(2000); this.Close(); return; } catch { } } try { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceControllerStatus status = sc.Status; c.UnInstallService("gView.MapServer.Tasker"); } catch { } if (!c.InstallService(path, "gView.MapServer.Tasker", "gView MapServer Tasker", false)) { txtOutput.Text = ServiceInstallUtil.InstallService(path); btnContinue.Visible = true; return; //lblStatus.Text = "Error on installing windows service 'gView.MapServer.Tasker'"; //btnContinue.Visible = true; //return; } txtOutput.Text = "Service 'gView.MapServer.Tasker' successfully installed..."; } else if (_action == Action.SetAutomatic) { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceHelper.ChangeStartMode(sc, ServiceStartMode.Automatic); } else if (_action == Action.SetManual) { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceHelper.ChangeStartMode(sc, ServiceStartMode.Manual); } else if (_action == Action.SetDisabled) { ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); ServiceHelper.ChangeStartMode(sc, ServiceStartMode.Disabled); } else if (_action == Action.Unsinstall) { try { // Service stoppen ServiceController sc = new ServiceController("gView.MapServer.Tasker"); sc.Refresh(); TimeSpan ts = new TimeSpan(0, 0, 30); sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped, ts); } catch { } if (!c.UnInstallService("gView.MapServer.Tasker")) { txtOutput.Text = "Error on uninstalling windows service 'gView.MapServer.Tasker'"; btnContinue.Visible = true; return; } txtOutput.Text = "Service 'gView.MapServer.Tasker' successfully uninstalled..."; } else if (_action == Action.Start) { try { TimeSpan ts = new TimeSpan(0, 0, 30); ServiceController sc = new ServiceController("gView.MapServer.Tasker"); if (sc.Status != ServiceControllerStatus.Running) { sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running, ts); } txtOutput.Text = "Service 'gView.MapServer.Tasker' successfully started..."; } catch (Exception ex) { txtOutput.Text = "Error: " + ex.Message; btnContinue.Visible = true; return; } } else if (_action == Action.Stop) { try { TimeSpan ts = new TimeSpan(0, 0, 30); ServiceController sc = new ServiceController("gView.MapServer.Tasker"); if (sc.Status != ServiceControllerStatus.Stopped) { sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped, ts); } txtOutput.Text = "Service 'gView.MapServer.Tasker' successfully stopped..."; } catch (Exception ex) { txtOutput.Text = "Error: " + ex.Message; btnContinue.Visible = true; return; } } } _succeeded = true; this.Refresh(); Thread.Sleep(2000); this.Close(); }