private void ServicelistView_SelectedIndexChanged(object sender, EventArgs e) { if (ServicelistView.SelectedIndices.Count == 1) { ServiceContextActionButton.Enabled = true; SelectedService = ServicelistView.SelectedItems[0].SubItems[0].Text; string SelectedServiceStatus = ServicelistView.SelectedItems[0].SubItems[1].Text; if ((SelectedServiceStatus.CompareTo(ServiceControllerStatus.Stopped.ToString()) == 0) || (SelectedServiceStatus.CompareTo(ServiceControllerStatus.StopPending.ToString()) == 0)) { ServiceContextActionButton.Text = "Start Service"; ServiceAction = ServiceActionType.StartService; } else if ((SelectedServiceStatus.CompareTo(ServiceControllerStatus.Running.ToString()) == 0) || (SelectedServiceStatus.CompareTo(ServiceControllerStatus.StartPending.ToString()) == 0)) { ServiceContextActionButton.Text = "Stop Service"; ServiceAction = ServiceActionType.StopService; } else { ServiceContextActionButton.Enabled = false; ServiceAction = ServiceActionType.NoAction; } } else { ServiceContextActionButton.Enabled = false; ServiceAction = ServiceActionType.NoAction; } }
private bool ActService(string name, ServiceActionType action) { var mo = _managementClass.CreateInstance(); mo.Path = new ManagementPath(_actionPath + ".Name=\"" + name + "\""); mo.InvokeMethod(action.ToString(), null); return(true); }
/// <summary> /// Логгирование действия с базой /// </summary> public static void LogServiceAction <TId, TDomain>(IResultError result, IBoutiqueLogger boutiqueLogger, ServiceActionType serviceActionType) where TDomain : IDomainModel <TId> where TId : notnull => result. ResultErrorVoidOkBad(() => boutiqueLogger.ShowMessage($"{serviceActionType} [{typeof(TDomain).Name}] completed"), errors => errors. Void(_ => boutiqueLogger.ShowMessage($"Error {serviceActionType} [{typeof(TDomain).Name}]")). Void(_ => boutiqueLogger.ShowErrors(errors)));
public static string GetIconForActionType(ServiceActionType action) { switch (action) { case ServiceActionType.Start: return("player_play"); case ServiceActionType.Stop: return("stop"); case ServiceActionType.Restart: return("reload"); default: return("applications-system"); } }
public string Perform(ServiceActionType action) { Process process = new Process(); process.StartInfo.FileName = SystemServices.SudoCommand; process.StartInfo.Arguments = SystemServices.GetArgsForService(Script, action); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); string stdout = process.StandardOutput.ReadToEnd(); string stderr = process.StandardError.ReadToEnd(); return(stdout + "\n" + stderr); }
/// <summary> /// Get full path to do action on service. /// </summary> /// <param name="name">name of script (service)</param> /// <param name="action">action to do</param> /// <returns>execute arguments for (gk)sudo</returns> public static string GetArgsForService(string name, ServiceActionType action) { string actionArgument; switch (action) { case ServiceActionType.Start: actionArgument = "start"; break; case ServiceActionType.Stop: actionArgument = "stop"; break; case ServiceActionType.Restart: actionArgument = "restart"; break; default: throw new ArgumentException("Unsupported Action", "action"); } return(Path.Combine(servicesDirectory, name) + " " + actionArgument); }
private void ConfigureFailureAction(IntPtr actions, int serviceActionDataSize, int index, ServiceActionType failureActionType, uint failureActionDelay) { Marshal.WriteInt32(actions, index * serviceActionDataSize + (int)Marshal.OffsetOf(typeof(ServiceAction), "actionType"), (int)failureActionType); Marshal.WriteInt32(actions, index * serviceActionDataSize + (int)Marshal.OffsetOf(typeof(ServiceAction), "delay"), (int)failureActionDelay); }
public BaseServiceAction(string name, string description, ServiceActionType action) { this.name = AddinManager.CurrentLocalizer.GetString(name); this.description = AddinManager.CurrentLocalizer.GetString(description); this.action = action; }