Пример #1
0
        public static IProcessInfo TryResolveTargetProcess(RunningProcessArguments identifiers, ConsoleLog console)
        {
            var processResolver = new ProcessResolver(new ProcessFinder());

            try
            {
                return(processResolver.ResolveTargetProcess(identifiers.Pid, identifiers.Name, identifiers.AppPoolNamePrefix));
            }
            catch (ProcessNotSpecifiedException ex)
            {
                throw new ErrorWithExitCodeException(1, ex.Message)
                      {
                          ShowUsage = true
                      };
            }
            catch (ProcessNotFoundException ex) when(ex.Candidates.Any())
            {
                new ProcessListDescriber().DescribeCandidateProcesses(ex.Candidates.ToList(), console);
                if (Bootstrap.WasUsed)
                {
                    throw ErrorWithExitCodeException.Propagate(3);
                }
                throw new ErrorWithExitCodeException(3, "Please specify a unique process Id using the -p switch.");
            }
            catch (ProcessNotFoundException ex)
            {
                throw new ErrorWithExitCodeException(3, ex.Message);
            }
        }
Пример #2
0
        public void ProcessNameIsResolvedToPid()
        {
            var processResolver = new ProcessResolver(
                Mock.Of<IProcessFinder>(f => f.FindProcessesByName("process.exe") == new[] { new ProcessInfo { Pid = 1234 } }));

            var process = processResolver.ResolveTargetProcess(null, "process.exe");

            Assert.That(process.Pid, Is.EqualTo(1234));
        }
Пример #3
0
        public void ProcessNameAndPidAreCheckedForMismatch()
        {
            var processResolver = new ProcessResolver(
                Mock.Of<IProcessFinder>(f => f.VerifyProcessName("process.exe", 1234) == new ProcessInfo { Pid = 1234 }));

            var process = processResolver.ResolveTargetProcess(1234, "process.exe");

            Assert.That(process.Pid, Is.EqualTo(1234));
        }
Пример #4
0
        public void NonUniqueProcessNameCannotBeResolved()
        {
            var processResolver = new ProcessResolver(
                Mock.Of<IProcessFinder>(f => f.FindProcessesByName("process.exe") == new[] {
                    new ProcessInfo(),
                    new ProcessInfo()
                }));

            var exception = Assert.Throws<ProcessNotFoundException>(() => processResolver.ResolveTargetProcess(null, "process.exe"));

            Assert.That(exception.Candidates.Count(), Is.EqualTo(2));
        }
Пример #5
0
        public static bool TryResolveTargetProcessQuietly(RunningProcessArguments identifiers, out IProcessInfo process)
        {
            var processResolver = new ProcessResolver(new ProcessFinder());

            try
            {
                process = processResolver.ResolveTargetProcess(identifiers.Pid, identifiers.Name, identifiers.AppPoolNamePrefix);
                return(true);
            }
            catch
            {
                process = null;
                return(false);
            }
        }
Пример #6
0
        public void ProvidingNeitherPidNorProcessName_ThrowsException()
        {
            var processResolver = new ProcessResolver(Mock.Of<IProcessFinder>());

            Assert.Throws<ProcessNotSpecifiedException>(() => processResolver.ResolveTargetProcess(null, ""));
        }
Пример #7
0
 private static IProcessInfo ResolveTargetProcess(Arguments arguments, ConsoleLog console)
 {
     var processResolver = new ProcessResolver(new ProcessFinder());
     try
     {
         return processResolver.ResolveTargetProcess(arguments.Pid, arguments.ProcessName);
     }
     catch(ProcessNotSpecifiedException ex)
     {
         throw new ErrorWithExitCodeException(1, ex.Message) { ShowUsage = true };
     }
     catch(ProcessNotFoundException ex) when(ex.Candidates.Any())
     {
         new ProcessListDescriber().DescribeCandidateProcesses(ex.Candidates.ToList(), console);
         if(Bootstrap.WasUsed) throw ErrorWithExitCodeException.Propagate(3);
         throw new ErrorWithExitCodeException(3, "Please specify a unique process Id using the -p switch.");
     }
     catch(ProcessNotFoundException ex)
     {
         throw new ErrorWithExitCodeException(3, ex.Message);
     }
 }