示例#1
0
 private void SetEventHandlers()
 {
     base.InstanceId    = this._runspacePool.InstanceId;
     this._eventManager = new PSRemoteEventManager(this._connectionInfo.ComputerName, base.InstanceId);
     this._runspacePool.StateChanged += new EventHandler <RunspacePoolStateChangedEventArgs>(this.HandleRunspacePoolStateChanged);
     this._runspacePool.RemoteRunspacePoolInternal.HostCallReceived       += new EventHandler <RemoteDataEventArgs <RemoteHostCall> >(this.HandleHostCallReceived);
     this._runspacePool.RemoteRunspacePoolInternal.URIRedirectionReported += new EventHandler <RemoteDataEventArgs <Uri> >(this.HandleURIDirectionReported);
     this._runspacePool.ForwardEvent += new EventHandler <PSEventArgs>(this.HandleRunspacePoolForwardEvent);
     this._runspacePool.RemoteRunspacePoolInternal.SessionCreateCompleted += new EventHandler <CreateCompleteEventArgs>(this.HandleSessionCreateCompleted);
 }
示例#2
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (!this._disposed)
         {
             lock (this._syncRoot)
             {
                 if (this._disposed)
                 {
                     return;
                 }
                 this._disposed = true;
             }
             if (disposing)
             {
                 this.Close();
                 try
                 {
                     this._runspacePool.StateChanged -= new EventHandler <RunspacePoolStateChangedEventArgs>(this.HandleRunspacePoolStateChanged);
                     this._runspacePool.RemoteRunspacePoolInternal.HostCallReceived       -= new EventHandler <RemoteDataEventArgs <RemoteHostCall> >(this.HandleHostCallReceived);
                     this._runspacePool.RemoteRunspacePoolInternal.URIRedirectionReported -= new EventHandler <RemoteDataEventArgs <Uri> >(this.HandleURIDirectionReported);
                     this._runspacePool.ForwardEvent -= new EventHandler <PSEventArgs>(this.HandleRunspacePoolForwardEvent);
                     this._runspacePool.RemoteRunspacePoolInternal.SessionCreateCompleted -= new EventHandler <CreateCompleteEventArgs>(this.HandleSessionCreateCompleted);
                     this._eventManager = null;
                     this._runspacePool.Dispose();
                 }
                 catch (InvalidRunspacePoolStateException exception)
                 {
                     throw exception.ToInvalidRunspaceStateException();
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
示例#3
0
        /// <summary>
        /// Dispose this runspace
        /// </summary>
        /// <param name="disposing">true if called from Dispose</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (_disposed)
                {
                    return;
                }

                lock (_syncRoot)
                {
                    if (_disposed)
                    {
                        return;
                    }

                    _disposed = true;
                }

                if (disposing)
                {
                    try
                    {
                        Close();
                    }
                    catch (PSRemotingTransportException)
                    {
                        // 
                        // If the WinRM listener has been removed before the runspace is closed, then calling
                        // Close() will cause a PSRemotingTransportException.  We don't want this exception 
                        // surfaced.  Most developers don't expect an exception from calling Dispose.
                        // See [Windows 8 Bugs] 968184.
                        //
                    }

                    if (_remoteDebugger != null)
                    {
                        // Release RunspacePool event forwarding handlers.
                        _remoteDebugger.Dispose();
                    }

                    try
                    {
                        RunspacePool.StateChanged -=
                                        new EventHandler<RunspacePoolStateChangedEventArgs>(HandleRunspacePoolStateChanged);
                        RunspacePool.RemoteRunspacePoolInternal.HostCallReceived -=
                            new EventHandler<RemoteDataEventArgs<RemoteHostCall>>(HandleHostCallReceived);
                        RunspacePool.RemoteRunspacePoolInternal.URIRedirectionReported -=
                            new EventHandler<RemoteDataEventArgs<Uri>>(HandleURIDirectionReported);
                        RunspacePool.ForwardEvent -=
                            new EventHandler<PSEventArgs>(HandleRunspacePoolForwardEvent);

                        RunspacePool.RemoteRunspacePoolInternal.SessionCreateCompleted -=
                            new EventHandler<CreateCompleteEventArgs>(HandleSessionCreateCompleted);

                        _eventManager = null;

                        RunspacePool.Dispose();
                        //_runspacePool = null;
                    }
                    catch (InvalidRunspacePoolStateException e)
                    {
                        throw e.ToInvalidRunspaceStateException();
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
示例#4
0
        /// <summary>
        /// Helper function to set event handlers.
        /// </summary>
        private void SetEventHandlers()
        {
            // RemoteRunspace must have the same instanceID as its contained RunspacePool instance because
            // the PSRP/WinRS layer tracks remote runspace Ids.
            this.InstanceId = RunspacePool.InstanceId;

            _eventManager = new PSRemoteEventManager(_connectionInfo.ComputerName, this.InstanceId);

            RunspacePool.StateChanged +=
                new EventHandler<RunspacePoolStateChangedEventArgs>(HandleRunspacePoolStateChanged);
            RunspacePool.RemoteRunspacePoolInternal.HostCallReceived +=
                new EventHandler<RemoteDataEventArgs<RemoteHostCall>>(HandleHostCallReceived);
            RunspacePool.RemoteRunspacePoolInternal.URIRedirectionReported +=
                new EventHandler<RemoteDataEventArgs<Uri>>(HandleURIDirectionReported);
            RunspacePool.ForwardEvent +=
                new EventHandler<PSEventArgs>(HandleRunspacePoolForwardEvent);

            RunspacePool.RemoteRunspacePoolInternal.SessionCreateCompleted +=
                new EventHandler<CreateCompleteEventArgs>(HandleSessionCreateCompleted);
        }
示例#5
0
 private void SetEventHandlers()
 {
     base.InstanceId = this._runspacePool.InstanceId;
     this._eventManager = new PSRemoteEventManager(this._connectionInfo.ComputerName, base.InstanceId);
     this._runspacePool.StateChanged += new EventHandler<RunspacePoolStateChangedEventArgs>(this.HandleRunspacePoolStateChanged);
     this._runspacePool.RemoteRunspacePoolInternal.HostCallReceived += new EventHandler<RemoteDataEventArgs<RemoteHostCall>>(this.HandleHostCallReceived);
     this._runspacePool.RemoteRunspacePoolInternal.URIRedirectionReported += new EventHandler<RemoteDataEventArgs<Uri>>(this.HandleURIDirectionReported);
     this._runspacePool.ForwardEvent += new EventHandler<PSEventArgs>(this.HandleRunspacePoolForwardEvent);
     this._runspacePool.RemoteRunspacePoolInternal.SessionCreateCompleted += new EventHandler<CreateCompleteEventArgs>(this.HandleSessionCreateCompleted);
 }
示例#6
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (!this._disposed)
         {
             lock (this._syncRoot)
             {
                 if (this._disposed)
                 {
                     return;
                 }
                 this._disposed = true;
             }
             if (disposing)
             {
                 this.Close();
                 try
                 {
                     this._runspacePool.StateChanged -= new EventHandler<RunspacePoolStateChangedEventArgs>(this.HandleRunspacePoolStateChanged);
                     this._runspacePool.RemoteRunspacePoolInternal.HostCallReceived -= new EventHandler<RemoteDataEventArgs<RemoteHostCall>>(this.HandleHostCallReceived);
                     this._runspacePool.RemoteRunspacePoolInternal.URIRedirectionReported -= new EventHandler<RemoteDataEventArgs<Uri>>(this.HandleURIDirectionReported);
                     this._runspacePool.ForwardEvent -= new EventHandler<PSEventArgs>(this.HandleRunspacePoolForwardEvent);
                     this._runspacePool.RemoteRunspacePoolInternal.SessionCreateCompleted -= new EventHandler<CreateCompleteEventArgs>(this.HandleSessionCreateCompleted);
                     this._eventManager = null;
                     this._runspacePool.Dispose();
                 }
                 catch (InvalidRunspacePoolStateException exception)
                 {
                     throw exception.ToInvalidRunspaceStateException();
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }