Exemplo n.º 1
0
        internal static RemoteDataObject GenerateCreatePowerShell(ClientRemotePowerShell shell)
        {
            HostInfo             info;
            PowerShell           powerShell   = shell.PowerShell;
            PSInvocationSettings settings     = shell.Settings;
            PSObject             data         = CreateEmptyPSObject();
            Guid           empty              = Guid.Empty;
            ApartmentState unknown            = ApartmentState.Unknown;
            RunspacePool   runspaceConnection = powerShell.GetRunspaceConnection() as RunspacePool;

            empty   = runspaceConnection.InstanceId;
            unknown = runspaceConnection.ApartmentState;
            data.Properties.Add(new PSNoteProperty("PowerShell", powerShell.ToPSObjectForRemoting()));
            data.Properties.Add(new PSNoteProperty("NoInput", shell.NoInput));
            if (settings == null)
            {
                info = new HostInfo(null)
                {
                    UseRunspaceHost = true
                };
                data.Properties.Add(new PSNoteProperty("ApartmentState", unknown));
                data.Properties.Add(new PSNoteProperty("RemoteStreamOptions", RemoteStreamOptions.AddInvocationInfo));
                data.Properties.Add(new PSNoteProperty("AddToHistory", false));
            }
            else
            {
                info = new HostInfo(settings.Host);
                if (settings.Host == null)
                {
                    info.UseRunspaceHost = true;
                }
                data.Properties.Add(new PSNoteProperty("ApartmentState", settings.ApartmentState));
                data.Properties.Add(new PSNoteProperty("RemoteStreamOptions", settings.RemoteStreamOptions));
                data.Properties.Add(new PSNoteProperty("AddToHistory", settings.AddToHistory));
            }
            PSNoteProperty member = CreateHostInfoProperty(info);

            data.Properties.Add(member);
            data.Properties.Add(new PSNoteProperty("IsNested", shell.PowerShell.IsNested));
            return(RemoteDataObject.CreateFrom(RemotingDestination.InvalidDestination | RemotingDestination.Server, RemotingDataType.CreatePowerShell, empty, shell.InstanceId, data));
        }
Exemplo n.º 2
0
        internal static RemoteDataObject GenerateCreatePowerShell(
            ClientRemotePowerShell shell)
        {
            PowerShell           powerShell    = shell.PowerShell;
            PSInvocationSettings settings      = shell.Settings;
            PSObject             emptyPsObject = RemotingEncoder.CreateEmptyPSObject();
            Guid           empty = Guid.Empty;
            RunspacePool   runspaceConnection = powerShell.GetRunspaceConnection() as RunspacePool;
            Guid           instanceId         = runspaceConnection.InstanceId;
            ApartmentState apartmentState     = runspaceConnection.ApartmentState;

            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("PowerShell", (object)powerShell.ToPSObjectForRemoting()));
            emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("NoInput", (object)shell.NoInput));
            HostInfo hostInfo;

            if (settings == null)
            {
                hostInfo = new HostInfo((PSHost)null);
                hostInfo.UseRunspaceHost = true;
                emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("ApartmentState", (object)apartmentState));
                emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("RemoteStreamOptions", (object)RemoteStreamOptions.AddInvocationInfo));
                emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("AddToHistory", (object)false));
            }
            else
            {
                hostInfo = new HostInfo(settings.Host);
                if (settings.Host == null)
                {
                    hostInfo.UseRunspaceHost = true;
                }
                emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("ApartmentState", (object)settings.ApartmentState));
                emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("RemoteStreamOptions", (object)settings.RemoteStreamOptions));
                emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("AddToHistory", (object)settings.AddToHistory));
            }
            PSNoteProperty hostInfoProperty = RemotingEncoder.CreateHostInfoProperty(hostInfo);

            emptyPsObject.Properties.Add((PSPropertyInfo)hostInfoProperty);
            return(RemoteDataObject.CreateFrom(RemotingDestination.Server, RemotingDataType.CreatePowerShell, instanceId, shell.InstanceId, (object)emptyPsObject));
        }