예제 #1
0
        public override ICommandStatus StartCollection()
        {
            ProcessCollectionCommandStatus status = new ProcessCollectionCommandStatus();

            status.CommandType = CommandType.ProcessCollectionStart;
            status.ProcessName = this.ProcessName;

            string           outputFileNameWithPath = string.Format(@"{0}\{1}", this.OutputPath, GetFileName());
            string           arguments = string.Format(" launch /cp:\"{0}\"  /f:\"{1}\" \"{2}\" {3}", this.CollectionPlanNameWithPath, outputFileNameWithPath, this.ProcessNameWithPath, this.CommandLineArguments);
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow  = false;
            startInfo.UseShellExecute = false;
            startInfo.FileName        = IntellitraceSCNameAndPath;
            startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
            startInfo.Arguments       = arguments;
            try
            {
                Process proc = Process.Start(startInfo);
                status.Success = true;
                status.ProcessIDs.Add(proc.Id);
                Thread.Sleep(5000);
                status.ProcessIDs.AddRange(ListOfProcessesLaunched(proc.Id));
            }
            catch (Exception ex)
            {
                status.Success     = false;
                status.ErrorMesage = ex.Message;
            }
            return(status);
        }
예제 #2
0
        public override ICommandStatus StopCollection()
        {
            ProcessCollectionCommandStatus status = new ProcessCollectionCommandStatus();

            status.CommandType = CommandType.ProcessCollectionStop;
            status.ProcessName = this.ProcessName;

            foreach (int procId in this.ProcessIDs)
            {
                Process[] currentProcesses = Process.GetProcesses();
                Process   proc             = currentProcesses.FirstOrDefault(pr => pr.Id == procId);
                if (proc == null)
                {
                    continue;
                }

                try
                {
                    //KillProcessAndChildren(this.ProcessID);
                    proc.Kill();
                    Thread.Sleep(1000);
                    status.Success = true;
                }
                catch (Exception ex)
                {
                    status.Success     = false;
                    status.ErrorMesage = ex.Message;
                }
            }
            status.Success = true;
            return(status);
        }
예제 #3
0
        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;
        }