/// <summary>
        /// This constructor will be used to created a remote runspace info
        /// object with a auto generated name.
        /// </summary>
        /// <param name="remoteRunspace">Remote runspace object for which
        /// the info object need to be created</param>
        internal PSSession(RemoteRunspace remoteRunspace)
        {
            _remoteRunspace = remoteRunspace;

            // Use passed in session Id, if available.
            if (remoteRunspace.PSSessionId != -1)
            {
                Id = remoteRunspace.PSSessionId;
            }
            else
            {
                Id = System.Threading.Interlocked.Increment(ref s_seed);
                remoteRunspace.PSSessionId = Id;
            }

            // Use passed in friendly name, if available.
            if (!string.IsNullOrEmpty(remoteRunspace.PSSessionName))
            {
                Name = remoteRunspace.PSSessionName;
            }
            else
            {
                Name = "Runspace" + Id;
                remoteRunspace.PSSessionName = Name;
            }

            switch (remoteRunspace.ConnectionInfo)
            {
            case WSManConnectionInfo _:
                ComputerType = TargetMachineType.RemoteMachine;
                string fullShellName = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(
                    remoteRunspace.ConnectionInfo,
                    "ShellUri", string.Empty);
                ConfigurationName = GetDisplayShellName(fullShellName);
                break;

            case VMConnectionInfo vmConnectionInfo:
                ComputerType      = TargetMachineType.VirtualMachine;
                ConfigurationName = vmConnectionInfo.ConfigurationName;
                break;

            case ContainerConnectionInfo containerConnectionInfo:
                ComputerType      = TargetMachineType.Container;
                ConfigurationName = containerConnectionInfo.ContainerProc.ConfigurationName;
                break;

            case SSHConnectionInfo _:
                ComputerType      = TargetMachineType.RemoteMachine;
                ConfigurationName = "DefaultShell";
                break;

            case NewProcessConnectionInfo _:
                ComputerType = TargetMachineType.RemoteMachine;
                break;

            default:
                Dbg.Assert(false, "Invalid Runspace");
                break;
            }
        }
Esempio n. 2
0
        internal PSSession(RemoteRunspace remoteRunspace)
        {
            this.remoteRunspace = remoteRunspace;
            if (remoteRunspace.Id != -1)
            {
                this.sessionid = remoteRunspace.Id;
            }
            else
            {
                this.sessionid    = Interlocked.Increment(ref seed);
                remoteRunspace.Id = this.sessionid;
            }
            if (!string.IsNullOrEmpty(remoteRunspace.Name))
            {
                this.name = remoteRunspace.Name;
            }
            else
            {
                this.name           = this.AutoGenerateRunspaceName();
                remoteRunspace.Name = this.name;
            }
            string shell = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(remoteRunspace.ConnectionInfo, "ShellUri", string.Empty);

            this.shell = this.GetDisplayShellName(shell);
        }
Esempio n. 3
0
        /// <summary>
        /// This constructor will be used to created a remote runspace info
        /// object with a auto generated name
        /// </summary>
        /// <param name="remoteRunspace">Remote runspace object for which
        /// the info object need to be created</param>
        internal PSSession(RemoteRunspace remoteRunspace)
        {
            _remoteRunspace = remoteRunspace;

            // Use passed in session Id, if available.
            if (remoteRunspace.PSSessionId != -1)
            {
                Id = remoteRunspace.PSSessionId;
            }
            else
            {
                Id = System.Threading.Interlocked.Increment(ref s_seed);
                remoteRunspace.PSSessionId = Id;
            }

            // Use passed in friendly name, if available.
            if (!string.IsNullOrEmpty(remoteRunspace.PSSessionName))
            {
                Name = remoteRunspace.PSSessionName;
            }
            else
            {
                Name = "Runspace" + Id;
                remoteRunspace.PSSessionName = Name;
            }

            // WSMan session
            if (remoteRunspace.ConnectionInfo is WSManConnectionInfo)
            {
                ComputerType = TargetMachineType.RemoteMachine;

                string fullShellName = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(
                    remoteRunspace.ConnectionInfo,
                    "ShellUri", string.Empty);

                ConfigurationName = GetDisplayShellName(fullShellName);
                return;
            }

            // VM session
            VMConnectionInfo vmConnectionInfo = remoteRunspace.ConnectionInfo as VMConnectionInfo;

            if (vmConnectionInfo != null)
            {
                ComputerType      = TargetMachineType.VirtualMachine;
                ConfigurationName = vmConnectionInfo.ConfigurationName;
                return;
            }

            // Container session
            ContainerConnectionInfo containerConnectionInfo = remoteRunspace.ConnectionInfo as ContainerConnectionInfo;

            if (containerConnectionInfo != null)
            {
                ComputerType      = TargetMachineType.Container;
                ConfigurationName = containerConnectionInfo.ContainerProc.ConfigurationName;
                return;
            }

            // SSH session
            SSHConnectionInfo sshConnectionInfo = remoteRunspace.ConnectionInfo as SSHConnectionInfo;

            if (sshConnectionInfo != null)
            {
                ComputerType      = TargetMachineType.RemoteMachine;
                ConfigurationName = "DefaultShell";
                return;
            }

            // We only support WSMan/VM/Container sessions now.
            Dbg.Assert(false, "Invalid Runspace");
        }