Example #1
0
        public int ProcessIdFromName(string processName)
        {
            Process[] processes       = null;
            Exception caughtException = null;

            try
            {
                processes = _processAbstraction.GetProcessesByName(processName);
            }
#pragma warning disable CA1031
            catch (Exception e)
#pragma warning restore CA1031
            {
                caughtException = e;
            }

            if (caughtException != null || processes == null || processes.Length == 0)
            {
                throw new ParameterException(
                          string.Format(CultureInfo.CurrentCulture, DisplayStrings.ErrorNoMatchingProcessNameFormat, processName),
                          caughtException);
            }

            if (processes.Length > 1)
            {
                throw new ParameterException(
                          string.Format(CultureInfo.CurrentCulture, DisplayStrings.ErrorMultipleMatchingProcessNameFormat, processName));
            }

            return(processes[0].Id);
        }
Example #2
0
        public int ProcessIdFromName(string processName)
        {
            Process[] processes       = null;
            Exception caughtException = null;

            try
            {
                processes = _processAbstraction.GetProcessesByName(processName);
            }
#pragma warning disable CA1031
            catch (Exception e)
#pragma warning restore CA1031
            {
                caughtException = e;
            }

            if (caughtException != null || processes == null || processes.Length == 0)
            {
                throw new ParameterException("Unable to find process with name " + processName, caughtException);
            }

            if (processes.Length > 1)
            {
                throw new ParameterException("Found multiple processes with name " + processName);
            }

            return(processes[0].Id);
        }