Ejemplo n.º 1
0
        private void ServiceCallbacks(object state)
        {
            LocalRunspaceAsyncResult localRunspaceAsyncResult = null;

            while (this._callbacks.TryDequeue(out localRunspaceAsyncResult))
            {
                localRunspaceAsyncResult.SetAsCompleted(null);
            }
            Interlocked.CompareExchange(ref this._isServicingCallbacks, 0, 1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Begin for obtaining a runspace for the specified ConnectionInfo
        /// </summary>
        /// <param name="connectionInfo">connection info to be used for remote connections</param>
        /// <param name="retryCount">number of times to retry</param>
        /// <param name="callback">optional user defined callback</param>
        /// <param name="state">optional user specified state</param>
        /// <param name="retryInterval">time in milliseconds before the next retry has to be attempted</param>
        /// <returns>async result</returns>
        public override IAsyncResult BeginGetRunspace(WSManConnectionInfo connectionInfo, uint retryCount, uint retryInterval, AsyncCallback callback, object state)
        {
            if (connectionInfo != null)
            {
                throw new InvalidOperationException();
            }

            LocalRunspaceAsyncResult asyncResult = new LocalRunspaceAsyncResult(state, callback, Guid.Empty);

            // Get the source language mode from the activity arguments if available and pass to runspace fetching.
            PSLanguageMode?      sourceLanguageMode = null;
            RunCommandsArguments args = state as RunCommandsArguments;

            if (args != null)
            {
                PSWorkflowRuntime wfRuntime = args.WorkflowHost as PSWorkflowRuntime;
                if (wfRuntime != null)
                {
                    PSWorkflowJob wfJob = wfRuntime.JobManager.GetJob(args.PSActivityContext.JobInstanceId);
                    if (wfJob != null)
                    {
                        sourceLanguageMode = wfJob.SourceLanguageMode;
                    }
                }
            }

            Runspace runspace = AssignRunspaceIfPossible(sourceLanguageMode);

            if (runspace != null)
            {
                asyncResult.Runspace = runspace;
                asyncResult.CompletedSynchronously = true;
                asyncResult.SetAsCompleted(null);
            }
            else
            {
                // queue the request
                _requests.Enqueue(asyncResult);
                CheckAndStartRequestServicingThread();
            }

            return(asyncResult);
        }
Ejemplo n.º 3
0
 public override IAsyncResult BeginGetRunspace(WSManConnectionInfo connectionInfo, uint retryCount, uint retryInterval, AsyncCallback callback, object state)
 {
     if (connectionInfo == null)
     {
         LocalRunspaceAsyncResult localRunspaceAsyncResult = new LocalRunspaceAsyncResult(state, callback, Guid.Empty);
         Runspace runspace = this.AssignRunspaceIfPossible();
         if (runspace == null)
         {
             this._requests.Enqueue(localRunspaceAsyncResult);
             this.CheckAndStartRequestServicingThread();
         }
         else
         {
             localRunspaceAsyncResult.Runspace = runspace;
             localRunspaceAsyncResult.CompletedSynchronously = true;
             localRunspaceAsyncResult.SetAsCompleted(null);
         }
         return(localRunspaceAsyncResult);
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Ejemplo n.º 4
0
		public override IAsyncResult BeginGetRunspace(WSManConnectionInfo connectionInfo, uint retryCount, uint retryInterval, AsyncCallback callback, object state)
		{
			if (connectionInfo == null)
			{
				LocalRunspaceAsyncResult localRunspaceAsyncResult = new LocalRunspaceAsyncResult(state, callback, Guid.Empty);
				Runspace runspace = this.AssignRunspaceIfPossible();
				if (runspace == null)
				{
					this._requests.Enqueue(localRunspaceAsyncResult);
					this.CheckAndStartRequestServicingThread();
				}
				else
				{
					localRunspaceAsyncResult.Runspace = runspace;
					localRunspaceAsyncResult.CompletedSynchronously = true;
					localRunspaceAsyncResult.SetAsCompleted(null);
				}
				return localRunspaceAsyncResult;
			}
			else
			{
				throw new InvalidOperationException();
			}
		}
Ejemplo n.º 5
0
        /// <summary>
        /// Begin for obtaining a runspace for the specified ConnectionInfo
        /// </summary>
        /// <param name="connectionInfo">connection info to be used for remote connections</param>
        /// <param name="retryCount">number of times to retry</param>
        /// <param name="callback">optional user defined callback</param>
        /// <param name="state">optional user specified state</param>
        /// <param name="retryInterval">time in milliseconds before the next retry has to be attempted</param>
        /// <returns>async result</returns>
        public override IAsyncResult BeginGetRunspace(WSManConnectionInfo connectionInfo, uint retryCount, uint retryInterval, AsyncCallback callback, object state)
        {
            if (connectionInfo != null)
            {
                throw new InvalidOperationException();
            }

            LocalRunspaceAsyncResult asyncResult = new LocalRunspaceAsyncResult(state, callback, Guid.Empty);

            // Get the source language mode from the activity arguments if available and pass to runspace fetching.
            PSLanguageMode? sourceLanguageMode = null;
            RunCommandsArguments args = state as RunCommandsArguments;
            if (args != null)
            {
                PSWorkflowRuntime wfRuntime = args.WorkflowHost as PSWorkflowRuntime;
                if (wfRuntime != null)
                {
                    PSWorkflowJob wfJob = wfRuntime.JobManager.GetJob(args.PSActivityContext.JobInstanceId);
                    if (wfJob != null)
                    {
                        sourceLanguageMode = wfJob.SourceLanguageMode;
                    }
                }
            }

            Runspace runspace = AssignRunspaceIfPossible(sourceLanguageMode);
            if (runspace != null)
            {
                asyncResult.Runspace = runspace;
                asyncResult.CompletedSynchronously = true;
                asyncResult.SetAsCompleted(null);
            }
            else
            {
                // queue the request
                _requests.Enqueue(asyncResult);
                CheckAndStartRequestServicingThread();
            }

            return asyncResult;
        }