Ejemplo n.º 1
0
 private void InternalClearAllResources()
 {
     Exception exception = new InvalidRunspacePoolStateException(StringUtil.Format(RunspacePoolStrings.InvalidRunspacePoolState, RunspacePoolState.Opened, this.stateInfo.State), this.stateInfo.State, RunspacePoolState.Opened);
     lock (this.runspaceRequestQueue)
     {
         while (this.runspaceRequestQueue.Count > 0)
         {
             this.runspaceRequestQueue.Dequeue().SetAsCompleted(exception);
         }
     }
     lock (this.ultimateRequestQueue)
     {
         while (this.ultimateRequestQueue.Count > 0)
         {
             this.ultimateRequestQueue.Dequeue().SetAsCompleted(exception);
         }
     }
     List<Runspace> list = new List<Runspace>();
     lock (this.runspaceList)
     {
         list.AddRange(this.runspaceList);
         this.runspaceList.Clear();
     }
     for (int i = list.Count - 1; i >= 0; i--)
     {
         try
         {
             list[i].Close();
             list[i].Dispose();
         }
         catch (InvalidRunspaceStateException exception2)
         {
             CommandProcessorBase.CheckForSevereException(exception2);
         }
     }
     lock (this.pool)
     {
         this.pool.Clear();
     }
 }
Ejemplo n.º 2
0
 protected void AssertIfStateIsBeforeOpen()
 {
     if (this.stateInfo.State != RunspacePoolState.BeforeOpen)
     {
         InvalidRunspacePoolStateException exception = new InvalidRunspacePoolStateException(StringUtil.Format(RunspacePoolStrings.CannotOpenAgain, new object[] { this.stateInfo.State.ToString() }), this.stateInfo.State, RunspacePoolState.BeforeOpen);
         throw exception;
     }
 }
Ejemplo n.º 3
0
 public override IAsyncResult BeginConnect(AsyncCallback callback, object state)
 {
     RunspacePoolState state2;
     if (!this.AvailableForConnection)
     {
         throw PSTraceSource.NewInvalidOperationException("RunspacePoolStrings", "CannotConnect", new object[0]);
     }
     bool flag = false;
     lock (base.syncObject)
     {
         state2 = base.stateInfo.State;
         if (state2 == RunspacePoolState.Disconnected)
         {
             RunspacePoolStateInfo newStateInfo = new RunspacePoolStateInfo(RunspacePoolState.Connecting, null);
             this.SetRunspacePoolState(newStateInfo);
             flag = true;
         }
     }
     if (flag)
     {
         base.RaiseStateChangeEvent(base.stateInfo);
     }
     flag = false;
     if (state2 == RunspacePoolState.Disconnected)
     {
         RunspacePoolAsyncResult reconnectAsyncResult;
         if (this.canReconnect)
         {
             this.dataStructureHandler.ReconnectPoolAsync();
             this.reconnectAsyncResult = new RunspacePoolAsyncResult(base.instanceId, callback, state, false);
             reconnectAsyncResult = this.reconnectAsyncResult;
         }
         else
         {
             this.dataStructureHandler.ConnectPoolAsync();
             this.openAsyncResult = new RunspacePoolAsyncResult(base.instanceId, callback, state, false);
             reconnectAsyncResult = this.openAsyncResult;
         }
         if (flag)
         {
             base.RaiseStateChangeEvent(base.stateInfo);
         }
         return reconnectAsyncResult;
     }
     InvalidRunspacePoolStateException exception = new InvalidRunspacePoolStateException(StringUtil.Format(RunspacePoolStrings.InvalidRunspacePoolState, RunspacePoolState.Disconnected, base.stateInfo.State), base.stateInfo.State, RunspacePoolState.Disconnected);
     throw exception;
 }
Ejemplo n.º 4
0
 public override IAsyncResult BeginDisconnect(AsyncCallback callback, object state)
 {
     RunspacePoolState state2;
     if (!this.CanDisconnect)
     {
         throw PSTraceSource.NewInvalidOperationException("RunspacePoolStrings", "DisconnectNotSupportedOnServer", new object[0]);
     }
     bool flag = false;
     lock (base.syncObject)
     {
         state2 = base.stateInfo.State;
         if (state2 == RunspacePoolState.Opened)
         {
             RunspacePoolStateInfo newStateInfo = new RunspacePoolStateInfo(RunspacePoolState.Disconnecting, null);
             this.SetRunspacePoolState(newStateInfo);
             flag = true;
         }
     }
     if (flag)
     {
         base.RaiseStateChangeEvent(base.stateInfo);
     }
     if (state2 == RunspacePoolState.Opened)
     {
         this.disconnectAsyncResult = new RunspacePoolAsyncResult(base.instanceId, callback, state, false);
         this.dataStructureHandler.DisconnectPoolAsync();
         return this.disconnectAsyncResult;
     }
     InvalidRunspacePoolStateException exception = new InvalidRunspacePoolStateException(StringUtil.Format(RunspacePoolStrings.InvalidRunspacePoolState, RunspacePoolState.Opened, base.stateInfo.State), base.stateInfo.State, RunspacePoolState.Opened);
     throw exception;
 }
Ejemplo n.º 5
0
 internal InvalidRunspaceStateException ToInvalidRunspaceStateException() => new InvalidRunspaceStateException(ResourceManagerCache.GetResourceString("Runspace", "InvalidRunspaceStateGeneral"), (Exception) this)
 {
     CurrentState  = InvalidRunspacePoolStateException.RunspacePoolStateToRunspaceState(this.CurrentState),
     ExpectedState = InvalidRunspacePoolStateException.RunspacePoolStateToRunspaceState(this.ExpectedState)
 };