void btnEndSession_Click(object sender, EventArgs e)
        {
            DialogInput clientnameDlg = new DialogInput("Please enter target client:");

            if (clientnameDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            client.EndCurrentSession(clientnameDlg.Result, (senderClient, response) =>
            {
                InvokeUI(() =>
                {
                    if (!response.HasError)
                    {
                        btnEndSession.Enabled    = false;
                        btnStartSession.Enabled  = true;
                        btnCalc.Enabled          = false;
                        btnRemoteDesktop.Enabled = false;
                        btnSendMessage.Enabled   = false;
                        btnUploadFile.Enabled    = false;
                    }
                    else
                    {
                        Status(response.Exception.ToString());
                    }
                });
            });
        }
        void btnLogin_Click(object sender, EventArgs e)
        {
            DialogInput dlg = new DialogInput("Please enter your user name:");

            if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            client.Login(dlg.Result, (senderClient, args) =>
            {
                if (args.IsValid)
                {
                    Status("User Validated!");
                    this.InvokeUI(() =>
                    {
                        this.Text = "Client - " + dlg.Result;
                        btnStartSession.Enabled = true;
                        btnLogin.Enabled        = false;
                    });
                }

                if (args.HasError)
                {
                    Status(args.Exception.ToString());
                }
            });
        }
        void btnStartSession_Click(object sender, EventArgs e)
        {
            DialogInput dlg = new DialogInput("Please enter target client:");

            if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            client.RequestSession(dlg.Result, (senderClient, args) =>
            {
                if (args.IsConfirmed)
                {
                    Status("Session started with " + dlg.Result);

                    InvokeUI(() =>
                    {
                        btnSendMessage.Enabled   = true;
                        btnRemoteDesktop.Enabled = true;
                        btnCalc.Enabled          = true;
                        btnUploadFile.Enabled    = true;
                        btnEndSession.Enabled    = true;
                    });
                }
                else
                {
                    Status(args.Exception.ToString());
                }
            });
        }
        void btnUploadFile_Click(object sender, EventArgs e)
        {
            DialogInput clientnameDlg = new DialogInput("Please enter target client:");

            if (clientnameDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title = this.Text + " select file to upload";
            if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            client.UploadFile(dlg.FileName, clientnameDlg.Result, (clientSender, response) =>
            {
                if (response.HasError)
                {
                    Status($"{response.Exception.Message}");
                    return;
                }
                //Status("Uploading " + response.FileName + ", " + ((response.CurrentPosition * 100) / response.TotalBytes) + "%...");
                Status($"{response.CurrentPosition} / {response.TotalBytes}");

                if (response.CurrentPosition >= response.TotalBytes)
                {
                    Status("Uploading " + response.FileName + " Completed!");
                }
            });
        }
        void btnRemoteDesktop_Click(object sender, EventArgs e)
        {
            DialogInput clientnameDlg = new DialogInput("Please enter target client:");

            if (clientnameDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            client.RequestDesktop(clientnameDlg.Result, (clientSender, response) =>
            {
                panelPreview.BackgroundImage = new Bitmap(response.FrameBytes);
                response.FrameBytes.Dispose();
            });
        }
        void btnSendMessage_Click(object sender, EventArgs e)
        {
            DialogInput clientnameDlg = new DialogInput("Please enter target client:");

            if (clientnameDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            DialogInput dlg = new DialogInput("Enter text message:");

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            client.SendTextMessage(dlg.Result, clientnameDlg.Result);
        }
        private void btnCalc_Click(object sender, EventArgs e)
        {
            DialogInput clientnameDlg = new DialogInput("Please enter target client:");

            if (clientnameDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            MessagesExtensions.CalcMessageRequest request = new MessagesExtensions.CalcMessageRequest();
            request.A = 10;
            request.B = 5;

            client.SendGenericRequest <MessagesExtensions.CalcMessageResponseDelegate>(clientnameDlg.Result, request, (clientSender, response) =>
            {
                InvokeUI(() =>
                {
                    MessageBox.Show(this, response.Result.ToString(), this.Text);
                });
            });
        }
        void btnConnect_Click(object sender, EventArgs e)
        {
            DialogInput clientnameDlg = new DialogInput("Please enter target server:");

            if (clientnameDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string serverIp = String.IsNullOrWhiteSpace(clientnameDlg.Result) ? "10.0.85.35" : clientnameDlg.Result;

            clientnameDlg = new DialogInput("Please enter target port:");
            if (clientnameDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            int serverPort = String.IsNullOrWhiteSpace(clientnameDlg.Result) ? 5904 : int.Parse(clientnameDlg.Result);

            client.Connect(serverIp, serverPort);
            btnLogin.Enabled      = true;
            btnDisconnect.Enabled = true;
            btnConnect.Enabled    = false;
        }