internal IAsyncResult BeginInvokePowerShell(System.Management.Automation.PowerShell command, PSDataCollection<PSObject> input, PSDataCollection<PSObject> output, PSActivityEnvironment policy, AsyncCallback callback, object state)
		{
			if (command != null)
			{
				ConnectionAsyncResult connectionAsyncResult = new ConnectionAsyncResult(state, callback, command.InstanceId);
				this._structuredTracer.OutOfProcessRunspaceStarted(command.ToString());
				ActivityInvoker activityInvoker = new ActivityInvoker();
				activityInvoker.Input = input;
				activityInvoker.Output = output;
				activityInvoker.Policy = policy;
				activityInvoker.PowerShell = command;
				activityInvoker.AsyncResult = connectionAsyncResult;
				ActivityInvoker activityInvoker1 = activityInvoker;
				connectionAsyncResult.Invoker = activityInvoker1;
				this._requests.Enqueue(activityInvoker1);
				PSOutOfProcessActivityController.PerfCountersMgr.UpdateCounterByValue(PSWorkflowPerformanceCounterSetInfo.CounterSetId, 19, (long)1, true);
				PSOutOfProcessActivityController.PerfCountersMgr.UpdateCounterByValue(PSWorkflowPerformanceCounterSetInfo.CounterSetId, 20, (long)1, true);
				this.CheckAndStartServicingThread();
				return connectionAsyncResult;
			}
			else
			{
				throw new ArgumentNullException("command");
			}
		}
Ejemplo n.º 2
0
 public virtual void StartResumablePSCommand(Guid jobInstanceId,
                                             Bookmark bookmark,
                                             System.Management.Automation.PowerShell command,
                                             PowerShellStreams <PSObject, PSObject> streams,
                                             PSActivityEnvironment environment,
                                             PSActivity activityInstance)
 {
     throw new NotImplementedException();
 }
        // This function executes the activity.
        // It is highly recommended to not to block the execution of this function while executing the activity.
        // All the information should be logged into the queue and the function should be returned.
        // In a separate thread or on a separate machine, read the data from the queue and execute the activity.
        // Once the activity action is completed the bookmark should be resumed.
        // Design the activity controller to hanlde multiple activities from one workflowflow.
        public override void StartResumablePSCommand(Guid jobInstanceId, Bookmark bookmark, PowerShell command, PowerShellStreams<PSObject, PSObject> streams, PSActivityEnvironment environment, PSActivity activityInstance)
        {
            ActivityActionData data = new ActivityActionData();
            data.jobInstanceId = jobInstanceId;
            data.bookmark = bookmark;
            data.command = command;
            data.streams = streams;
            data.environment = environment;

            // Add the request to the queue.
            ActivityActionsQueue.TryAdd(jobInstanceId, data);

            // Return the fucntion and allow the workfow do other work in parallel.
            // There should be a servicing thead which gets the data from the queue and perform the action.
            // To keep this sample simple, the worker thread calls the servicing function.
            ThreadPool.QueueUserWorkItem(ServiceRequests, jobInstanceId);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Begin invocation of command specified in activity
        /// </summary>
        /// <param name="command">pipeline of command to execute</param>
        /// <param name="input">input collection</param>
        /// <param name="output">output collection</param>
        /// <param name="policy">policy to use for the activity</param>
        /// <param name="callback">optional callback</param>
        /// <param name="state">optional caller specified state</param>
        /// <returns>IAsyncResult</returns>
        internal IAsyncResult BeginInvokePowerShell(System.Management.Automation.PowerShell command, 
            PSDataCollection<PSObject> input, PSDataCollection<PSObject> output, PSActivityEnvironment policy, 
                AsyncCallback callback, object state)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            ConnectionAsyncResult result = new ConnectionAsyncResult(state, callback, command.InstanceId);

            _structuredTracer.OutOfProcessRunspaceStarted(command.ToString());

            ActivityInvoker invoker =
                new ActivityInvoker
                {
                    Input = input,
                    Output = output,
                    Policy = policy,
                    PowerShell = command,
                    AsyncResult = result
                };

            result.Invoker = invoker;

            _requests.Enqueue(invoker);
            PerfCountersMgr.UpdateCounterByValue(
                    PSWorkflowPerformanceCounterSetInfo.CounterSetId,
                    PSWorkflowPerformanceCounterIds.ActivityHostMgrIncomingRequestsPerSec);
            PerfCountersMgr.UpdateCounterByValue(
                    PSWorkflowPerformanceCounterSetInfo.CounterSetId,
                    PSWorkflowPerformanceCounterIds.ActivityHostMgrPendingRequestsQueueLength);
            CheckAndStartServicingThread();
            return result;
        }
