internal RunCommandsArguments(ActivityParameters activityParameters, PSDataCollection <PSObject> output, PSDataCollection <PSObject> input, PSActivityContext psActivityContext, PSWorkflowHost workflowHost, bool runInProc, Dictionary <string, object> parameterDefaults, Type activityType, PrepareSessionDelegate prepareSession, object activityObject, ActivityImplementationContext implementationContext) { this.ActivityParameters = activityParameters; this.Output = output; this.Input = input; this.PSActivityContext = psActivityContext; this.ParameterDefaults = parameterDefaults; this.ActivityType = activityType; this.Delegate = prepareSession; this.ActivityObject = activityObject; this.WorkflowHost = workflowHost; this.ImplementationContext = implementationContext; this.CommandExecutionType = RunCommandsArguments.DetermineCommandExecutionType(implementationContext.ConnectionInfo, runInProc, activityType, psActivityContext); }
public void Cancel() { ActivityImplementationContext activityImplementationContext = null; IAsyncResult asyncResult = null; if (this.WorkflowHost != null) { if (this.commandQueue != null) { while (!this.commandQueue.IsEmpty) { bool flag = this.commandQueue.TryDequeue(out activityImplementationContext); if (!flag) { continue; } PowerShell powerShellInstance = activityImplementationContext.PowerShellInstance; object[] objArray = new object[1]; objArray[0] = powerShellInstance; this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "PowerShell activity: Cancelling pending command {0}.", objArray)); powerShellInstance.Dispose(); } } PSResumableActivityHostController pSActivityHostController = this.WorkflowHost.PSActivityHostController as PSResumableActivityHostController; if (pSActivityHostController == null) { PSOutOfProcessActivityController pSOutOfProcessActivityController = this.WorkflowHost.PSActivityHostController as PSOutOfProcessActivityController; if (pSOutOfProcessActivityController != null) { while (this.AsyncResults.Count > 0) { this.AsyncResults.TryDequeue(out asyncResult); pSOutOfProcessActivityController.CancelInvokePowerShell(asyncResult); } } } else { pSActivityHostController.StopAllResumablePSCommands(this.JobInstanceId); } while (this.runningCommands.Count > 0) { PowerShell powerShell = null; lock (this.runningCommands) { Dictionary <PowerShell, RetryCount> .KeyCollection.Enumerator enumerator = this.runningCommands.Keys.GetEnumerator(); try { if (enumerator.MoveNext()) { PowerShell current = enumerator.Current; powerShell = current; } } finally { enumerator.Dispose(); } if (powerShell == null) { break; } } if (powerShell.InvocationStateInfo.State == PSInvocationState.Running) { object[] objArray1 = new object[1]; objArray1[0] = powerShell; this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "PowerShell activity: Stopping command {0}.", objArray1)); try { powerShell.Stop(); } catch (NullReferenceException nullReferenceException) { } catch (InvalidOperationException invalidOperationException) { } } if (powerShell.InvocationStateInfo.State != PSInvocationState.Completed || powerShell.HadErrors) { this.Failed = true; } int num = RunCommandsArguments.DetermineCommandExecutionType(powerShell.Runspace.ConnectionInfo as WSManConnectionInfo, this.RunInProc, this.ActivityType, this); if (num != 1) { PSActivity.CloseRunspaceAndDisposeCommand(powerShell, this.WorkflowHost, this, num); } this.runningCommands.Remove(powerShell); } return; } else { throw new InvalidOperationException("WorkflowHost"); } }