Esempio n. 1
0
        private void Connect_Click(object sender, RoutedEventArgs e)
        {
            saveCursor           = this.Cursor;
            Mouse.OverrideCursor = Cursors.Wait;

            Connect_Button.IsEnabled = false;

            try
            {
                senderSock = SocketHelper.Connect(textBox.Text);
                IPEndPoint remoteIpEndPoint = senderSock.RemoteEndPoint as IPEndPoint;
                pageforNewConnection.reportActivity("\n Client connected to : " + remoteIpEndPoint, Brushes.Blue, FontWeights.Regular);
                //faccio prima anche se potrei fare dopo, cosi mi porto avanti prima di fare la recv, ma forse non va bene
                pageforNewConnection.addServer(senderSock);

                JsonObject jsObj = SocketHelper.ReceiveImmediatly <JsonObject>(senderSock);
                pageforNewConnection.firstInfo(jsObj, senderSock);

                Switcher.Switch(pageforNewConnection);      //forse meglio spostare, decido quando cambiare pagina
            }
            catch (Exception ex)
            {
                writeError(ex.Message);
            }
            finally
            {
                Connect_Button.IsEnabled = true;
                Mouse.OverrideCursor     = saveCursor;
            }
        }
        private void SendKeys(object sender, RoutedEventArgs e)
        {
            commObj.Lista = commandList;
            commObj.Tasti = commandList.Count;

            try
            {
                if (checkForAllServer.IsChecked == true)
                {
                    //send to all server with this opened programs
                    foreach (var value in pageforNewConnection.serverList)
                    {
                        if (value.List.Exists(item => item.Name == commObj.Application))
                        {
                            SocketHelper.Send(value.sock, commObj);
                        }
                        //Trace Activity
                        pageforNewConnection.reportActivity("\n Sent keystrtokes: " + commandsField.Text + ", to : " + value.Name, Brushes.Black, FontWeights.Normal);
                    }
                }
                else
                {
                    SocketHelper.Send(actualServer.sock, commObj);
                    //Trace Activity
                    pageforNewConnection.reportActivity("\n Sent keystrtokes: " + commandsField.Text + ", to : " + actualServer.Name, Brushes.Black, FontWeights.Normal);
                }

                commandsField.Text = "";
                commandList.Clear();

                //return to prevoius page
                Switcher.Switch(pageforNewConnection);
            }
            catch (NullReferenceException)
            {
                //ignore
            }
            catch (Exception ex)
            {
                messageError.Content    = ex.ToString();
                messageError.Visibility = Visibility.Visible;
            }
        }