Exemplo n.º 1
0
        public CreateTerminalResponse CreateTerminal(CreateTerminalRequest request)
        {
            ITerminalSession terminal = null;

            try
            {
                if (request.SessionType == SessionType.WinPty)
                {
                    terminal = new WinPtySession();
                }
                else if (request.SessionType == SessionType.ConPty)
                {
                    terminal = new ConPtySession();
                }
                terminal.Start(request, this);
            }
            catch (Exception e)
            {
                return(new CreateTerminalResponse {
                    Error = e.ToString()
                });
            }

            terminal.ConnectionClosed += OnTerminalConnectionClosed;
            _terminals.Add(terminal.Id, terminal);
            return(new CreateTerminalResponse
            {
                Success = true,
                Id = terminal.Id,
                ShellExecutableName = terminal.ShellExecutableName
            });
        }
Exemplo n.º 2
0
        public CreateTerminalResponse CreateTerminal(CreateTerminalRequest request)
        {
            if (_terminals.ContainsKey(request.Id))
            {
                // App terminated without cleaning up, removing orphaned sessions
                foreach (var item in _terminals.Values)
                {
                    item.Dispose();
                }
                _terminals.Clear();
            }

            string error = request.Profile?.CheckIfMosh();

            if (!string.IsNullOrEmpty(error))
            {
                return(new CreateTerminalResponse
                {
                    Error = error, ShellExecutableName = request.Profile.Location, Success = false
                });
            }

            ITerminalSession terminal = null;

            try
            {
                if (request.SessionType == SessionType.WinPty)
                {
                    terminal = new WinPtySession();
                }
                else if (request.SessionType == SessionType.ConPty)
                {
                    terminal = new ConPtySession();
                }
                terminal.Start(request, this);
            }
            catch (Exception e)
            {
                return(new CreateTerminalResponse {
                    Error = e.ToString()
                });
            }

            terminal.ConnectionClosed += OnTerminalConnectionClosed;
            _terminals.Add(terminal.Id, terminal);
            return(new CreateTerminalResponse
            {
                Success = true,
                ShellExecutableName = terminal.ShellExecutableName
            });
        }
        public CreateTerminalResponse CreateTerminal(CreateTerminalRequest request)
        {
            if (_terminals.ContainsKey(request.Id))
            {
                // App terminated without cleaning up, removing orphaned sessions
                foreach (var item in _terminals.Values)
                {
                    item.Session.Dispose();
                }
                _terminals.Clear();
            }

            request.Profile.Location = Utilities.ResolveLocation(request.Profile.Location);

            ITerminalSession terminal = null;

            try
            {
                if (request.SessionType == SessionType.WinPty)
                {
                    terminal = new WinPtySession();
                }
                else
                {
                    terminal = new ConPtySession();
                }
                terminal.Start(request, this);
            }
            catch (Exception e)
            {
                return(new CreateTerminalResponse {
                    Error = e.ToString()
                });
            }

            var name = string.IsNullOrEmpty(request.Profile.Name) ? terminal.ShellExecutableName : request.Profile.Name;

            terminal.ConnectionClosed += OnTerminalConnectionClosed;
            _terminals.Add(terminal.Id, new TerminalSessionInfo
            {
                ProfileName = name,
                StartTime   = DateTime.Now,
                Session     = terminal
            });
            return(new CreateTerminalResponse
            {
                Success = true,
                Name = name
            });
        }