Beispiel #1
0
        private void HandleWorkflowApplicationFaultedState(Exception e)
        {
            if (System.Threading.Interlocked.CompareExchange(ref terminalStateHandled, Handled, NotHandled) == Handled)
                return;

            Tracer.WriteMessage("Workflow Application is completed in Faulted state.");

            // there might be possible of race condition here in case of Winrm shutdown. if the activity is 
            // executing on loop back winrm process so there might be possibility that the winrm shuts down the 
            // activity process fist and causing the workflow to fail in the M3P process.
            // in order to avoid those situations we will ignore the remote exception if the shutdown is in progress
            if (WorkflowJobSourceAdapter.GetInstance().IsShutdownInProgress)
            {
                if (e.GetType() == typeof(RemoteException))
                {
                    Tracer.WriteMessage("PSWorkflowApplicationInstance", "HandleWorkflowApplicationFaultedState", id, "Since we are in shuting down mode so ignoring the remote exception");
                    Tracer.TraceException(e);

                    // no need to proceed any further
                    return;
                }
            }

            // before we start handling the faulted state we need to cancel
            // all running activities. Activities may be running if there is a 
            // parallel statement involved            
            StopAllAsyncExecutions();

            State = JobState.Failed;
            Exception reason = null;

            if (!_suppressTerminateError)
            {
                reason = e;

                ErrorRecord failureErrorRecord = GetInnerErrorRecord(reason);
                if (failureErrorRecord != null)
                {
                    reason = failureErrorRecord.Exception;

                    if (PSWorkflowJob.SynchronousExecution && Streams.ErrorStream.IsOpen)
                    {
                        // If we're running synchronously from the commandline, we want to see the error
                        // record from the workflow without the Receive-Job decoration. Receive-Job will
                        // decorate the reason, so do not send it as the reason.
                        // Note that if the error collection is closed, we do not want to lose this data, so
                        // pass the exception despite the bad decoration.
                        Streams.ErrorStream.Add(failureErrorRecord);
                        reason = null;
                    }
                }
                else
                {
                    // No error record, a raw exception was thrown. See if we have location
                    // information that we can wrap it in.
                    HostSettingCommandMetadata commandMetadata = null;

                    if (_paramDefaults != null)
                        commandMetadata = _paramDefaults.HostCommandMetadata;

                    if (commandMetadata != null)
                    {
                        ScriptPosition scriptStart = new ScriptPosition(
                            commandMetadata.CommandName,
                            commandMetadata.StartLineNumber,
                            commandMetadata.StartColumnNumber,
                            null);
                        ScriptPosition scriptEnd = new ScriptPosition(
                            commandMetadata.CommandName,
                            commandMetadata.EndLineNumber,
                            commandMetadata.EndColumnNumber,
                            null);
                        ScriptExtent extent = new ScriptExtent(scriptStart, scriptEnd);

                        reason = new JobFailedException(reason, extent);
                    }
                }
            }

            this.Error = reason;

            this.PerformTaskAtTerminalState();

            // do all cleanups here to save memory
            PerformCleanupAtTerminalState();

            if (this.OnFaulted != null)
                this.OnFaulted(reason, this);
        }
		private void HandleWorkflowApplicationFaultedState(Exception e)
		{
			if (Interlocked.CompareExchange(ref this.terminalStateHandled, 1, 0) != 1)
			{
				this.Tracer.WriteMessage("Workflow Application is completed in Faulted state.");
				if (!WorkflowJobSourceAdapter.GetInstance().IsShutdownInProgress || !(e.GetType() == typeof(RemoteException)))
				{
					this.StopAllAsyncExecutions();
					this.State = JobState.Failed;
					Exception jobFailedException = e;
					ErrorRecord innerErrorRecord = this.GetInnerErrorRecord(jobFailedException);
					if (innerErrorRecord == null)
					{
						HostSettingCommandMetadata hostCommandMetadata = null;
						if (this._paramDefaults != null)
						{
							hostCommandMetadata = this._paramDefaults.HostCommandMetadata;
						}
						if (hostCommandMetadata != null)
						{
							ScriptPosition scriptPosition = new ScriptPosition(hostCommandMetadata.CommandName, hostCommandMetadata.StartLineNumber, hostCommandMetadata.StartColumnNumber, null);
							ScriptPosition scriptPosition1 = new ScriptPosition(hostCommandMetadata.CommandName, hostCommandMetadata.EndLineNumber, hostCommandMetadata.EndColumnNumber, null);
							ScriptExtent scriptExtent = new ScriptExtent(scriptPosition, scriptPosition1);
							jobFailedException = new JobFailedException(jobFailedException, scriptExtent);
						}
					}
					else
					{
						jobFailedException = innerErrorRecord.Exception;
						if (this.PSWorkflowJob.SynchronousExecution && this.Streams.ErrorStream.IsOpen)
						{
							this.Streams.ErrorStream.Add(innerErrorRecord);
							jobFailedException = null;
						}
					}
					this.Error = jobFailedException;
					this.PerformTaskAtTerminalState();
					this.PerformCleanupAtTerminalState();
					if (base.OnFaulted != null)
					{
						base.OnFaulted(jobFailedException, this);
					}
					return;
				}
				else
				{
					this.Tracer.WriteMessage("PSWorkflowApplicationInstance", "HandleWorkflowApplicationFaultedState", this.id, "Sicne we are in shuting down mode so ignoring the remote exception", new string[0]);
					this.Tracer.TraceException(e);
					return;
				}
			}
			else
			{
				return;
			}
		}