Exemplo n.º 1
0
 public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable, PowerShellProcessInstance processInstance)
 {
     NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(null) {
         Process = processInstance
     };
     return CreateRunspace(connectionInfo, null, typeTable);
 }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="typeTable"></param>
        /// <param name="processInstance"></param>
        /// <returns></returns>
        public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable, PowerShellProcessInstance processInstance)
        {
            NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(null)
            {
                Process = processInstance
            };

            return(CreateRunspace(connectionInfo, null, typeTable));
        }
Exemplo n.º 3
0
 private void OnStateChanged(object source, RunspacePoolStateChangedEventArgs args)
 {
     if (this.ConnectionInfo is NewProcessConnectionInfo)
     {
         NewProcessConnectionInfo connectionInfo = this.ConnectionInfo as NewProcessConnectionInfo;
         if ((connectionInfo.Process != null) && ((args.RunspacePoolStateInfo.State == RunspacePoolState.Opened) || (args.RunspacePoolStateInfo.State == RunspacePoolState.Broken)))
         {
             connectionInfo.Process.RunspacePool = this;
         }
     }
     this.InternalStateChanged.SafeInvoke <RunspacePoolStateChangedEventArgs>(this, args);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Handle internal Pool state changed events.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        private void OnStateChanged(object source, RunspacePoolStateChangedEventArgs args)
        {
            if (ConnectionInfo is NewProcessConnectionInfo)
            {
                NewProcessConnectionInfo connectionInfo = ConnectionInfo as NewProcessConnectionInfo;
                if (connectionInfo.Process != null &&
                    (args.RunspacePoolStateInfo.State == RunspacePoolState.Opened ||
                     args.RunspacePoolStateInfo.State == RunspacePoolState.Broken))
                {
                    connectionInfo.Process.RunspacePool = this;
                }
            }

            // call any event handlers on this, replacing the
            // internalPool sender with 'this' since receivers
            // are expecting a RunspacePool
            InternalStateChanged.SafeInvoke(this, args);
        }
Exemplo n.º 5
0
 protected override void CreateHelpersForSpecifiedComputerNames()
 {
     if (((base.Context.LanguageMode == PSLanguageMode.ConstrainedLanguage) && (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce)) && ((this.ScriptBlock != null) || (this.InitializationScript != null)))
     {
         base.ThrowTerminatingError(new ErrorRecord(new PSNotSupportedException(RemotingErrorIdStrings.CannotStartJobInconsistentLanguageMode), "CannotStartJobInconsistentLanguageMode", ErrorCategory.PermissionDenied, base.Context.LanguageMode));
     }
     NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(this.Credential) {
         RunAs32 = this.shouldRunAs32,
         InitializationScript = this.initScript,
         AuthenticationMechanism = this.Authentication,
         PSVersion = this.PSVersion
     };
     RemoteRunspace remoteRunspace = (RemoteRunspace) RunspaceFactory.CreateRunspace(connectionInfo, base.Host, Utils.GetTypeTableFromExecutionContextTLS());
     remoteRunspace.Events.ReceivedEvents.PSEventReceived += new PSEventReceivedEventHandler(this.OnRunspacePSEventReceived);
     Pipeline pipeline = base.CreatePipeline(remoteRunspace);
     IThrottleOperation item = new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline, false);
     base.Operations.Add(item);
 }
 internal OutOfProcessClientSessionTransportManager(Guid runspaceId, NewProcessConnectionInfo connectionInfo, PSRemotingCryptoHelper cryptoHelper) : base(runspaceId, cryptoHelper)
 {
     this._processCreated = true;
     this.onDataAvailableToSendCallback = new System.Management.Automation.Remoting.PrioritySendDataCollection.OnDataAvailableCallback(this.OnDataAvailableCallback);
     this.cmdTransportManagers = new Dictionary<Guid, OutOfProcessClientCommandTransportManager>();
     this.connectionInfo = connectionInfo;
     this.dataProcessingCallbacks = new OutOfProcessUtils.DataProcessingDelegates();
     this.dataProcessingCallbacks.DataPacketReceived = (OutOfProcessUtils.DataPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.DataPacketReceived, new OutOfProcessUtils.DataPacketReceived(this.OnDataPacketReceived));
     this.dataProcessingCallbacks.DataAckPacketReceived = (OutOfProcessUtils.DataAckPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.DataAckPacketReceived, new OutOfProcessUtils.DataAckPacketReceived(this.OnDataAckPacketReceived));
     this.dataProcessingCallbacks.CommandCreationPacketReceived = (OutOfProcessUtils.CommandCreationPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.CommandCreationPacketReceived, new OutOfProcessUtils.CommandCreationPacketReceived(this.OnCommandCreationPacketReceived));
     this.dataProcessingCallbacks.CommandCreationAckReceived = (OutOfProcessUtils.CommandCreationAckReceived) Delegate.Combine(this.dataProcessingCallbacks.CommandCreationAckReceived, new OutOfProcessUtils.CommandCreationAckReceived(this.OnCommandCreationAckReceived));
     this.dataProcessingCallbacks.SignalPacketReceived = (OutOfProcessUtils.SignalPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.SignalPacketReceived, new OutOfProcessUtils.SignalPacketReceived(this.OnSignalPacketReceived));
     this.dataProcessingCallbacks.SignalAckPacketReceived = (OutOfProcessUtils.SignalAckPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.SignalAckPacketReceived, new OutOfProcessUtils.SignalAckPacketReceived(this.OnSiganlAckPacketReceived));
     this.dataProcessingCallbacks.ClosePacketReceived = (OutOfProcessUtils.ClosePacketReceived) Delegate.Combine(this.dataProcessingCallbacks.ClosePacketReceived, new OutOfProcessUtils.ClosePacketReceived(this.OnClosePacketReceived));
     this.dataProcessingCallbacks.CloseAckPacketReceived = (OutOfProcessUtils.CloseAckPacketReceived) Delegate.Combine(this.dataProcessingCallbacks.CloseAckPacketReceived, new OutOfProcessUtils.CloseAckPacketReceived(this.OnCloseAckReceived));
     base.dataToBeSent.Fragmentor = base.Fragmentor;
     base.ReceivedDataCollection.MaximumReceivedDataSize = null;
     base.ReceivedDataCollection.MaximumReceivedObjectSize = 0xa00000;
     this.closeTimeOutTimer = new Timer(60000.0);
     this.closeTimeOutTimer.Elapsed += new ElapsedEventHandler(this.OnCloseTimeOutTimerElapsed);
     this._tracer = PowerShellTraceSourceFactory.GetTraceSource();
 }
