Example #1
0
        public void ConstructorSetsProperties()
        {
            var data       = "Some Data";
            var outputType = ProcessOutputType.ErrorOutput;
            var args       = new ProcessOutputEventArgs(outputType, data);

            Assert.AreEqual(outputType, args.OutputType);
            Assert.AreEqual(data, args.Data);
        }
 private void run_OutputReceived(object sender, ProcessOutputEventArgs args)
 {
     if (args.Error)
     {
         lock (_sbExceptionsLock) { _sbExceptions.AppendLine(args.Data); }
     }
     else
     {
         lock (_sbStdOutLock) { _sbStdOut.AppendLine(args.Data); }
     }
 }
Example #3
0
        /// <summary>
        /// Event Handler for the ProcessOutput event of the ProcessExecutor.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="args">The event arguments.</param>
        /// <remarks></remarks>
        private void ProcessExecutor_ProcessOutput(object sender, ProcessOutputEventArgs args)
        {
            if (_buildProgressInformation == null)
            {
                return;
            }

            if (args.OutputType == ProcessOutputType.ErrorOutput)
            {
                return;
            }

            _buildProgressInformation.AddTaskInformation(args.Data);
        }
        private void ProcessExecutor_ProcessOutput(object sender, ProcessOutputEventArgs e)
        {
            if (buildProgressInformation == null)
            {
                return;
            }

            // ignore error output in the progress information
            //if (e.OutputType == ProcessOutputType.ErrorOutput)
            //	return;
            // show error output as requested by CCNET-1918:MSBuild task does not give console output error messages for report generators to use

            buildProgressInformation.AddTaskInformation(e.Data);
        }
Example #5
0
        private void ProcessExecutor_ProcessOutput(object sender, ProcessOutputEventArgs e)
        {
            if (_buildProgressInformation == null)
            {
                return;
            }

            // ignore error output in the progress information
            if (e.OutputType == ProcessOutputType.ErrorOutput)
            {
                return;
            }

            _buildProgressInformation.AddTaskInformation(e.Data);
        }
 protected virtual void OnOutputRecieved(object sender, ProcessOutputEventArgs args)
 {
     try
     {
         if (args.Error == true)
         {
             _colErrorLines.Add(args.Data);
             //Console.WriteLine("Error: " + args.Data);
         }
         else
         {
             _colOutputLines.Add(args.Data);
             //Console.WriteLine(args.Data);
         }
     }
     catch (Exception objEx)
     {
         DispatchException(objEx);
     }
 }
    override protected void OnOutputRecieved(object sender, ProcessOutputEventArgs objArgs)
    {
        //FMPEG out always shows as Error
        base.OnOutputRecieved(sender, objArgs);

        if (_bIsConverting == false && objArgs.Data.StartsWith("Press [q] to stop encoding") == true)
        {
            _bIsConverting = true;
        }
        else if (_bIsConverting == true && objArgs.Data.StartsWith("frame=") == true)
        {
            //Capture Progress
            UpdateProgressFromOutputLine(objArgs.Data);
        }
        else if (_bIsConverting == true && _nPercentageComplete > .8 && objArgs.Data.StartsWith("frame=") == false)
        {
            UpdateProgress(1);
            _bIsConverting = false;
        }
    }
Example #8
0
 private void InterfaceOnError(object sender, ProcessOutputEventArgs e)
 {
     Error?.Invoke(this, e);
 }
Example #9
0
 private void InterfaceOnOutput(object sender, ProcessOutputEventArgs e)
 {
     Output?.Invoke(this, e);
 }