Ejemplo n.º 5
0
        internal void RunPowerShellInActivityHost(System.Management.Automation.PowerShell powershell, PSDataCollection<PSObject> input,
            PSDataCollection<PSObject> output, PSActivityEnvironment policy, ConnectionAsyncResult asyncResult)
        {
            ActivityInvoker invoker =
                new ActivityInvoker
                    {
                        Input = input,
                        Output = output,
                        Policy = policy,
                        PowerShell = powershell,
                        AsyncResult = asyncResult
                    };

            _requests.Enqueue(invoker);
            CheckAndStartServicingThread();
        }        
		public virtual void StartResumablePSCommand(Guid jobInstanceId, Bookmark bookmark, System.Management.Automation.PowerShell command, PowerShellStreams<PSObject, PSObject> streams, PSActivityEnvironment environment, PSActivity activityInstance)
		{
			throw new NotImplementedException();
		}
		internal void RunPowerShellInActivityHost(System.Management.Automation.PowerShell powershell, PSDataCollection<PSObject> input, PSDataCollection<PSObject> output, PSActivityEnvironment policy, ConnectionAsyncResult asyncResult)
		{
			ActivityInvoker activityInvoker = new ActivityInvoker();
			activityInvoker.Input = input;
			activityInvoker.Output = output;
			activityInvoker.Policy = policy;
			activityInvoker.PowerShell = powershell;
			activityInvoker.AsyncResult = asyncResult;
			ActivityInvoker activityInvoker1 = activityInvoker;
			this._requests.Enqueue(activityInvoker1);
			this.CheckAndStartServicingThread();
		}
Ejemplo n.º 8
0
		private static void SetVariablesInRunspaceUsingProxy(PSActivityEnvironment activityEnvironment, Runspace runspace)
		{
			PowerShellTraceSource traceSource = PowerShellTraceSourceFactory.GetTraceSource();
			using (traceSource)
			{
				traceSource.WriteMessage("BEGIN SetVariablesInRunspaceUsingProxy");
				Dictionary<string, object> variablesToSetInRunspace = PSActivity.GetVariablesToSetInRunspace(activityEnvironment);
				foreach (string key in variablesToSetInRunspace.Keys)
				{
					object item = variablesToSetInRunspace[key];
					if (item == null)
					{
						continue;
					}
					try
					{
						runspace.SessionStateProxy.PSVariable.Set(key, item);
					}
					catch (PSNotSupportedException pSNotSupportedException)
					{
						traceSource.WriteMessage("SetVariablesInRunspaceUsingProxy: Copying the workflow variables to a RemoteSessionStateProxy is not supported.");
						return;
					}
				}
				traceSource.WriteMessage("END SetVariablesInRunspaceUsingProxy");
			}
		}
Ejemplo n.º 9
0
		private static Dictionary<string, object> GetVariablesToSetInRunspace(PSActivityEnvironment activityEnvironment)
		{
			InitialSessionStateEntryCollection<SessionStateVariableEntry> variables = PSActivity.Iss.Variables;
			Func<SessionStateVariableEntry, string> func = (SessionStateVariableEntry entry) => entry.Name;
			Dictionary<string, object> dictionary = variables.ToDictionary<SessionStateVariableEntry, string, object>(func, (SessionStateVariableEntry entry) => entry.Value);
			if (activityEnvironment != null && activityEnvironment.Variables != null)
			{
				foreach (string key in activityEnvironment.Variables.Keys)
				{
					object item = activityEnvironment.Variables[key];
					if (item == null)
					{
						continue;
					}
					if (!dictionary.ContainsKey(key))
					{
						dictionary.Add(key, item);
					}
					else
					{
						dictionary[key] = item;
					}
				}
			}
			if (dictionary.ContainsKey("OutputEncoding"))
			{
				dictionary.Remove("OutputEncoding");
			}
			return dictionary;
		}