/// <summary> /// Constructor which creates a RunspacePool using the /// supplied <paramref name="configuration"/>, /// <paramref name="minRunspaces"/> and <paramref name="maxRunspaces"/> /// </summary> /// <param name="minRunspaces"> /// The minimum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="maxRunspaces"> /// The maximum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="host"> /// The explicit PSHost implementation. /// </param> /// <exception cref="ArgumentNullException"> /// Host is null. /// </exception> /// <exception cref="ArgumentException"> /// Maximum runspaces is less than 1. /// Minimum runspaces is less than 1. /// </exception> internal RunspacePool(int minRunspaces, int maxRunspaces, PSHost host) { // Currently we support only Local Runspace Pool.. // this needs to be changed once remote runspace pool // is implemented _internalPool = new RunspacePoolInternal(minRunspaces, maxRunspaces, host); }
/// <summary> /// Creates a runspace pool object in a disconnected state that is /// ready to connect to a remote runspace pool session specified by /// the instanceId parameter. /// </summary> /// <param name="isDisconnected">Indicates whether the shell/runspace pool is disconnected.</param> /// <param name="instanceId">Identifies a remote runspace pool session to connect to.</param> /// <param name="name">Friendly name for runspace pool.</param> /// <param name="connectCommands">Runspace pool running commands information.</param> /// <param name="connectionInfo">Connection information of remote server.</param> /// <param name="host">PSHost object.</param> /// <param name="typeTable">TypeTable used for serialization/deserialization of remote objects.</param> internal RunspacePool( bool isDisconnected, Guid instanceId, string name, ConnectCommandInfo[] connectCommands, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { // Disconnect-Connect semantics are currently only supported in WSMan transport. if (!(connectionInfo is WSManConnectionInfo)) { throw new NotSupportedException(); } _internalPool = new RemoteRunspacePoolInternal(instanceId, name, isDisconnected, connectCommands, connectionInfo, host, typeTable); IsRemote = true; }
/// <summary> /// Construct a runspace pool object. /// </summary> /// <param name="minRunspaces">Min runspaces.</param> /// <param name="maxRunspaces">Max runspaces.</param> /// <param name="typeTable">TypeTable.</param> /// <param name="host">Host.</param> /// <param name="applicationArguments">App arguments.</param> /// <param name="connectionInfo">Connection information.</param> /// <param name="name">Session name.</param> internal RunspacePool( int minRunspaces, int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo, string name = null) { _internalPool = new RemoteRunspacePoolInternal( minRunspaces, maxRunspaces, typeTable, host, applicationArguments, connectionInfo, name); IsRemote = true; }
/// <summary> /// Constructor which creates a RunspacePool using the /// supplied <paramref name="configuration"/>, <paramref name="minRunspaces"/> /// and <paramref name="maxRunspaces"/> /// </summary> /// <param name="runspaceConfiguration"> /// RunspaceConfiguration to use when creating a new Runspace. /// </param> /// <param name="maxRunspaces"> /// The maximum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="minRunspaces"> /// The minimum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="host"> /// The explicit PSHost implementation. /// </param> /// <exception cref="ArgumentNullException"> /// RunspaceConfiguration is null. /// Host is null. /// </exception> /// <exception cref="ArgumentException"> /// Maximum runspaces is less than 1. /// Minimum runspaces is less than 1. /// </exception> public RunspacePoolInternal(int minRunspaces, int maxRunspaces, RunspaceConfiguration runspaceConfiguration, PSHost host) : this(minRunspaces, maxRunspaces) { if (runspaceConfiguration == null) { throw PSTraceSource.NewArgumentNullException("runspaceConfiguration"); } if (host == null) { throw PSTraceSource.NewArgumentNullException("host"); } rsConfig = runspaceConfiguration; this.host = host; pool = new Stack<Runspace>(); runspaceRequestQueue = new Queue<GetRunspaceAsyncResult>(); ultimateRequestQueue = new Queue<GetRunspaceAsyncResult>(); }
/// <summary> /// Queries the server for disconnected runspace pools and creates an array of runspace /// pool objects associated with each disconnected runspace pool on the server. Each /// runspace pool object in the returned array is in the Disconnected state and can be /// connected to the server by calling the Connect() method on the runspace pool. /// </summary> /// <param name="connectionInfo">Connection object for the target server.</param> /// <param name="host">Client host object.</param> /// <param name="typeTable">TypeTable object.</param> /// <returns>Array of RunspacePool objects each in the Disconnected state.</returns> public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return(RemoteRunspacePoolInternal.GetRemoteRunspacePools(connectionInfo, host, typeTable)); }
/// <summary> /// Queries the server for disconnected runspace pools and creates an array of runspace /// pool objects associated with each disconnected runspace pool on the server. Each /// runspace pool object in the returned array is in the Disconnected state and can be /// connected to the server by calling the Connect() method on the runspace pool. /// </summary> /// <param name="connectionInfo">Connection object for the target server.</param> /// <param name="host">Client host object.</param> /// <returns>Array of RunspacePool objects each in the Disconnected state.</returns> public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host) { return(GetRunspacePools(connectionInfo, host, null)); }
/// <summary> /// Dispose off the current runspace pool /// </summary> /// <param name="disposing"> /// true to release all the internal resources. /// </param> public virtual void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { Close(); _cleanupTimer.Dispose(); _initialSessionState = null; host = null; } _isDisposed = true; } }
/// <summary> /// Starts progress bar. /// </summary> /// <param name="sourceId"></param> /// <param name="computerName"></param> /// <param name="secondsTotal"></param> /// <param name="psHost"></param> public void StartProgress( long sourceId, string computerName, int secondsTotal, System.Management.Automation.Host.PSHost psHost) { if (psHost == null) { return; } if (secondsTotal < 1) { return; } if (string.IsNullOrEmpty(computerName)) { throw new ArgumentNullException("computerName"); } lock (_syncObject) { if (_progressIsRunning) { return; } _progressIsRunning = true; _sourceId = sourceId; _secondsTotal = secondsTotal; _secondsRemaining = secondsTotal; _psHost = psHost; _status = StringUtil.Format(RemotingErrorIdStrings.RCProgressStatus, computerName); _progressRecord = new ProgressRecord(0, _activity, _status); // Create timer to fire every second to update progress bar. _updateTimer = new Timer(new TimerCallback(UpdateCallback), null, TimeSpan.Zero, new TimeSpan(0, 0, 1)); } }
/// <summary> /// Constructor which creates a RunspacePool using the /// supplied <paramref name="configuration"/>, <paramref name="minRunspaces"/> /// and <paramref name="maxRunspaces"/> /// </summary> /// <param name="initialSessionState"> /// InitialSessionState to use when creating a new Runspace. /// </param> /// <param name="maxRunspaces"> /// The maximum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="minRunspaces"> /// The minimum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="host"> /// The explicit PSHost implementation. /// </param> /// <exception cref="ArgumentNullException"> /// initialSessionState is null. /// Host is null. /// </exception> /// <exception cref="ArgumentException"> /// Maximum runspaces is less than 1. /// Minimum runspaces is less than 1. /// </exception> public RunspacePoolInternal(int minRunspaces, int maxRunspaces, InitialSessionState initialSessionState, PSHost host) : this(minRunspaces, maxRunspaces) { if (initialSessionState == null) { throw PSTraceSource.NewArgumentNullException("initialSessionState"); } if (host == null) { throw PSTraceSource.NewArgumentNullException("host"); } _initialSessionState = initialSessionState.Clone(); this.host = host; ThreadOptions = initialSessionState.ThreadOptions; #if !CORECLR // No ApartmentState In CoreCLR this.ApartmentState = initialSessionState.ApartmentState; #endif pool = new Stack<Runspace>(); runspaceRequestQueue = new Queue<GetRunspaceAsyncResult>(); ultimateRequestQueue = new Queue<GetRunspaceAsyncResult>(); }
/// <summary> /// Queries the server for disconnected runspace pools and creates an array of runspace /// pool objects associated with each disconnected runspace pool on the server. Each /// runspace pool object in the returned array is in the Disconnected state and can be /// connected to the server by calling the Connect() method on the runspace pool. /// </summary> /// <param name="connectionInfo">Connection object for the target server.</param> /// <param name="host">Client host object.</param> /// <returns>Array of RunspacePool objects each in the Disconnected state.</returns> public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host) { return GetRunspacePools(connectionInfo, host, null); }
/// <summary> /// Queries the server for disconnected runspace pools and creates an array of runspace /// pool objects associated with each disconnected runspace pool on the server. Each /// runspace pool object in the returned array is in the Disconnected state and can be /// connected to the server by calling the Connect() method on the runspace pool. /// </summary> /// <param name="connectionInfo">Connection object for the target server.</param> /// <param name="host">Client host object.</param> /// <param name="typeTable">TypeTable object.</param> /// <returns>Array of RunspacePool objects each in the Disconnected state.</returns> public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return RemoteRunspacePoolInternal.GetRemoteRunspacePools(connectionInfo, host, typeTable); }
/// <summary> /// Constructor which creates a RunspacePool using the /// supplied <paramref name="initialSessionState"/>, /// <paramref name="minRunspaces"/> and <paramref name="maxRunspaces"/> /// </summary> /// <param name="minRunspaces"> /// The minimum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="maxRunspaces"> /// The maximum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="initialSessionState"> /// InitialSessionState object to use when creating a new Runspace. /// </param> /// <param name="host"> /// The explicit PSHost implementation. /// </param> /// <exception cref="ArgumentNullException"> /// initialSessionState is null. /// Host is null. /// </exception> /// <exception cref="ArgumentException"> /// Maximum runspaces is less than 1. /// Minimum runspaces is less than 1. /// </exception> internal RunspacePool(int minRunspaces, int maxRunspaces, InitialSessionState initialSessionState, PSHost host) { // Currently we support only Local Runspace Pool.. // this needs to be changed once remote runspace pool // is implemented _internalPool = new RunspacePoolInternal(minRunspaces, maxRunspaces, initialSessionState, host); }
/// <summary> /// Constructor which creates a RunspacePool using the /// supplied <paramref name="configuration"/>, /// <paramref name="minRunspaces"/> and <paramref name="maxRunspaces"/> /// </summary> /// <param name="minRunspaces"> /// The minimum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="maxRunspaces"> /// The maximum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="runspaceConfiguration"> /// RunspaceConfiguration to use when creating a new Runspace. /// </param> /// <param name="host"> /// The explicit PSHost implementation. /// </param> /// <exception cref="ArgumentNullException"> /// RunspaceConfiguration is null. /// Host is null. /// </exception> /// <exception cref="ArgumentException"> /// Maximum runspaces is less than 1. /// Minimum runspaces is less than 1. /// </exception> internal RunspacePool(int minRunspaces, int maxRunspaces, RunspaceConfiguration runspaceConfiguration, PSHost host) { // Currently we support only Local Runspace Pool.. // this needs to be changed once remote runspace pool // is implemented _internalPool = new RunspacePoolInternal(minRunspaces, maxRunspaces, runspaceConfiguration, host); }
protected override bool ShouldRun(CommandInfo commandInfo, CommandOrigin origin, System.Management.Automation.Host.PSHost host, out Exception reason) { return(base.ShouldRun(commandInfo, origin, host, out reason)); }