internal RemoteRunspacePoolInternal(int minRunspaces, int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo, string name = null) : base(minRunspaces, maxRunspaces) { this.applicationPrivateDataReceived = new ManualResetEvent(false); this.friendlyName = string.Empty; if (connectionInfo == null) { throw PSTraceSource.NewArgumentNullException("WSManConnectionInfo"); } PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, new object[] { this.instanceId.ToString(), this.minPoolSz.ToString(CultureInfo.InvariantCulture), this.maxPoolSz.ToString(CultureInfo.InvariantCulture) }); if (connectionInfo is WSManConnectionInfo) { this.connectionInfo = ((WSManConnectionInfo) connectionInfo).Copy(); } else if (connectionInfo is NewProcessConnectionInfo) { this.connectionInfo = ((NewProcessConnectionInfo) connectionInfo).Copy(); } base.host = host; this.applicationArguments = applicationArguments; this.availableForConnection = false; this.dispatchTable = new DispatchTable<object>(); if (!string.IsNullOrEmpty(name)) { this.Name = name; } this.CreateDSHandler(typeTable); }
internal RemoteRunspace(TypeTable typeTable, RunspaceConnectionInfo connectionInfo, PSHost host, PSPrimitiveDictionary applicationArguments, string name = null, int id = -1) { this._runningPipelines = new ArrayList(); this._syncRoot = new object(); this._runspaceStateInfo = new System.Management.Automation.Runspaces.RunspaceStateInfo(RunspaceState.BeforeOpen); this._version = PSVersionInfo.PSVersion; this._runspaceEventQueue = new Queue<RunspaceEventQueueItem>(); this.id = -1; PSEtwLog.SetActivityIdForCurrentThread(base.InstanceId); this._applicationArguments = applicationArguments; PSEtwLog.LogOperationalVerbose(PSEventId.RunspaceConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, new object[] { base.InstanceId.ToString() }); if (connectionInfo is WSManConnectionInfo) { this._connectionInfo = ((WSManConnectionInfo) connectionInfo).Copy(); this._originalConnectionInfo = ((WSManConnectionInfo) connectionInfo).Copy(); } else if (connectionInfo is NewProcessConnectionInfo) { this._connectionInfo = ((NewProcessConnectionInfo) connectionInfo).Copy(); this._originalConnectionInfo = ((NewProcessConnectionInfo) connectionInfo).Copy(); } this._runspacePool = new System.Management.Automation.Runspaces.RunspacePool(1, 1, typeTable, host, applicationArguments, connectionInfo, name); this.Id = id; this.SetEventHandlers(); }
internal RemoteRunspacePoolInternal(Guid instanceId, string name, bool isDisconnected, ConnectCommandInfo[] connectCommands, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) : base(1, 1) { this.applicationPrivateDataReceived = new ManualResetEvent(false); this.friendlyName = string.Empty; if (connectCommands == null) { throw PSTraceSource.NewArgumentNullException("ConnectCommandInfo[]"); } if (connectionInfo == null) { throw PSTraceSource.NewArgumentNullException("WSManConnectionInfo"); } if (connectionInfo is WSManConnectionInfo) { this.connectionInfo = ((WSManConnectionInfo) connectionInfo).Copy(); } base.instanceId = instanceId; base.minPoolSz = -1; base.maxPoolSz = -1; PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, new object[] { instanceId.ToString(), this.minPoolSz.ToString(CultureInfo.InvariantCulture), this.maxPoolSz.ToString(CultureInfo.InvariantCulture) }); this.connectCommands = connectCommands; this.Name = name; base.host = host; this.dispatchTable = new DispatchTable<object>(); this.SetRunspacePoolState(new RunspacePoolStateInfo(RunspacePoolState.Disconnected, null)); this.CreateDSHandler(typeTable); this.availableForConnection = isDisconnected; }
public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable, PowerShellProcessInstance processInstance) { NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(null) { Process = processInstance }; return CreateRunspace(connectionInfo, null, typeTable); }
/// <summary> /// /// </summary> /// <param name="connectionInfo"></param> /// <param name="host"></param> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="applicationArguments"> /// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/> /// </param> /// <param name="name">Name for remote runspace.</param> /// <returns></returns> public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments, string name) { if ((!(connectionInfo is WSManConnectionInfo)) && (!(connectionInfo is NewProcessConnectionInfo)) && (!(connectionInfo is NamedPipeConnectionInfo)) && (!(connectionInfo is SSHConnectionInfo)) && (!(connectionInfo is VMConnectionInfo)) && (!(connectionInfo is ContainerConnectionInfo))) { throw new NotSupportedException(); } if (connectionInfo is WSManConnectionInfo) { RemotingCommandUtil.CheckHostRemotingPrerequisites(); } return(new RemoteRunspace(typeTable, connectionInfo, host, applicationArguments, name)); }
/// <summary> /// /// </summary> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="host"></param> /// <param name="connectionInfo"></param> /// <returns></returns> public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return(CreateRunspace(connectionInfo, host, typeTable, null, null)); }
/// <summary> /// </summary> /// <param name="typeTable"></param> /// <returns></returns> public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable) { NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(null); return(CreateRunspace(connectionInfo, null, typeTable)); }
public static RunspacePool CreateRunspacePool(int minRunspaces, int maxRunspaces, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) { if (connectionInfo is not WSManConnectionInfo && connectionInfo is not NewProcessConnectionInfo && connectionInfo is not NamedPipeConnectionInfo && connectionInfo is not VMConnectionInfo && connectionInfo is not ContainerConnectionInfo) { throw new NotSupportedException(); } if (connectionInfo is WSManConnectionInfo) { RemotingCommandUtil.CheckHostRemotingPrerequisites(); } return(new RunspacePool(minRunspaces, maxRunspaces, typeTable, host, applicationArguments, connectionInfo)); }
public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) { if (!(connectionInfo is WSManConnectionInfo) && !(connectionInfo is NewProcessConnectionInfo)) { throw new NotSupportedException(); } if (connectionInfo is WSManConnectionInfo) { RemotingCommandUtil.CheckHostRemotingPrerequisites(); } return(new RemoteRunspace(typeTable, connectionInfo, host, applicationArguments, null, -1)); }
/// <summary> /// /// </summary> /// <param name="connectionInfo"></param> /// <param name="host"></param> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="applicationArguments"> /// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/> /// </param> /// <param name="name">Name for remote runspace.</param> /// <returns></returns> public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments, string name) { if ((!(connectionInfo is WSManConnectionInfo)) && (!(connectionInfo is NewProcessConnectionInfo)) && (!(connectionInfo is NamedPipeConnectionInfo)) && (!(connectionInfo is SSHConnectionInfo)) && (!(connectionInfo is VMConnectionInfo)) && (!(connectionInfo is ContainerConnectionInfo))) { throw new NotSupportedException(); } if (connectionInfo is WSManConnectionInfo) { RemotingCommandUtil.CheckHostRemotingPrerequisites(); } return new RemoteRunspace(typeTable, connectionInfo, host, applicationArguments, name); }
internal RunspacePool(bool isDisconnected, Guid instanceId, string name, ConnectCommandInfo[] connectCommands, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { this.syncObject = new object(); if (!(connectionInfo is WSManConnectionInfo)) { throw new NotSupportedException(); } this.internalPool = new System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal(instanceId, name, isDisconnected, connectCommands, connectionInfo, host, typeTable); this.isRemote = true; }
static ActivityHostProcess() { ActivityHostProcess._perfCountersMgr = PSPerfCountersMgr.Instance; string[] strArrays = new string[1]; strArrays[0] = "%windir%\\system32\\windowspowershell\\v1.0\\modules\\psworkflow\\PSWorkflow.types.ps1xml"; ActivityHostProcess.ActivitiesTypesFiles = strArrays; WSManConnectionInfo wSManConnectionInfo = new WSManConnectionInfo(); wSManConnectionInfo.Port = 0xb799; wSManConnectionInfo.ShellUri = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell.Workflow.ActivityHost"; ActivityHostProcess.ActivityHostConnectionInfo = wSManConnectionInfo; List<string> defaultTypeFiles = TypeTable.GetDefaultTypeFiles(); defaultTypeFiles.AddRange(ActivityHostProcess.ActivitiesTypesFiles.Select<string, string>(new Func<string, string>(Environment.ExpandEnvironmentVariables))); ActivityHostProcess.ActivitiesTypeTable = new TypeTable(defaultTypeFiles); }
/// <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> /// 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> /// Creates a single disconnected remote Runspace object based on connection information and /// session / command identifiers. /// </summary> /// <param name="connectionInfo">Connection object for target machine</param> /// <param name="sessionId">Session Id to connect to</param> /// <param name="commandId">Optional command Id to connect to</param> /// <param name="host">Optional PSHost</param> /// <param name="typeTable">Optional TypeTable</param> /// <returns>Disconnect remote Runspace object</returns> internal static Runspace GetRemoteRunspace(RunspaceConnectionInfo connectionInfo, Guid sessionId, Guid? commandId, PSHost host, TypeTable typeTable) { RunspacePool runspacePool = RemoteRunspacePoolInternal.GetRemoteRunspacePool( connectionInfo, sessionId, commandId, host, typeTable); return new RemoteRunspace(runspacePool); }
public static RunspacePool CreateRunspacePool(int minRunspaces, int maxRunspaces, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return CreateRunspacePool(minRunspaces, maxRunspaces, connectionInfo, host, typeTable, null); }
/// <summary> /// /// </summary> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="host"></param> /// <param name="connectionInfo"></param> /// <returns></returns> public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return CreateRunspace(connectionInfo, host, typeTable, null, null); }
public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return(System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.GetRemoteRunspacePools(connectionInfo, host, typeTable)); }
private void CreateDSHandler(TypeTable typeTable) { this.dataStructureHandler = new ClientRunspacePoolDataStructureHandler(this, typeTable); this.dataStructureHandler.RemoteHostCallReceived += new EventHandler<RemoteDataEventArgs<RemoteHostCall>>(this.HandleRemoteHostCalls); this.dataStructureHandler.StateInfoReceived += new EventHandler<RemoteDataEventArgs<RunspacePoolStateInfo>>(this.HandleStateInfoReceived); this.dataStructureHandler.RSPoolInitInfoReceived += new EventHandler<RemoteDataEventArgs<RunspacePoolInitInfo>>(this.HandleInitInfoReceived); this.dataStructureHandler.ApplicationPrivateDataReceived += new EventHandler<RemoteDataEventArgs<PSPrimitiveDictionary>>(this.HandleApplicationPrivateDataReceived); this.dataStructureHandler.SessionClosing += new EventHandler<RemoteDataEventArgs<Exception>>(this.HandleSessionClosing); this.dataStructureHandler.SessionClosed += new EventHandler<RemoteDataEventArgs<Exception>>(this.HandleSessionClosed); this.dataStructureHandler.SetMaxMinRunspacesResponseRecieved += new EventHandler<RemoteDataEventArgs<PSObject>>(this.HandleResponseReceived); this.dataStructureHandler.URIRedirectionReported += new EventHandler<RemoteDataEventArgs<Uri>>(this.HandleURIDirectionReported); this.dataStructureHandler.PSEventArgsReceived += new EventHandler<RemoteDataEventArgs<PSEventArgs>>(this.HandlePSEventArgsReceived); this.dataStructureHandler.SessionDisconnected += new EventHandler<RemoteDataEventArgs<Exception>>(this.HandleSessionDisconnected); this.dataStructureHandler.SessionReconnected += new EventHandler<RemoteDataEventArgs<Exception>>(this.HandleSessionReconnected); this.dataStructureHandler.SessionRCDisconnecting += new EventHandler<RemoteDataEventArgs<Exception>>(this.HandleSessionRCDisconnecting); this.dataStructureHandler.SessionCreateCompleted += new EventHandler<CreateCompleteEventArgs>(this.HandleSessionCreateCompleted); }
internal RunspacePool(int minRunspaces, int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo) { throw new NotImplementedException(); }
/// <summary> /// Queries the server for disconnected runspaces and creates an array of runspace /// objects associated with each disconnected runspace on the server. Each /// runspace 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. /// </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 Runspace objects each in the Disconnected state.</returns> internal static Runspace[] GetRemoteRunspaces(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { List<Runspace> runspaces = new List<Runspace>(); RunspacePool[] runspacePools = RemoteRunspacePoolInternal.GetRemoteRunspacePools(connectionInfo, host, typeTable); // We don't yet know how many runspaces there are in these runspace pool objects. This information isn't updated // until a Connect() is performed. But we can use the ConnectCommands list to prune runspace pool objects that // clearly have more than one command/runspace. foreach (RunspacePool runspacePool in runspacePools) { if (runspacePool.RemoteRunspacePoolInternal.ConnectCommands.Length < 2) { runspaces.Add(new RemoteRunspace(runspacePool)); } } return runspaces.ToArray(); }
/// <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)); }
internal RunspacePool(int minRunspaces, int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo, string name = null) { this.syncObject = new object(); if (!(connectionInfo is WSManConnectionInfo) && !(connectionInfo is NewProcessConnectionInfo)) { throw new NotSupportedException(); } this.internalPool = new System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal(minRunspaces, maxRunspaces, typeTable, host, applicationArguments, connectionInfo, name); this.isRemote = true; }
/// <summary> /// </summary> /// <param name="connectionInfo"></param> /// <param name="host"></param> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="applicationArguments"> /// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/> /// </param> /// <param name="name">Name for remote runspace.</param> /// <returns></returns> public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments, string name) { if (connectionInfo is WSManConnectionInfo) { RemotingCommandUtil.CheckHostRemotingPrerequisites(); } return(new RemoteRunspace(typeTable, connectionInfo, host, applicationArguments, name)); }
public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.GetRemoteRunspacePools(connectionInfo, host, typeTable); }
public static RunspacePool CreateRunspacePool(int minRunspaces, int maxRunspaces, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return(CreateRunspacePool(minRunspaces, maxRunspaces, connectionInfo, host, typeTable, null)); }
public SessionStateTypeEntry(TypeTable typeTable) : base("*") { throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="host"></param> /// <param name="connectionInfo"></param> /// <param name="applicationArguments"> /// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/> /// </param> /// <returns></returns> public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) { return(CreateRunspace(connectionInfo, host, typeTable, applicationArguments, null)); }
public static Runspace[] GetRunspaces(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return RemoteRunspace.GetRemoteRunspaces(connectionInfo, host, typeTable); }
/// <summary> /// Initialize a connection info object in the static constructor /// It can be reused for all connections /// </summary> static ActivityHostProcess() { ActivityHostConnectionInfo = new WSManConnectionInfo { Port = WSManLocalPort, ShellUri = ActivityHostShellUri }; List<String> typefiles = TypeTable.GetDefaultTypeFiles(); typefiles.AddRange(ActivitiesTypesFiles.Select(Environment.ExpandEnvironmentVariables)); ActivitiesTypeTable = new TypeTable(typefiles); }
/// <summary> /// Returns a single disconnected Runspace object targeted to the remote computer and remote /// session as specified by the connection, session Id, and command Id parameters. /// </summary> /// <param name="connectionInfo">Connection object for the target server.</param> /// <param name="sessionId">Id of a disconnected remote session on the target server.</param> /// <param name="commandId">Optional Id of a disconnected command running in the disconnected remote session on the target server.</param> /// <param name="host">Optional client host object.</param> /// <param name="typeTable">Optional TypeTable object.</param> /// <returns>Disconnected runspace corresponding to the provided session Id.</returns> public static Runspace GetRunspace(RunspaceConnectionInfo connectionInfo, Guid sessionId, Guid? commandId, PSHost host, TypeTable typeTable) { return RemoteRunspace.GetRemoteRunspace(connectionInfo, sessionId, commandId, host, typeTable); }
public static RunspacePool CreateRunspacePool(int minRunspaces, int maxRunspaces, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) { if ((!(connectionInfo is WSManConnectionInfo)) && (!(connectionInfo is NewProcessConnectionInfo)) && (!(connectionInfo is NamedPipeConnectionInfo)) && (!(connectionInfo is VMConnectionInfo)) && (!(connectionInfo is ContainerConnectionInfo))) { throw new NotSupportedException(); } if (connectionInfo is WSManConnectionInfo) { RemotingCommandUtil.CheckHostRemotingPrerequisites(); } return new RunspacePool(minRunspaces, maxRunspaces, typeTable, host, applicationArguments, connectionInfo); }
public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) { if (!(connectionInfo is WSManConnectionInfo) && !(connectionInfo is NewProcessConnectionInfo)) { throw new NotSupportedException(); } if (connectionInfo is WSManConnectionInfo) { RemotingCommandUtil.CheckHostRemotingPrerequisites(); } return new RemoteRunspace(typeTable, connectionInfo, host, applicationArguments, null, -1); }
/// <summary> /// /// </summary> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="host"></param> /// <param name="connectionInfo"></param> /// <param name="applicationArguments"> /// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/> /// </param> /// <returns></returns> public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) { return CreateRunspace(connectionInfo, host, typeTable, applicationArguments, null); }
internal InternalMISerializer(int depth) { _depth = depth; // TODO, insivara : Revisit this _typeTable = new TypeTable(); }
/// <summary> /// /// </summary> /// <param name="typeTable"></param> /// <returns></returns> public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable) { NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(null); return CreateRunspace(connectionInfo, null, typeTable); }
public static Runspace[] GetRunspaces(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { return(RemoteRunspace.GetRemoteRunspaces(connectionInfo, host, typeTable)); }
internal static RunspacePool[] GetRemoteRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable) { WSManConnectionInfo wsmanConnectionInfo = connectionInfo as WSManConnectionInfo; if (wsmanConnectionInfo == null) { throw new NotSupportedException(); } List<RunspacePool> list = new List<RunspacePool>(); foreach (PSObject obj2 in RemoteRunspacePoolEnumeration.GetRemotePools(wsmanConnectionInfo)) { WSManConnectionInfo info2 = wsmanConnectionInfo.Copy(); PSPropertyInfo info3 = obj2.Properties["ShellId"]; PSPropertyInfo info4 = obj2.Properties["State"]; PSPropertyInfo info5 = obj2.Properties["Name"]; PSPropertyInfo info6 = obj2.Properties["ResourceUri"]; if (((info3 != null) && (info4 != null)) && ((info5 != null) && (info6 != null))) { string name = info5.Value.ToString(); string str2 = info6.Value.ToString(); bool isDisconnected = info4.Value.ToString().Equals("Disconnected", StringComparison.OrdinalIgnoreCase); Guid shellId = Guid.Parse(info3.Value.ToString()); if (str2.StartsWith("http://schemas.microsoft.com/powershell/", StringComparison.OrdinalIgnoreCase)) { Collection<PSObject> remoteCommands; UpdateWSManConnectionInfo(info2, obj2); info2.EnableNetworkAccess = true; List<ConnectCommandInfo> list2 = new List<ConnectCommandInfo>(); try { remoteCommands = RemoteRunspacePoolEnumeration.GetRemoteCommands(shellId, info2); } catch (CmdletInvocationException exception) { if ((exception.InnerException == null) || !(exception.InnerException is InvalidOperationException)) { throw; } continue; } foreach (PSObject obj3 in remoteCommands) { PSPropertyInfo info7 = obj3.Properties["CommandId"]; PSPropertyInfo info8 = obj3.Properties["CommandLine"]; if (info7 != null) { string cmdStr = (info8 != null) ? info8.Value.ToString() : string.Empty; Guid cmdId = Guid.Parse(info7.Value.ToString()); list2.Add(new ConnectCommandInfo(cmdId, cmdStr)); } } RunspacePool item = new RunspacePool(isDisconnected, shellId, name, list2.ToArray(), info2, host, typeTable); list.Add(item); } } } return list.ToArray(); }
internal OutOfProcessServerTransportManager(OutOfProcessTextWriter stdOutWriter, OutOfProcessTextWriter stdErrWriter, Guid powershellInstanceId, TypeTable typeTableToUse, int fragmentSize, PSRemotingCryptoHelper cryptoHelper) : base(fragmentSize, cryptoHelper) { _stdOutWriter = stdOutWriter; _stdErrWriter = stdErrWriter; _powershellInstanceId = powershellInstanceId; this.TypeTable = typeTableToUse; this.WSManTransportErrorOccured += HandleWSManTransportError; }
/// <summary> /// Construct a remote runspace based on the connection information /// and the specified host /// </summary> /// <param name="typeTable"> /// The TypeTable to use while deserializing/serializing remote objects. /// TypeTable has the following information used by serializer: /// 1. SerializationMethod /// 2. SerializationDepth /// 3. SpecificSerializationProperties /// TypeTable has the following information used by deserializer: /// 1. TargetTypeForDeserialization /// 2. TypeConverter /// </param> /// <param name="connectionInfo">connection information which identifies /// the remote computer</param> /// <param name="host">host on the client</param> /// <param name="applicationArguments"> /// <param name="name">Friendly name for remote runspace session.</param> /// <param name="id">Id for remote runspace.</param> /// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/> /// </param> internal RemoteRunspace(TypeTable typeTable, RunspaceConnectionInfo connectionInfo, PSHost host, PSPrimitiveDictionary applicationArguments, string name = null, int id = -1) { PSEtwLog.SetActivityIdForCurrentThread(this.InstanceId); PSEtwLog.LogOperationalVerbose(PSEventId.RunspaceConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, InstanceId.ToString()); _connectionInfo = connectionInfo.InternalCopy(); OriginalConnectionInfo = connectionInfo.InternalCopy(); RunspacePool = new RunspacePool(1, 1, typeTable, host, applicationArguments, connectionInfo, name); this.PSSessionId = id; SetEventHandlers(); }