Exemplo n.º 7
0
        /// <summary>
        /// </summary>
        /// <param name="typeTable"></param>
        /// <returns></returns>
        public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable)
        {
            NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(null);

            return(CreateRunspace(connectionInfo, null, typeTable));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="typeTable"></param>
        /// <returns></returns>
        public static Runspace CreateOutOfProcessRunspace(TypeTable typeTable)
        {
            NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(null);

            return CreateRunspace(connectionInfo, null, typeTable);
        }
 internal OutOfProcessClientSessionTransportManager(Guid runspaceId,
     NewProcessConnectionInfo connectionInfo,
     PSRemotingCryptoHelper cryptoHelper)
     : base(runspaceId, cryptoHelper)
 {
     _connectionInfo = connectionInfo;
 }
Exemplo n.º 10
0
        } // CoreBeginProcessing

        /// <summary>
        /// Create a throttle operation using NewProcessConnectionInfo 
        /// ie., Out-Of-Process runspace.
        /// </summary>
        protected override void CreateHelpersForSpecifiedComputerNames()
        {
            // If we're in ConstrainedLanguage mode and the system is in lockdown mode,
            // ensure that they haven't specified a ScriptBlock or InitScript - as
            // we can't protect that boundary
            if ((Context.LanguageMode == PSLanguageMode.ConstrainedLanguage) &&
                (SystemPolicy.GetSystemLockdownPolicy() != SystemEnforcementMode.Enforce) &&
                ((ScriptBlock != null) || (InitializationScript != null)))
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new PSNotSupportedException(RemotingErrorIdStrings.CannotStartJobInconsistentLanguageMode),
                            "CannotStartJobInconsistentLanguageMode",
                            ErrorCategory.PermissionDenied,
                            Context.LanguageMode));
            }

            NewProcessConnectionInfo connectionInfo = new NewProcessConnectionInfo(this.Credential);
            connectionInfo.RunAs32 = _shouldRunAs32;
            connectionInfo.InitializationScript = _initScript;
            connectionInfo.AuthenticationMechanism = this.Authentication;
            connectionInfo.PSVersion = this.PSVersion;

            RemoteRunspace remoteRunspace = (RemoteRunspace)RunspaceFactory.CreateRunspace(connectionInfo, this.Host,
                        Utils.GetTypeTableFromExecutionContextTLS());

            remoteRunspace.Events.ReceivedEvents.PSEventReceived += OnRunspacePSEventReceived;

            Pipeline pipeline = CreatePipeline(remoteRunspace);

            IThrottleOperation operation =
                new ExecutionCmdletHelperComputerName(remoteRunspace, pipeline);

            Operations.Add(operation);
        }
