// 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);
        }
        /// <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);
        }
Esempio n. 3
0
 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");
     }
 }
        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();
        }
Esempio n. 5
0
        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();
        }