public static int ChangeWindowsServiceStatus(int serverId, string id, WindowsServiceStatus status) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsAdmin | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // load server info ServerInfo server = ServerController.GetServerById(serverId); // place log record TaskManager.StartTask("SERVER", "CHANGE_WINDOWS_SERVICE_STATUS", id); TaskManager.ItemId = serverId; TaskManager.WriteParameter("New Status", status); try { GetServerService(serverId).ChangeWindowsServiceStatus(id, status); return(0); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public void Execute(IJobExecutionContext context) { if (!ServiceGlobalVariable.SignalRHubExists) { string url = "http://localhost:8080"; using (WebApp.Start(url)) { Console.WriteLine("Server running on {0}", url); ServiceGlobalVariable.SignalRHubExists = true; Console.ReadLine(); } } else { DateTime heartBeat = new DateTime(); heartBeat = DateTime.Now; WindowsServiceStatus windowsServiceStatus = new WindowsServiceStatus(); windowsServiceStatus.HeartBeatValue = heartBeat; windowsServiceStatus.RunningServerName = System.Environment.MachineName; windowsServiceStatus.ServiceName = ServiceGlobalVariable.ServiceName; this._IHRAMServicesService.UpdateServerServiceStatusBatch(windowsServiceStatus); // Get the context for the Pusher hub IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <MyHub>(); hubContext.Clients.All.addMessage(ServiceGlobalVariable.ServiceName , heartBeat.ToString()); } }
public bool UpdateServerServiceStatusBatch(WindowsServiceStatus windowsServiceStatus) { try { return this._IHRAMServicesRepository.UpdateServerServiceStatusBatch(windowsServiceStatus); } catch (Exception ex) { throw; } }
public WindowsService[] GetWindowsServices() { try { Log.WriteStart("GetWindowsServices"); List <WindowsService> winServices = new List <WindowsService>(); ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { WindowsService winService = new WindowsService(); winService.Id = service.ServiceName; winService.Name = service.DisplayName; winService.CanStop = service.CanStop; winService.CanPauseAndContinue = service.CanPauseAndContinue; WindowsServiceStatus status = WindowsServiceStatus.ContinuePending; switch (service.Status) { case ServiceControllerStatus.ContinuePending: status = WindowsServiceStatus.ContinuePending; break; case ServiceControllerStatus.Paused: status = WindowsServiceStatus.Paused; break; case ServiceControllerStatus.PausePending: status = WindowsServiceStatus.PausePending; break; case ServiceControllerStatus.Running: status = WindowsServiceStatus.Running; break; case ServiceControllerStatus.StartPending: status = WindowsServiceStatus.StartPending; break; case ServiceControllerStatus.Stopped: status = WindowsServiceStatus.Stopped; break; case ServiceControllerStatus.StopPending: status = WindowsServiceStatus.StopPending; break; } winService.Status = status; winServices.Add(winService); } Log.WriteEnd("GetWindowsServices"); return(winServices.ToArray()); } catch (Exception ex) { Log.WriteError("GetWindowsServices", ex); throw; } }
public void ChangeWindowsServiceStatus(string id, WindowsServiceStatus status) { try { Log.WriteStart("ChangeWindowsServiceStatus"); // get all services ServiceController[] services = ServiceController.GetServices(); // find required service foreach (ServiceController service in services) { if (String.Compare(service.ServiceName, id, true) == 0) { if (status == WindowsServiceStatus.Paused && service.Status == ServiceControllerStatus.Running) { service.Pause(); } else if (status == WindowsServiceStatus.Running && service.Status == ServiceControllerStatus.Stopped) { service.Start(); } else if (status == WindowsServiceStatus.Stopped && ((service.Status == ServiceControllerStatus.Running) || (service.Status == ServiceControllerStatus.Paused))) { service.Stop(); } else if (status == WindowsServiceStatus.ContinuePending && service.Status == ServiceControllerStatus.Paused) { service.Continue(); } } } Log.WriteEnd("ChangeWindowsServiceStatus"); } catch (Exception ex) { Log.WriteError("ChangeWindowsServiceStatus", ex); throw; } }
protected void gvServices_RowCommand(object sender, GridViewCommandEventArgs e) { WindowsServiceStatus status = (WindowsServiceStatus)Enum.Parse(typeof(WindowsServiceStatus), e.CommandName, true); string id = (string)e.CommandArgument; try { int result = ES.Services.Servers.ChangeWindowsServiceStatus(PanelRequest.ServerId, id, status); if (result < 0) { ShowResultMessage(result); return; } // rebind BindServices(); } catch (Exception ex) { ShowErrorMessage("SERVER_CHANGE_WIN_SERVICE_STATE", ex); return; } }
public void ChangeWindowsServiceStatus(string id, WindowsServiceStatus status) { try { Log.WriteStart("ChangeWindowsServiceStatus"); // get all services ServiceController[] services = ServiceController.GetServices(); // find required service foreach (ServiceController service in services) { if (String.Compare(service.ServiceName, id, true) == 0) { if (status == WindowsServiceStatus.Paused && service.Status == ServiceControllerStatus.Running) service.Pause(); else if (status == WindowsServiceStatus.Running && service.Status == ServiceControllerStatus.Stopped) service.Start(); else if (status == WindowsServiceStatus.Stopped && ((service.Status == ServiceControllerStatus.Running) || (service.Status == ServiceControllerStatus.Paused))) service.Stop(); else if (status == WindowsServiceStatus.ContinuePending && service.Status == ServiceControllerStatus.Paused) service.Continue(); } } Log.WriteEnd("ChangeWindowsServiceStatus"); } catch (Exception ex) { Log.WriteError("ChangeWindowsServiceStatus", ex); throw; } }
public int ChangeWindowsServiceStatus(int serverId, string id, WindowsServiceStatus status) { return(OperatingSystemController.ChangeWindowsServiceStatus(serverId, id, status)); }
public int ChangeWindowsServiceStatus(int serverId, string id, WindowsServiceStatus status) { return OperatingSystemController.ChangeWindowsServiceStatus(serverId, id, status); }
public void ChangeWindowsServiceStatus(string id, WindowsServiceStatus status) { this.Invoke("ChangeWindowsServiceStatus", new object[] { id, status}); }
public int ChangeWindowsServiceStatus(int serverId, string id, WindowsServiceStatus status) { object[] results = this.Invoke("ChangeWindowsServiceStatus", new object[] { serverId, id, status}); return ((int)(results[0])); }
/// <remarks/> public System.IAsyncResult BeginChangeWindowsServiceStatus(string id, WindowsServiceStatus status, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("ChangeWindowsServiceStatus", new object[] { id, status}, callback, asyncState); }
/// <remarks/> public void ChangeWindowsServiceStatusAsync(string id, WindowsServiceStatus status) { this.ChangeWindowsServiceStatusAsync(id, status, null); }
/// <remarks/> public void ChangeWindowsServiceStatusAsync(string id, WindowsServiceStatus status, object userState) { if ((this.ChangeWindowsServiceStatusOperationCompleted == null)) { this.ChangeWindowsServiceStatusOperationCompleted = new System.Threading.SendOrPostCallback(this.OnChangeWindowsServiceStatusOperationCompleted); } this.InvokeAsync("ChangeWindowsServiceStatus", new object[] { id, status}, this.ChangeWindowsServiceStatusOperationCompleted, userState); }
public static int ChangeWindowsServiceStatus(int serverId, string id, WindowsServiceStatus status) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsAdmin | DemandAccount.IsActive); if (accountCheck < 0) return accountCheck; // load server info ServerInfo server = ServerController.GetServerById(serverId); // place log record TaskManager.StartTask("SERVER", "CHANGE_WINDOWS_SERVICE_STATUS", id, serverId); TaskManager.WriteParameter("New Status", status); try { GetServerService(serverId).ChangeWindowsServiceStatus(id, status); return 0; } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }