Example #1
0
        public void SuccessfullyExit(ITerminalConnection connection)
        {
            ITerminalSettings terminalSettings = PoderosaTerminalEmulatorService.CreateDefaultTerminalSettings(Connection.DisplayName, null);

            TerminalSession session       = new TerminalSession(connection, terminalSettings);
            SessionHost     sessionHost   = new SessionHost(PoderosaSessionManagerPlugin, session);
            TerminalView    terminalView  = new TerminalView(null, _terminal);
            RenderProfile   renderProfile = new RenderProfile(_terminal.GetRenderProfile());

            renderProfile.BackColor = Connection.BackgroundColor;
            renderProfile.ForeColor = Connection.TextColor;

            session.TerminalSettings.BeginUpdate();
            session.TerminalSettings.RenderProfile = renderProfile;
            session.TerminalSettings.EndUpdate();

            _sshConnection = (SSHTerminalConnection)connection;

            Invoke(
                new Action(
                    () =>
            {
                _terminal.Attach(session);

                session.InternalStart(sessionHost);
                session.InternalAttachView(sessionHost.DocumentAt(0), terminalView);

                _sshConnection.ConnectionEventReceiver.NormalTermination   += ConnectionEventReceiver_NormalTermination;
                _sshConnection.ConnectionEventReceiver.AbnormalTermination += ConnectionEventReceiver_AbnormalTermination;

                ParentForm.Closing += ParentForm_OnClosing;

                OnConnected(_terminal, null);
            }));
        }
Example #2
0
        /// <summary>
        /// Creates a new network session for users to join.
        /// </summary>
        /// <param name="username">The username the user wants.</param>
        /// <paramm name="port">Port to host the server on</param>
        // TODO: Take in parameters from user
        private void CreateNewLobbySession(string username, int port)
        {
            SessionHost host = new SessionHost(username, port);
            host.CreateNewSession();

        }
        public static Response DeleteForce(this WindowsWirtualDesktopManagementClient client, SessionHost sessionHost)
        {
            var userSessions = client.UserSessionOperations.List(new UserSession(sessionHost.HostPoolName, sessionHost.TenantName, sessionHost.TenantGroupName)).Value.Where(x => x.SessionHostName == sessionHost.SessionHostName);

            if (userSessions.Any())
            {
                foreach (var userSession in userSessions)
                {
                    client.UserSessionOperations.Logoff(userSession, true);
                }
            }

            return(client.SessionHostOperations.Delete(sessionHost));
        }
        /// <summary>
        /// Wires up a PowerShell runspace created via <see cref="RunspaceFactory.CreateRunspace()"/> to the terminal to display the PowerShell to the user.
        /// </summary>
        public override void Connect()
        {
            _progressBar.Value  = 0;
            _progressLabel.Text = "";

            // This is not strictly a network connection:  we're relaying information that we receive from the runspace to the terminal over a local stream
            // (a StreamConnection in this case)
            ITerminalParameter terminalParam = new EmptyTerminalParameter();
            StreamConnection   connection    = new StreamConnection(terminalParam)
            {
                Capture = false
            };

            // Attach the new "connection" to the terminal control
            try
            {
                ITerminalSettings terminalSettings = PoderosaTerminalEmulatorService.CreateDefaultTerminalSettings(Connection.DisplayName, null);
                TerminalSession   session          = new TerminalSession(connection, terminalSettings);
                SessionHost       sessionHost      = new SessionHost(PoderosaSessionManagerPlugin, session);
                TerminalView      terminalView     = new TerminalView(null, _terminal);
                RenderProfile     renderProfile    = new RenderProfile(_terminal.GetRenderProfile());

                renderProfile.BackColor = Connection.BackgroundColor;
                renderProfile.ForeColor = Connection.TextColor;
                renderProfile.FontName  = Connection.FontFamily;
                renderProfile.FontSize  = Connection.FontSize;

                session.TerminalSettings.BeginUpdate();
                session.TerminalSettings.RenderProfile = renderProfile;
                session.TerminalSettings.EndUpdate();

                _terminal.Attach(session);

                session.InternalStart(sessionHost);
                session.InternalAttachView(sessionHost.DocumentAt(0), terminalView);

                _powerShellHost = new PowerShellHost(this, _terminal, connection, ExecuteQuiet, _progressBar, _progressLabel);

                // Create the host and runspace instances for this interpreter.  If we're connecting to the local host, don't bother with the connection info.
                // ReSharper disable StringCompareIsCultureSpecific.3
                if (String.Compare(Connection.Host, "localhost", true) != 0 && Connection.Host != "127.0.0.1" &&
                    String.Compare(Connection.Host, Environment.MachineName, true) != 0)
                // ReSharper restore StringCompareIsCultureSpecific.3
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo
                    {
                        ComputerName = Connection.Host
                    };

                    if (!String.IsNullOrEmpty(Connection.InheritedUsername))
                    {
                        connectionInfo.Credential = new PSCredential(Connection.InheritedUsername, Connection.InheritedPassword);
                    }

                    Runspace = RunspaceFactory.CreateRunspace(_powerShellHost, connectionInfo);
                }

                else
                {
                    Runspace = RunspaceFactory.CreateRunspace(_powerShellHost);
                }

                Runspace.Open();
            }

            catch (Exception e)
            {
                OnConnectionLost(this, new ErrorEventArgs(e));
                return;
            }

            // Start capturing input from the prompt via the input loop
            _inputThread = new Thread(InputLoop)
            {
                Name = "PowerShellConnectionForm Input Thread"
            };
            _inputThread.Start();

            ParentForm.Closing += ParentForm_Closing;

            OnConnected(this, null);
        }
        public static async Task <Response> DeleteForceAsync(this WindowsWirtualDesktopManagementClient client, SessionHost sessionHost)
        {
            var result = await client.UserSessionOperations.ListAsync(new UserSession(sessionHost.HostPoolName, sessionHost.TenantName, sessionHost.TenantGroupName)).ConfigureAwait(false);

            var userSessions = result.Value.Where(x => x.SessionHostName == sessionHost.SessionHostName);

            if (userSessions.Any())
            {
                foreach (var userSession in userSessions)
                {
                    await client.UserSessionOperations.LogoffAsync(userSession, true).ConfigureAwait(false);
                }
            }

            return(await client.SessionHostOperations.DeleteAsync(sessionHost).ConfigureAwait(false));
        }