예제 #1
0
		public PowwaSession CreateSession(string sessionId, RunspaceConnectionInfo connectionInfo, ClientInfo clientInfo, string authenticatedUserName)
		{
			bool flag = false;
			PowwaSession powwaSession;
			PowwaSession stringSid = new PowwaSession(sessionId, authenticatedUserName, connectionInfo, clientInfo);
			string str = null;
			stringSid.AuthenticatedUserSid = PowwaAuthorizationManager.Instance.activeDirectoryHelper.ConvertAccountNameToStringSid(authenticatedUserName, out flag, out str);
			lock (this.sessionsLock)
			{
				bool userActiveSessions = this.GetUserActiveSessions(stringSid.AuthenticatedUserSid) < PowwaAuthorizationManager.Instance.UserSessionsLimit;
				if (userActiveSessions)
				{
					stringSid.Name = this.GetSessionName(stringSid);
					try
					{
						this.sessions.Add(sessionId, stringSid);
					}
					catch (ArgumentException argumentException)
					{
						PowwaEvents.PowwaEVENT_DEBUG_LOG0("CreateSession: Attempt to create a session that already exists");
						throw new ArgumentException("There is already a PowWA session with the given ID", "sessionId");
					}
					powwaSession = stringSid;
				}
				else
				{
					object[] objArray = new object[1];
					objArray[0] = authenticatedUserName;
					throw new Exception(string.Format(CultureInfo.CurrentCulture, Resources.UserActiveSessionLimitReached, objArray));
				}
			}
			return powwaSession;
		}
예제 #2
0
        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();
        }
예제 #3
0
 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;
 }
예제 #4
0
 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 ClientRemoteSessionDSHandlerImpl(ClientRemoteSession session, PSRemotingCryptoHelper cryptoHelper, RunspaceConnectionInfo connectionInfo, ClientRemoteSession.URIDirectionReported uriRedirectionHandler)
 {
     if (session == null)
     {
         throw PSTraceSource.NewArgumentNullException("session");
     }
     this._session = session;
     this._stateMachine = new ClientRemoteSessionDSHandlerStateMachine();
     this._stateMachine.StateChanged += new EventHandler<RemoteSessionStateEventArgs>(this.HandleStateChanged);
     this._connectionInfo = connectionInfo;
     this._cryptoHelper = cryptoHelper;
     if (this._connectionInfo is NewProcessConnectionInfo)
     {
         this._transportManager = new OutOfProcessClientSessionTransportManager(this._session.RemoteRunspacePoolInternal.InstanceId, (NewProcessConnectionInfo) this._connectionInfo, cryptoHelper);
     }
     else
     {
         this._transportManager = new WSManClientSessionTransportManager(this._session.RemoteRunspacePoolInternal.InstanceId, (WSManConnectionInfo) this._connectionInfo, cryptoHelper, this._session.RemoteRunspacePoolInternal.Name);
     }
     this._transportManager.DataReceived += new EventHandler<RemoteDataEventArgs>(this.DispatchInputQueueData);
     this._transportManager.WSManTransportErrorOccured += new EventHandler<TransportErrorOccuredEventArgs>(this.HandleTransportError);
     this._transportManager.CloseCompleted += new EventHandler<EventArgs>(this.HandleCloseComplete);
     this._transportManager.DisconnectCompleted += new EventHandler<EventArgs>(this.HandleDisconnectComplete);
     this._transportManager.ReconnectCompleted += new EventHandler<EventArgs>(this.HandleReconnectComplete);
     this._transportManager.RobustConnectionNotification += new EventHandler<ConnectionStatusEventArgs>(this.HandleRobustConnectionNotification);
     WSManConnectionInfo info = connectionInfo as WSManConnectionInfo;
     if (info != null)
     {
         this.uriRedirectionHandler = uriRedirectionHandler;
         this.maxUriRedirectionCount = info.MaximumConnectionRedirectionCount;
     }
 }
        /// <summary>
        /// Creates an instance of ClientRemoteSessionDSHandlerImpl
        /// </summary>
        internal ClientRemoteSessionDSHandlerImpl(ClientRemoteSession session,
            PSRemotingCryptoHelper cryptoHelper,
            RunspaceConnectionInfo connectionInfo,
            ClientRemoteSession.URIDirectionReported uriRedirectionHandler)
        {
            Dbg.Assert(_maxUriRedirectionCount >= 0, "maxUriRedirectionCount cannot be less than 0.");

            if (session == null)
            {
                throw PSTraceSource.NewArgumentNullException("session");
            }

            _session = session;

            //Create state machine
            _stateMachine = new ClientRemoteSessionDSHandlerStateMachine();
            _stateMachine.StateChanged += HandleStateChanged;

            _connectionInfo = connectionInfo;

            // Create transport manager
            _cryptoHelper = cryptoHelper;
            _transportManager = _connectionInfo.CreateClientSessionTransportManager(
                _session.RemoteRunspacePoolInternal.InstanceId,
                _session.RemoteRunspacePoolInternal.Name,
                cryptoHelper);

            _transportManager.DataReceived += DispatchInputQueueData;
            _transportManager.WSManTransportErrorOccured += HandleTransportError;
            _transportManager.CloseCompleted += HandleCloseComplete;
            _transportManager.DisconnectCompleted += HandleDisconnectComplete;
            _transportManager.ReconnectCompleted += HandleReconnectComplete;

            _transportManager.RobustConnectionNotification += new EventHandler<ConnectionStatusEventArgs>(HandleRobustConnectionNotification);

            WSManConnectionInfo wsmanConnectionInfo = _connectionInfo as WSManConnectionInfo;
            if (null != wsmanConnectionInfo)
            {
                // only WSMan transport supports redirection

                // store the uri redirection handler and authmechanism 
                // for uri redirection.
                _uriRedirectionHandler = uriRedirectionHandler;
                _maxUriRedirectionCount = wsmanConnectionInfo.MaximumConnectionRedirectionCount;
            }
        }
