public override ICommandStatus StartCollection() { WindowsServiceCollectionCommandStatus status = new WindowsServiceCollectionCommandStatus(); status.ServiceName = this.ServiceName; status.CommandType = CommandType.ServiceCollectionStart; //if (!Utils.DoesEveryoneHasWritePermissionOnFolder(this.CalculatedPath)) //{ // Utils.GrantEveryoneWritePermissionToFolder(this.CalculatedPath); //} CommandStatus updatePlanStatus = (CommandStatus)UpdatePlanForOutputFolderPath(); if (updatePlanStatus.Success) { status.InfoMessages.Add("Collection Plan updated successfully for Output path."); } else { status.InfoMessages.Add(updatePlanStatus.ErrorMesage); status.Success = false; return(status); } CommandStatus createRegistryStatus = (CommandStatus)CreateRegistryEntryForIntellitrace(); if (createRegistryStatus.Success) { status.InfoMessages.Add(string.Format("Registry Key IntelliTrace data collection successfully updated for service {0}.", this.ServiceName)); } else { status.InfoMessages.Add(createRegistryStatus.ErrorMesage); status.Success = false; return(status); } CommandStatus resetServiceStatus; ServiceController service = new ServiceController(this.ServiceName); if (service.Status == ServiceControllerStatus.Running) { resetServiceStatus = (CommandStatus)ResetService(false); if (resetServiceStatus.Success) { status.InfoMessages.Add(string.Format("Service {0} stopped collection successfully.", this.ServiceName)); } else { status.InfoMessages.Add(resetServiceStatus.ErrorMesage); status.Success = false; return(status); } } else { status.InfoMessages.Add(string.Format("Service {0} state = {1}.", this.ServiceName, service.Status.ToString())); } resetServiceStatus = (CommandStatus)ResetService(true); if (resetServiceStatus.Success) { status.InfoMessages.Add(string.Format("Service {0} started collection successfully.", this.ServiceName)); } else { status.InfoMessages.Add(resetServiceStatus.ErrorMesage); status.Success = false; return(status); } status.Success = true; return(status); }
private void UpdateActionCompleted(ICommandStatus result) { string commandType = "", message = ""; this.pbCollection.IsIndeterminate = false; switch (result.CommandType) { case CommandType.IISCollectionStart: commandType = "IIS Collection Start"; break; case CommandType.IISCollectionStop: commandType = "IIS Collection Stop"; break; case CommandType.ServiceCollectionStart: commandType = "Service Start"; break; case CommandType.ServiceCollectionStop: commandType = "Service Stop"; break; case CommandType.ProcessCollectionStart: commandType = "Process Collection Start"; break; case CommandType.ProcessCollectionStop: commandType = "Process Collection Stop"; break; } if (result is WindowsServiceCollectionCommandStatus) { WindowsServiceCollectionCommandStatus wsStatus = (WindowsServiceCollectionCommandStatus)result; AddToLog(wsStatus.InfoMessages); } else if (result is ProcessCollectionCommandStatus) { ProcessCollectionCommandStatus pStatus = (ProcessCollectionCommandStatus)result; if (result.Success) { message = string.Format("Process {0} {1} successfully for Intellitrace Collection.", pStatus.ProcessName, (pStatus.CommandType == CommandType.ProcessCollectionStart ? "started" : "stopped")); this.processIds = pStatus.ProcessIDs; foreach (int id in processIds) { AddToLog(string.Format("process id = {0}", id)); } } else { message = string.Format("Process {0} Failed to {1} for Intellitrace Collection - {2}.", pStatus.ProcessName, (pStatus.CommandType == CommandType.ProcessCollectionStart ? "start" : "stop"), result.ErrorMesage); } AddToLog(message); } else if (result is CommandStatus) { if (result.Success) { message = string.Format("{0} Successful.", commandType); } else { message = string.Format("{0} Failed - {1}.", commandType, result.ErrorMesage); } AddToLog(message); } this.Cursor = Cursors.Arrow; }
public override ICommandStatus StopCollection() { WindowsServiceCollectionCommandStatus status = new WindowsServiceCollectionCommandStatus(); status.ServiceName = this.ServiceName; status.CommandType = CommandType.ServiceCollectionStart; List <string> info = new List <string>(); CommandStatus removeRegistryStatus = (CommandStatus)RemoveRegistryEntryForIntellitrace(); if (removeRegistryStatus.Success) { info.Add(string.Format("Registry Key IntelliTrace data collection removed for service {0}.", this.ServiceName)); } else { info.Add(removeRegistryStatus.ErrorMesage); status.Success = false; status.InfoMessages = info; return(status); } CommandStatus resetServiceStatus; ServiceController service = new ServiceController(this.ServiceName); if (service.Status == ServiceControllerStatus.Running) { resetServiceStatus = (CommandStatus)ResetService(false); if (resetServiceStatus.Success) { info.Add(string.Format("Service {0} stopped collection successfully.", this.ServiceName)); } else { info.Add(resetServiceStatus.ErrorMesage); status.Success = false; status.InfoMessages = info; return(status); } } else { info.Add(string.Format("Service {0} state = {1}.", this.ServiceName, service.Status.ToString())); } resetServiceStatus = (CommandStatus)ResetService(true); if (resetServiceStatus.Success) { info.Add(string.Format("Service {0} started collection successfully.", this.ServiceName)); } else { info.Add(resetServiceStatus.ErrorMesage); status.Success = false; status.InfoMessages = info; return(status); } status.Success = true; status.InfoMessages = info; return(status); }