Пример #1
0
 private void NewSession(TcpClientSession session)
 {
     session.SentCompleted += (s, e) =>
     {
         IncreaseSentSize(e.Header.DataLength + Header.HEADER_SIZE);
         if (e.Header.Key == MessageKeys.Literal)
         {
             var msg = (BytesMessage)e;
             Print($"{e.Header.From}:{MessageHelper.LiteralEncoding.GetString(msg.Bytes)}");
         }
         else if (e.Header.Key == MessageKeys.File)
         {
             Print($"{e.Header.From}:{e.Header.State}");
         }
     };
     session.Received += (s, e) =>
     {
         if (e.Header.Key == MessageKeys.Literal)
         {
             var msg = (BytesMessage)e;
             Print($"{e.Header.From ?? "system"}:{MessageHelper.LiteralEncoding.GetString(msg.Bytes)}");
         }
         else if (e.Header.Key == MessageKeys.Remote)
         {
             Remote(session, e.Header.From);
         }
         else if (e.Header.Key == MessageKeys.RemoteStop)
         {
         }
         else if (e.Header.Key == MessageKeys.RemoteImage)
         {
             var bytesMesaage = e as BytesMessage;
             var terminal     = RemoteForm.Get(e.Header.From);
             if (terminal == null)
             {
                 session.Send(MessageHelper.CreateRemoteStopMessage(this.userName, e.Header.From, null));
                 return;
             }
             if (terminal.Disposing || terminal.IsDisposed)
             {
                 return;
             }
             if (!terminal.Visible)
             {
                 this.Invoke(new MethodInvoker(() =>
                 {
                     terminal.Show();
                 }));
             }
             terminal.Draw(bytesMesaage.Bytes);
             Task.Run(() =>
             {
                 Thread.Sleep(1000);
                 SendRemoteImageRequest(e.Header.From);
             });
         }
     };
 }
Пример #2
0
        public static RemoteForm Add(string to)
        {
            if (termimals.Keys.Contains(to))
            {
                return(null);
            }
            var terminal = new RemoteForm(to);

            RemoteForm.termimals.Add(to, terminal);
            return(terminal);
        }
Пример #3
0
 private void txtConnectRemote_Click(object sender, EventArgs e)
 {
     if (remotes.Any(s => s.To == txtRemoteTarget.Text))
     {
         Print($"You are remoting {txtRemoteTarget.Text} now");
         return;
     }
     if (string.IsNullOrEmpty(txtRemoteTarget.Text))
     {
         Print("please input the username of the user you want to connect to");
         return;
     }
     remotes.Add(RemoteForm.Add(txtRemoteTarget.Text));
     SendRemoteImageRequest(txtRemoteTarget.Text);
 }