Пример #1
0
        /// <summary>
        /// Funzione che chiude un singolo tab
        /// </summary>
        /// <param name="tab">Riferimento al tab da chiudere</param>
        public void CloseTab(DynamicTabItem tab)
        {
            // Caso in cui il tab da chiudere sia l'ultimo attivo: chiusura dell'intera finestra
            if (ServerTabs.Count == 1)
            {
                this.Close();
                return;
            }

            ServerTabManagement servertab = tab.ServerTab;

            // In caso di chiusura della main window, la funzione di chiusura di questo tab non andrà più eseguita
            ClosingEvent -= servertab.ServerTabClose;

            // Chiusura del tab
            servertab.ServerTabClose();

            // Rimozione di questo tab dalla lista dei tab dei server
            ServerTabs.Remove(tab);

            // Rimozione dei questa connessione dalla lista di connessioni attive
            ActiveConnections.Remove(tab.RemoteHost);

            if (ServerTabs.Count == 1)
            {
                ForegroundAppsBox.IsEnabled = false;
            }
        }
Пример #2
0
        static public void SendError(ServerTabManagement Item)
        {
            MessageBoxResult res = MessageBox.Show("Errore durante l'invio del comando. Chiudere la connessione?", "Attenzione!", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (res == MessageBoxResult.Yes)
            {
                Item.ServerTab.MainWndw.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => { Item.ServerTab.MainWndw.CloseTab(Item.ServerTab); }));
            }
        }
Пример #3
0
        /// <summary>
        /// Funzione associata al tasto disconnetti. Chiude il tab relativo a server da cui vi si sta disconnettendo.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void F_Disconnect_Click(object sender, RoutedEventArgs e)
        {
            ServerTabManagement s = ServerTabControl.SelectedContent as ServerTabManagement;

            if (s != null)
            {
                CloseTab(s.ServerTab);
            }
        }
Пример #4
0
 static public void ReceiveConnectionError(ServerTabManagement Item)
 {
     MessageBox.Show("Errore di connessione.", "Attenzione!", MessageBoxButton.OK, MessageBoxImage.Warning);
     if (Item.ServerTab.MainWndw.ServerTabs.Count == 1)
     {
         Item.ServerTab.MainWndw.Error = true;
     }
     Item.ServerTab.MainWndw.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
     {
         Item.ServerTab.MainWndw.CloseTab(Item.ServerTab);
     }));
 }
Пример #5
0
        } // ClientKeyPressed closing bracket

        /// <summary>
        /// Metodo che gestisce la terminazione dell'invio di dati al server
        /// </summary>
        /// <param name="a"></param>
        private void SendToServer(IAsyncResult a)
        {
            ServerTabManagement s = (ServerTabManagement)a.AsyncState;

            try
            {
                s.Stream.EndWrite(a);
            }
            catch (IOException)
            {
                ExceptionHandler.SendError(s);
            }
        }
Пример #6
0
        /// <summary>
        /// Funzione che crea un nuovo tab
        /// </summary>
        /// <param name="client"></param>
        /// <param name="stream"></param>
        /// <param name="address"></param>
        public void NewTab(TcpClient client, NetworkStream stream, String address)
        {
            DynamicTabItem      tab = new DynamicTabItem(this);
            ServerTabManagement s   = new ServerTabManagement(tab);

            tab.ServerTab = s;

            // Il titolo del nuovo tab ed il suo host remoto corrispondono all'indirizzo del server
            tab.DynamicHeader = tab.RemoteHost = address;

            if (address.StartsWith("127."))
            {
                tab.DynamicHeader = "Loopback";
            }
            else
            {
                Dns.BeginGetHostEntry(address, new AsyncCallback((IAsyncResult ar) =>
                {
                    try
                    {
                        string host = Dns.EndGetHostEntry(ar).HostName;
                        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                        {
                            tab.DynamicHeader = host;
                        }));
                    }
                    catch (SocketException)
                    {
                        Console.WriteLine("Server {0}: Nessun host trovato", address);
                    }
                }), null);
            }

            s.Connection = client;
            s.Stream     = stream;
            s.StartServerDataExchange();
            tab.Content = s;

            // Aggiunta del nuovo tab alla lista
            ServerTabs.Add(tab);

            // Evidenziazione dell'ultimo tab creato
            ServerTabControl.SelectedIndex = ServerTabs.Count - 1;

            if (ServerTabs.Count > 1)
            {
                ForegroundAppsBox.IsEnabled = true;
            }
        }
Пример #7
0
        /// <summary>
        /// Funzione invocata dall'evento KeyPressed.
        /// Cattura e registra i modificatori premuti ed invia i tasti premuti.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ClientKeyPressed(object sender, KeyEventArgs e)
        {
            Key key;

            if (e.Key == Key.System)
            {
                key = e.SystemKey;
            }
            else
            {
                key = e.Key;
            }

            switch (key)
            {
            case Key.LeftShift:
            case Key.RightShift:
                modifier   = modifier | mod_code.shift;
                Shift.Fill = new SolidColorBrush(Colors.Blue);
                e.Handled  = true;
                break;

            case Key.LeftCtrl:
            case Key.RightCtrl:
                modifier  = modifier | mod_code.ctrl;
                Ctrl.Fill = new SolidColorBrush(Colors.Blue);
                e.Handled = true;
                break;

            case Key.LeftAlt:
            case Key.RightAlt:
                modifier  = modifier | mod_code.alt;
                Alt.Fill  = new SolidColorBrush(Colors.Blue);
                e.Handled = true;
                break;

            default:
                break;
            } // Switch closing bracket

            // Nel caso in cui il tasto premuto non sia un modificatore
            if (e.Handled == false)
            {
                // Preparazione dei dati da inviare
                int    conv_key = KeyInterop.VirtualKeyFromKey(key);
                byte[] buffer   = new byte[1 + sizeof(int)];        // Struttura che conterrà (Modificatori + tasto)
                buffer[0] = (byte)modifier;
                BitConverter.GetBytes(IPAddress.HostToNetworkOrder(conv_key)).CopyTo(buffer, 1);

                // Recupero l'applicazione che è in focus dall'elemento selezionato nella combobox

                ForegroundApp appinfocus = ForegroundAppsBox.SelectedItem as ForegroundApp;
                if (appinfocus == null)
                {
                    e.Handled = true;
                    return;
                }

                // Se c'è almeno un app in focus, cerchiamo il tab o server a cui appartiene
                foreach (DynamicTabItem tab in ServerTabs)
                {
                    if (tab.ForegroundApp == appinfocus.Name)
                    {
                        ServerTabManagement s = tab.Content as ServerTabManagement;
                        if (s != null)
                        {
                            try
                            {
                                s.Stream.BeginWrite(buffer, 0, 1 + sizeof(int), new AsyncCallback(SendToServer), s);
                            }
                            catch (IOException)
                            {
                                ExceptionHandler.SendError(s);
                            }
                        }
                    }
                }

                e.Handled = true;
            }
        } // ClientKeyPressed closing bracket
Пример #8
0
 /// <summary>
 /// Costruttore della classe SocketListener
 /// </summary>
 /// <param name="s"></param>
 public SocketListener(ServerTabManagement s)
 {
     Item   = s;
     Stream = s.Stream;
 }