예제 #7
0
        /// <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;
        }
예제 #8
0
        /// <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;
        }
예제 #9
0
 internal RemoteRunspace(System.Management.Automation.Runspaces.RunspacePool runspacePool)
 {
     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;
     if ((runspacePool.RunspacePoolStateInfo.State != RunspacePoolState.Disconnected) || !(runspacePool.ConnectionInfo is WSManConnectionInfo))
     {
         throw PSTraceSource.NewInvalidOperationException("RunspaceStrings", "InvalidRunspacePool", new object[0]);
     }
     this._runspacePool = runspacePool;
     this._runspacePool.RemoteRunspacePoolInternal.SetMinRunspaces(1);
     this._runspacePool.RemoteRunspacePoolInternal.SetMaxRunspaces(1);
     this._connectionInfo = ((WSManConnectionInfo) runspacePool.ConnectionInfo).Copy();
     this.SetRunspaceState(RunspaceState.Disconnected, null);
     this._runspaceAvailability = this._runspacePool.RemoteRunspacePoolInternal.AvailableForConnection ? System.Management.Automation.Runspaces.RunspaceAvailability.None : System.Management.Automation.Runspaces.RunspaceAvailability.Busy;
     this.SetEventHandlers();
     PSEtwLog.SetActivityIdForCurrentThread(base.InstanceId);
     PSEtwLog.LogOperationalVerbose(PSEventId.RunspaceConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, new object[] { base.InstanceId.ToString() });
 }
