예제 #1
0
        public ConsoleSession CreateCmdSession()
        {
            var session = new ConsoleSession();

            StartCmdLoopForSession(session);
            return(session);
        }
예제 #2
0
        public ConsoleSession CreateCmdSession(ConsoleClient clientToAttach)
        {
            var session = new ConsoleSession();

            clientToAttach.Attach(session);
            StartCmdLoopForSession(session);
            return(session);
        }
예제 #3
0
 public void StartCmdLoopForSession(ConsoleSession session)
 {
     StartSafeThread(() => {
         this.AddConsole(session);
         this.CommandHub.CmdLoop(session.Console);
         this.RemoveConsole(session);
         session.RemoveAllClient();
     }, "CmdSession");
 }
예제 #4
0
        public void RemoveConsole(ConsoleSession console)
        {
            if (console == null)
            {
                throw new ArgumentNullException(nameof(console));
            }

            Sessions.Remove(console);
        }
예제 #5
0
        public void AddConsole(ConsoleSession console)
        {
            if (console == null)
            {
                throw new ArgumentNullException(nameof(console));
            }
            if (Sessions.Contains(console))
            {
                throw new Exception("this console has been already added.");
            }

            Sessions.Add(console);
        }
예제 #6
0
        public virtual void Attach(ConsoleSession session)
        {
            if (session == Session)
            {
                return;
            }
            var oldSession = Session;

            Session = null;
            oldSession?.RemoveClient(this);
            this.Session = session;
            Session?.AddClient(this);
            SessionChanged?.Invoke(this);
        }
예제 #7
0
        private void _sessionSelect(ConsoleClient client, bool autoCreate)
        {
            if (Sessions.Count == 0 && autoCreate)
            {
                CreateCmdSession(client);
                return;
            }
            var tempsession = new ConsoleSession();

            void checkDetach(ConsoleClient cli)
            {
                if (cli.Session != tempsession)
                {
                    cli.SessionChanged -= checkDetach;
                    tempsession.InputLine(null);
                }
            }

            client.SessionChanged += checkDetach;
            client.Attach(tempsession);
            var c = tempsession.Console;

            while (true)
            {
                c.WriteLine("Select Session:");
                var sessions = Sessions.ToArray();
                for (int i = 0; i < sessions.Length; i++)
                {
                    c.WriteLine($"{i} {sessions[i]}");
                }
                c.WriteLine("n New Session");
                var line = c.ReadLine("> ");
                if (line == null)
                {
                    return;
                }
                if (int.TryParse(line, out int n) && n >= 0 && n < sessions.Length)
                {
                    client.Attach(sessions[n]);
                    break;
                }
                else if (line == "n")
                {
                    CreateCmdSession(client);
                    break;
                }
            }
        }
예제 #8
0
 public CmdRunner(ConsoleSession session)
 {
     _session = session;
 }