Exemplo n.º 1
0
        /// <summary>
        /// Raises events for changes in execution state.
        /// </summary>
        protected void RaisePipelineStateEvents()
        {
            Queue <ExecutionEventQueueItem>       tempEventQueue = null;
            EventHandler <PipelineStateEventArgs> stateChanged   = null;
            bool runspaceHasAvailabilityChangedSubscribers       = false;

            lock (SyncRoot)
            {
                stateChanged = this.StateChanged;
                runspaceHasAvailabilityChangedSubscribers = _runspace.HasAvailabilityChangedSubscribers;

                if (stateChanged != null || runspaceHasAvailabilityChangedSubscribers)
                {
                    tempEventQueue       = _executionEventQueue;
                    _executionEventQueue = new Queue <ExecutionEventQueueItem>();
                }
                else
                {
                    //Clear the events if there are no EventHandlers. This
                    //ensures that events do not get called for state
                    //changes prior to their registration.
                    _executionEventQueue.Clear();
                }
            }

            if (tempEventQueue != null)
            {
                while (tempEventQueue.Count > 0)
                {
                    ExecutionEventQueueItem queueItem = tempEventQueue.Dequeue();

                    if (runspaceHasAvailabilityChangedSubscribers && queueItem.NewRunspaceAvailability != queueItem.CurrentRunspaceAvailability)
                    {
                        _runspace.RaiseAvailabilityChangedEvent(queueItem.NewRunspaceAvailability);
                    }

                    // this is shipped as part of V1. So disabling the warning here.
#pragma warning disable 56500
                    //Exception rasied in the eventhandler are not error in pipeline.
                    //silently ignore them.
                    if (stateChanged != null)
                    {
                        try
                        {
                            stateChanged(this, new PipelineStateEventArgs(queueItem.PipelineStateInfo));
                        }
                        catch (Exception exception) // ignore non-severe exceptions
                        {
                            CommandProcessorBase.CheckForSevereException(exception);
                        }
                    }
#pragma warning restore 56500
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Raises events for changes in execution state.
        /// </summary>
        protected void RaisePipelineStateEvents()
        {
            Queue <ExecutionEventQueueItem>       tempEventQueue = null;
            EventHandler <PipelineStateEventArgs> stateChanged   = null;
            bool runspaceHasAvailabilityChangedSubscribers       = false;

            lock (_syncRoot)
            {
                stateChanged = this.StateChanged;
                runspaceHasAvailabilityChangedSubscribers = _runspace.HasAvailabilityChangedSubscribers;

                if (stateChanged != null || runspaceHasAvailabilityChangedSubscribers)
                {
                    tempEventQueue       = _executionEventQueue;
                    _executionEventQueue = new Queue <ExecutionEventQueueItem>();
                }
                else
                {
                    //Clear the events if there are no EventHandlers. This
                    //ensures that events do not get called for state
                    //changes prior to their registration.
                    _executionEventQueue.Clear();
                }
            }

            if (tempEventQueue != null)
            {
                while (tempEventQueue.Count > 0)
                {
                    ExecutionEventQueueItem queueItem = tempEventQueue.Dequeue();

                    if (runspaceHasAvailabilityChangedSubscribers && queueItem.NewRunspaceAvailability != queueItem.CurrentRunspaceAvailability)
                    {
                        _runspace.RaiseAvailabilityChangedEvent(queueItem.NewRunspaceAvailability);
                    }

                    //Exception raised in the eventhandler are not error in pipeline.
                    //silently ignore them.
                    if (stateChanged != null)
                    {
                        try
                        {
                            stateChanged(this, new PipelineStateEventArgs(queueItem.PipelineStateInfo));
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected void RaisePipelineStateEvents()
        {
            Queue <ExecutionEventQueueItem>       queue        = null;
            EventHandler <PipelineStateEventArgs> stateChanged = null;
            bool hasAvailabilityChangedSubscribers             = false;

            lock (this.SyncRoot)
            {
                stateChanged = this.StateChanged;
                hasAvailabilityChangedSubscribers = this._runspace.HasAvailabilityChangedSubscribers;
                if ((stateChanged != null) || hasAvailabilityChangedSubscribers)
                {
                    queue = this._executionEventQueue;
                    this._executionEventQueue = new Queue <ExecutionEventQueueItem>();
                }
                else
                {
                    this._executionEventQueue.Clear();
                }
            }
            if (queue != null)
            {
                while (queue.Count > 0)
                {
                    ExecutionEventQueueItem item = queue.Dequeue();
                    if (hasAvailabilityChangedSubscribers && (item.NewRunspaceAvailability != item.CurrentRunspaceAvailability))
                    {
                        this._runspace.RaiseAvailabilityChangedEvent(item.NewRunspaceAvailability);
                    }
                    if (stateChanged != null)
                    {
                        try
                        {
                            stateChanged(this, new PipelineStateEventArgs(item.PipelineStateInfo));
                            continue;
                        }
                        catch (Exception exception)
                        {
                            CommandProcessorBase.CheckForSevereException(exception);
                            continue;
                        }
                    }
                }
            }
        }