예제 #10
0
        internal RunspacePool(
            int minRunspaces,
            int maxRunspaces,
            TypeTable typeTable,
            PSHost host,
            PSPrimitiveDictionary applicationArguments,
            RunspaceConnectionInfo connectionInfo)
        {
            using (RunspacePool.tracer.TraceConstructor((object)this))
            {
                switch (connectionInfo)
                {
                case WSManConnectionInfo _:
                case NewProcessConnectionInfo _:
                    this.internalPool = (RunspacePoolInternal) new RemoteRunspacePoolInternal(minRunspaces, maxRunspaces, typeTable, host, applicationArguments, connectionInfo);
                    this.isRemote     = true;
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
        }
예제 #11
0
 /// <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>
 /// <returns>Array of RunspacePool objects each in the Disconnected state.</returns>
 public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo)
 {
     return(GetRunspacePools(connectionInfo, null, null));
 }
예제 #12
0
 /// <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);
 }
예제 #13
0
 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;
 }
예제 #14
0
 public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo) => RunspaceFactory.CreateRunspace((PSHost)null, connectionInfo);
예제 #15
0
 public static RunspacePool CreateRunspacePool(int minRunspaces,
     int maxRunspaces, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable)
 {
     return CreateRunspacePool(minRunspaces, maxRunspaces, connectionInfo, host, typeTable, null);
 }
예제 #16
0
 public static Runspace[] GetRunspaces(RunspaceConnectionInfo connectionInfo, PSHost host)
 {
     return GetRunspaces(connectionInfo, host, null);
 }
예제 #17
0
 public static RunspacePool CreateRunspacePool(int minRunspaces, int maxRunspaces, 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 RunspacePool(minRunspaces, maxRunspaces, typeTable, host, applicationArguments, connectionInfo, null));
 }
예제 #18
0
 internal CreateCompleteEventArgs(RunspaceConnectionInfo connectionInfo)
 {
     this._connectionInfo = connectionInfo;
 }
예제 #19
0
 public static Runspace[] GetRunspaces(RunspaceConnectionInfo connectionInfo)
 {
     return GetRunspaces(connectionInfo, null, null);
 }
예제 #20
0
 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;
 }
예제 #21
0
 public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable)
 {
     return System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.GetRemoteRunspacePools(connectionInfo, host, typeTable);
 }
예제 #22
0
 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;
 }
예제 #23
0
 /// <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));
 }
예제 #24
0
 public static Runspace[] GetRunspaces(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable)
 {
     return RemoteRunspace.GetRemoteRunspaces(connectionInfo, host, typeTable);
 }
예제 #25
0
 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;
 }
예제 #26
0
 /// <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);
 }
예제 #27
0
 public static Runspace CreateRunspace(
     PSHost host,
     RunspaceConnectionInfo connectionInfo)
 {
     return(RunspaceFactory.CreateRunspace(connectionInfo, host, (TypeTable)null));
 }
예제 #28
0
        /// <summary>
        /// Create temporary remote runspace.
        /// </summary>
        private RemoteRunspace CreateTemporaryRemoteRunspaceForPowerShellDirect(PSHost host, RunspaceConnectionInfo connectionInfo)
        {
            // Create and open the runspace.
            TypeTable typeTable = TypeTable.LoadDefaultTypeFiles();
            RemoteRunspace remoteRunspace = RunspaceFactory.CreateRunspace(connectionInfo, host, typeTable) as RemoteRunspace;
            remoteRunspace.Name = "PowerShellDirectAttach";

            Dbg.Assert(remoteRunspace != null, "Expected remoteRunspace != null");
            try
            {
                remoteRunspace.Open();

                // Mark this temporary runspace so that it closes on pop.
                remoteRunspace.ShouldCloseOnPop = true;
            }
            finally
            {
                // Make sure we dispose the temporary runspace if something bad happens.
                if (remoteRunspace.RunspaceStateInfo.State != RunspaceState.Opened)
                {
                    remoteRunspace.Dispose();
                    remoteRunspace = null;
                }
            }

            return remoteRunspace;
        }
예제 #29
0
 public static RunspacePool CreateRunspacePool(int minRunspaces,
                                 int maxRunspaces, RunspaceConnectionInfo connectionInfo)
 {
     return CreateRunspacePool(minRunspaces, maxRunspaces, connectionInfo, null);
 }
예제 #30
0
        /// <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);
        }
예제 #31
0
        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);
        }
