Example #1
0
 /// <summary>
 /// Starts a process resource by specifying the name of an application and a set of command-line arguments.
 /// </summary>
 /// <param name="fileName">The name of an application file to run in the process.</param>
 /// <param name="arguments">Command-line arguments to pass when starting the process.</param>
 /// <param name="processCompletedCallback">The process completed callback, invoked only when the process is started successfully and completed.</param>
 /// <exception cref="ArgumentException">The <paramref name="fileName"/> is <c>null</c> or whitespace.</exception>
 /// <exception cref="Win32Exception">An error occurred when opening the associated file.</exception>
 public virtual void StartProcess(string fileName, string arguments = "", ProcessCompletedDelegate processCompletedCallback = null)
 {
     StartProcess(new ProcessContext
     {
         FileName  = fileName,
         Arguments = arguments
     }, processCompletedCallback);
 }
Example #2
0
        /// <summary>
        /// Starts a process resource by specifying the name of an application and a set of command-line arguments.
        /// </summary>
        /// <param name="processContext">The process context of an application file to run in the process.</param>
        /// <param name="processCompletedCallback">The process completed callback, invoked only when the process is started successfully and completed.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="processContext"/> is <c>null</c>.</exception>
        /// <exception cref="Win32Exception">An error occurred when opening the associated file.</exception>
        public virtual void StartProcess(ProcessContext processContext, ProcessCompletedDelegate processCompletedCallback = null)
        {
            var task = RunAsync(processContext);

            if (processCompletedCallback != null)
            {
                task.ContinueWith(x => processCompletedCallback(task.Result.ExitCode));
            }
        }
Example #3
0
        /// <summary>
        /// Starts a process resource by specifying the name of an application and a set of command-line arguments.
        /// </summary>
        /// <param name="fileName">The name of an application file to run in the process.</param>
        /// <param name="arguments">Command-line arguments to pass when starting the process.</param>
        /// <param name="processCompletedCallback">The process completed callback, invoked only when the process is started successfully and completed.</param>
        /// <exception cref="ArgumentException">The <paramref name="fileName"/> is <c>null</c> or whitespace.</exception>
        public void StartProcess(string fileName, string arguments = "", ProcessCompletedDelegate processCompletedCallback = null)
        {
            Argument.IsNotNullOrWhitespace("fileName", fileName);

            if (ExpectedResults.Count == 0)
            {
                throw new Exception(ResourceHelper.GetString("NoExpectedResultsInQueueForUnitTest"));
            }

            var result = ExpectedResults.Dequeue();
            if (result.Result)
            {
                if (processCompletedCallback != null)
                {
                    processCompletedCallback(result.ProcessResultCode);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Starts a process resource by specifying the name of an application and a set of command-line arguments.
        /// </summary>
        /// <param name="fileName">The name of an application file to run in the process.</param>
        /// <param name="arguments">Command-line arguments to pass when starting the process.</param>
        /// <param name="processCompletedCallback">The process completed callback, invoked only when the process is started successfully and completed.</param>
        /// <exception cref="ArgumentException">The <paramref name="fileName"/> is <c>null</c> or whitespace.</exception>
        public void StartProcess(string fileName, string arguments = "", ProcessCompletedDelegate processCompletedCallback = null)
        {
            Argument.IsNotNullOrWhitespace("fileName", fileName);

            if (ExpectedResults.Count == 0)
            {
                throw new Exception(ResourceHelper.GetString("NoExpectedResultsInQueueForUnitTest"));
            }

            var result = ExpectedResults.Dequeue();

            if (result.Result)
            {
                if (processCompletedCallback != null)
                {
                    processCompletedCallback(result.ProcessResultCode);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Starts a process resource by specifying the name of an application and a set of command-line arguments.
        /// </summary>
        /// <param name="fileName">The name of an application file to run in the process.</param>
        /// <param name="arguments">Command-line arguments to pass when starting the process.</param>
        /// <param name="processCompletedCallback">The process completed callback, invoked only when the process is started successfully and completed.</param>
        /// <exception cref="ArgumentException">The <paramref name="fileName"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="Win32Exception">An error occurred when opening the associated file.</exception>
        public virtual void StartProcess(string fileName, string arguments = "", ProcessCompletedDelegate processCompletedCallback = null)
        {
            Argument.IsNotNullOrWhitespace("fileName", fileName);

            if (arguments == null)
            {
                arguments = string.Empty;
            }

#if NETFX_CORE
            var launcher = Launcher.LaunchUriAsync(new Uri(fileName));
            if (processCompletedCallback != null)
            {
                launcher.Completed += (sender, e) => processCompletedCallback(0);
            }
#else
            var process = Process.Start(fileName, arguments);
            if (processCompletedCallback != null)
            {
                process.EnableRaisingEvents = true;
                process.Exited += (sender, e) => processCompletedCallback(process.ExitCode);
            }
#endif
        }