Example #10
0
        /// <summary>
        /// Monitors the process and reads it's output. This method should only
        /// execute in the reader thread.
        /// </summary>
        protected override void ProcessReader()
        {
            ProcessOutputEventArgs outArgs  = null;
            PingProgressEventArgs  progress = null;
            var   output    = String.Empty;
            var   errMsg    = String.Empty;
            var   i         = 1;
            var   count     = this._count;
            var   succeeded = 0;
            var   failed    = 0;
            Match mReply    = null;
            Match mFailed   = null;

            try {
                // Start the process and raise the running event.
                this._pingProc.Start();
                base.OnProcessStarted(new ProcessStartedEventArgs(this._pingProc.Id));

                // Read the output until the process terminates.
                output = this._pingProc.StandardOutput.ReadLine();
                while ((output != null) && (!base.WasCancelled))
                {
                    // Notify output listeners.
                    outArgs = new ProcessOutputEventArgs(output);
                    base.OnOutputReceived(outArgs);

                    // See if the output message is a ping reply.
                    mReply  = this._reReply.Match(output);
                    mFailed = this._reFailed.Match(output);
                    if ((mReply.Success) || (mFailed.Success))
                    {
                        // If we're pinging continuously, the request count and
                        // current request are always equal.
                        if (this._continuous)
                        {
                            count = i;
                        }

                        // Compute responses received and lost.
                        if (mReply.Success)
                        {
                            succeeded++;
                        }

                        if ((mFailed.Success) || (output.Contains("unreachable")))
                        {
                            failed++;
                        }

                        // Raise progress event.
                        progress = new PingProgressEventArgs(i, succeeded, failed, count);
                        this.OnProgress(progress);
                        i++;
                    }

                    // This loop is blocking, which is why we are using a thread.
                    output = this._pingProc.StandardOutput.ReadLine();
                }

                // Wait for the process to finish up, then get the exit code.
                this._pingProc.WaitForExit();
                base._exitCode = this._pingProc.ExitCode;

                // If the progress hits 100% or the process terminated normally,
                // the notify listeners that we're done. Otherwise, notify output
                // and cancellation listeners.
                if ((base._exitCode == 0) || ((progress != null) && (progress.PercentComplete == 100)))
                {
                    base.OnProcessFinished(new ProccessDoneEventArgs(base._exitCode));
                }
                else
                {
                    errMsg = "A ping error occured: " + PingUtils.GetPingErrorMessage(this.ExitStatus) +
                             " Error code: " + base._exitCode.ToString();
                    base.OnOutputReceived(new ProcessOutputEventArgs(errMsg));
                    base.OnProcessCancelled(ProcessCancelledEventArgs.Empty);
                    lock (_flagLock) {
                        base._wasCancelled = true;
                    }
                }
            }
            catch (InvalidOperationException) {
                // This will occur if the Cancel() or Dispose() methods are called,
                // since this is expected to occur under these conditions, then just
                // raise the ProcessCancelled event.
                base.OnProcessCancelled(ProcessCancelledEventArgs.Empty);
                lock (_flagLock) {
                    base._wasCancelled = true;
                }
            }
            catch (Exception ex) {
                errMsg  = "An error occurred while reading process output: " + ex.ToString();
                outArgs = new ProcessOutputEventArgs(errMsg);
                base.OnOutputReceived(outArgs);
                base.OnProcessCancelled(new ProcessCancelledEventArgs(ex));
                lock (_flagLock) {
                    base._wasCancelled = true;
                }
            }
            finally {
                // Destroy the process and update the state flag.
                if (this._pingProc != null)
                {
                    this._pingProc.Close();
                    this._pingProc.Dispose();
                }

                lock (_flagLock) {
                    base._isRunning = false;
                }
            }
        }
Example #11
0
 /// <summary>
 /// Handles the output event from the ping module. This writes the
 /// output received to the console textbox.
 /// </summary>
 /// <param name="sender">
 /// The object sending the event call.
 /// </param>
 /// <param name="e">
 /// The event arguments.
 /// </param>
 private void Pm_OutputReceived(object sender, ProcessOutputEventArgs e)
 {
     this.SafeWriteConsole(e.StandardOutput);
 }
 static void run_OutputReceived(object sender, ProcessOutputEventArgs args)
 {
     Console.WriteLine("{0}: {1}", args.Error ? "Error" : "Output", args.Data);
 }
Example #13
0
        /// <summary>
        /// Monitors the process and reads it's output. This method should only
        /// execute in the reader thread.
        /// </summary>
        protected override void ProcessReader()
        {
            ProcessOutputEventArgs outArgs = null;
            var output = String.Empty;
            var errMsg = String.Empty;

            try {
                // Start the process and raise the running event.
                this._pathpingProc.Start();
                base.OnProcessStarted(new ProcessStartedEventArgs(this._pathpingProc.Id));

                // TODO Compute progress like we did in TraceRouteModule? Will need regex.

                // Read the output until the process terminates.
                output = this._pathpingProc.StandardOutput.ReadLine();
                while (output != null && !base.WasCancelled)
                {
                    // Notify output listeners.
                    outArgs = new ProcessOutputEventArgs(output);
                    base.OnOutputReceived(outArgs);

                    // This loop is blocking, which is why we are using a thread.
                    output = this._pathpingProc.StandardOutput.ReadLine();
                }

                // Wait for the process to finish up, then get the exit code.
                this._pathpingProc.WaitForExit();
                base._exitCode = this._pathpingProc.ExitCode;

                // If the process terminated normally, then notify listeners that
                // we're done. Otherwise, notify output and cancellation listeners.
                if (base._exitCode == 0)
                {
                    base.OnProcessFinished(new ProccessDoneEventArgs(base._exitCode));
                }
                else
                {
                    errMsg = "A pathping error occurred. Error code: " + base._exitCode.ToString();
                    base.OnOutputReceived(new ProcessOutputEventArgs(errMsg));
                    base.OnProcessCancelled(ProcessCancelledEventArgs.Empty);
                    lock (_flagLock) {
                        base._wasCancelled = true;
                    }
                }
            }
            catch (InvalidOperationException) {
                // This will occur if the Cancel() or Dispose() methods are called,
                // since this is expected to occur under these conditions, then just
                // raise the ProcessCancelled event.
                base.OnProcessCancelled(ProcessCancelledEventArgs.Empty);
                lock (_flagLock) {
                    base._wasCancelled = true;
                }
            }
            catch (Exception ex) {
                errMsg  = "An error occurred while reading process output: " + ex.ToString();
                outArgs = new ProcessOutputEventArgs(errMsg);
                base.OnOutputReceived(outArgs);
                base.OnProcessCancelled(new ProcessCancelledEventArgs(ex));
                lock (_flagLock) {
                    base._wasCancelled = true;
                }
            }
            finally {
                // Destroy the process and update the state flag.
                if (this._pathpingProc != null)
                {
                    this._pathpingProc.Dispose();
                }

                lock (_flagLock) {
                    base._isRunning = false;
                }
            }
        }
Example #14
0
        public void CanConstruct()
        {
            var args = new ProcessOutputEventArgs("test");

            Assert.True(args.StandardOutput.Equals("test"));
        }