예제 #32
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="connectionInfo"></param>
 /// <returns></returns>
 public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo)
 {
     return CreateRunspace(null, connectionInfo);
 }
예제 #33
0
 /// <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);
 }
예제 #34
0
파일: RunspacePool.cs 프로젝트: mauve/Pash
 internal RunspacePool(int minRunspaces, int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo)
 {
     throw new NotImplementedException();
 }
예제 #35
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="host"></param>
 /// <param name="connectionInfo"></param>
 /// <returns></returns>
 public static Runspace CreateRunspace(PSHost host, RunspaceConnectionInfo connectionInfo)
 {
     return CreateRunspace(connectionInfo, host, null);
 }
예제 #36
0
 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);
 }
예제 #37
0
 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();
 }
예제 #38
0
 public static RunspacePool CreateRunspacePool(int minRunspaces,
                                               int maxRunspaces, RunspaceConnectionInfo connectionInfo)
 {
     return(CreateRunspacePool(minRunspaces, maxRunspaces, connectionInfo, null));
 }
예제 #39
0
 public static Runspace[] GetRunspaces(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable)
 {
     return(RemoteRunspace.GetRemoteRunspaces(connectionInfo, host, typeTable));
 }
예제 #40
0
 /// <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));
 }
예제 #41
0
 /// <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));
 }
예제 #42
0
 /// <summary>
 /// </summary>
 /// <param name="host"></param>
 /// <param name="connectionInfo"></param>
 /// <returns></returns>
 public static Runspace CreateRunspace(PSHost host, RunspaceConnectionInfo connectionInfo)
 {
     return(CreateRunspace(connectionInfo, host, null));
 }
예제 #43
0
 /// <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);
 }
예제 #44
0
 public static RunspacePool[] GetRunspacePools(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable)
 {
     return(System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.GetRemoteRunspacePools(connectionInfo, host, typeTable));
 }
예제 #45
0
 public static RunspacePool CreateRunspacePool(int minRunspaces,
                                               int maxRunspaces, RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable)
 {
     return(CreateRunspacePool(minRunspaces, maxRunspaces, connectionInfo, host, typeTable, null));
 }
예제 #46
0
        internal NamedPipeClientSessionTransportManagerBase(
            RunspaceConnectionInfo connectionInfo,
            Guid runspaceId,
            PSRemotingCryptoHelper cryptoHelper,
            string threadName)
            : base(runspaceId, cryptoHelper)
        {
            if (connectionInfo == null)
            {
                throw new PSArgumentNullException("connectionInfo");
            }

            _connectionInfo = connectionInfo;
            _threadName = threadName;
            Fragmentor.FragmentSize = RemoteSessionNamedPipeServer.NamedPipeBufferSizeForRemoting;
        }
예제 #47
0
 /// <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));
 }
예제 #48
0
        /// <summary>
        /// Create a transport manager for command
        /// </summary>
        /// <param name="connectionInfo"></param>
        /// <param name="cmd"></param>
        /// <param name="noInput"></param>
        /// <returns></returns>
        internal override BaseClientCommandTransportManager CreateClientCommandTransportManager(
            RunspaceConnectionInfo connectionInfo,
            ClientRemotePowerShell cmd,
            bool noInput)
        {
            Dbg.Assert(null != cmd, "Cmd cannot be null");

            OutOfProcessClientCommandTransportManager result = new
                OutOfProcessClientCommandTransportManager(cmd, noInput, this, stdInWriter);
            AddCommandTransportManager(cmd.InstanceId, result);

            return result;
        }
예제 #49
0
 /// <summary>
 /// </summary>
 /// <param name="connectionInfo"></param>
 /// <returns></returns>
 public static Runspace CreateRunspace(RunspaceConnectionInfo connectionInfo)
 {
     return(CreateRunspace(null, connectionInfo));
 }
예제 #50
0
 internal RunspacePool(int minRunspaces, int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo)
 {
     throw new NotImplementedException();
 }