Exemplo n.º 11
0
		public static RemoteRunspace FromPSObjectForRemoting (PSObject obj)
		{
			int id = RemotingDecoder.GetPropertyValue<int> (obj, "Id");
			string name = RemotingDecoder.GetPropertyValue<string> (obj, "Name");
			PSPrimitiveDictionary appArgs = RemotingDecoder.GetPropertyValue<PSPrimitiveDictionary> (obj, "ApplicationArguments");
			string connectionInfoType = RemotingDecoder.GetPropertyValue<string> (obj, "ConnectionInfoType");
			PSObject connectionObj = RemotingDecoder.GetPropertyValue<PSObject> (obj, "ConnectionInfo");
			RunspaceConnectionInfo connectionInfo = null;
			if (connectionInfoType == "WSManConnectionInfo") {
				connectionInfo = WSManConnectionInfo.FromPSObjectForRemoting (connectionObj);
			} 
			else 
			{
				var securePassord = new System.Security.SecureString();
				securePassord.AppendChar ('z');
				connectionInfo = new NewProcessConnectionInfo(new PSCredential("Anonymous", securePassord));
			}
			var runspace = new RemoteRunspace(new TypeTable(), connectionInfo, null, appArgs, name, id);
			runspace._version =	RemotingDecoder.GetPropertyValue<Version>(obj, "Version");
			runspace.ApartmentState = RemotingDecoder.GetPropertyValue<ApartmentState>(obj, "ApartmentState");
			runspace.InstanceId = RemotingDecoder.GetPropertyValue<Guid>(obj, "InstanceId");
			runspace._shouldCloseOnPop = RemotingDecoder.GetPropertyValue<bool>(obj, "ShouldCloseOnPop");
			runspace._runspaceStateInfo = new System.Management.Automation.Runspaces.RunspaceStateInfo(RemotingDecoder.GetPropertyValue<RunspaceState>(obj, "RunspaceStateInfo"));
			runspace._runspaceAvailability = RemotingDecoder.GetPropertyValue<RunspaceAvailability>(obj, "RunspaceAvailability");
			runspace.ThreadOptions = RemotingDecoder.GetPropertyValue<PSThreadOptions>(obj, "ThreadOptions");
			runspace.EngineActivityId = RemotingDecoder.GetPropertyValue<Guid>(obj, "EngineActivityId");
			runspace._bSessionStateProxyCallInProgress = RemotingDecoder.GetPropertyValue<bool>(obj, "SessionStateProxyCallInProgress");
			runspace._bypassRunspaceStateCheck = RemotingDecoder.GetPropertyValue<bool>(obj, "ByPassRunspaceStateCheck");
			PSEtwLog.SetActivityIdForCurrentThread(runspace.InstanceId);
			string originalConnectionInfoType = RemotingDecoder.GetPropertyValue<string> (obj, "OriginalConnectionInfoType");
			PSObject originalConnectionObj = RemotingDecoder.GetPropertyValue<PSObject> (obj, "OriginalConnectionInfo");
			RunspaceConnectionInfo originalConnectionInfo = null;
			if (originalConnectionInfoType == "WSManConnectionInfo") {
				originalConnectionInfo = WSManConnectionInfo.FromPSObjectForRemoting (originalConnectionObj);
			}
			else 
			{
				var securePassord = new System.Security.SecureString();
				securePassord.AppendChar ('z');
				originalConnectionInfo = new NewProcessConnectionInfo(new PSCredential("Anonymous", securePassord));
			}
			runspace._originalConnectionInfo = originalConnectionInfo;
			runspace.RunspacePool.RemoteRunspacePoolInternal.SetStateInfo (new RunspacePoolStateInfo(RunspacePoolState.Opened, null));
			return runspace;
		}