This class implements the ViewModel in the MVVM pattern. This relais data from the Peer to the configuration windows and allows user to update this configuration
Inheritance: INotifyPropertyChanged
Exemplo n.º 1
0
        /// <summary>
        /// Handler for the peer configuration menu item. This method shows the Peer configuration dialog.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void peer_config_item_Click(object sender, RoutedEventArgs e)
        {
            PeerConfigurationModel vm  = new PeerConfigurationModel(int.Parse(peer.ConfOptions["udpPort"]), int.Parse(peer.ConfOptions["kadPort"]));
            PeerSettingsDialog     dlg = new PeerSettingsDialog();

            dlg.DataContext = vm;
            dlg.Owner       = this;
            dlg.ShowDialog();
            if (dlg.DialogResult.HasValue && dlg.DialogResult.Value)
            {
                peer.Configure(vm.UdpPort.ToString(), vm.KademliaPort.ToString());
                MessageBox.Show(this, "Peer Settings successfully changed", "Peer Settings", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Default constructor. This constructor starts the splash in a different thread and the try to run the Peer.
        /// If the peer port is already in use a Peer Configuration dialog will be shown. If everything goes well the
        /// the model will be instantiated and the data context will be set. The splash screen will disappear when all
        /// GUI element have been loaded.
        /// </summary>
        public MainWindow()
        {
            bool keepTry = true;

            while (keepTry)
            {
                this.splashThread = new Thread(() =>
                {
                    System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => new AppSplashDialog().Show()));
                    System.Windows.Threading.Dispatcher.Run();
                });
                splashThread.SetApartmentState(ApartmentState.STA);
                splashThread.IsBackground = true;
                splashThread.Start();
                try
                {
                    peer = new Peer();
                    peer.RunLayers(true);
                    keepTry = false;
                }
                catch (SocketException aaiue)
                {
                    this.splashThread.Abort();
                    MessageBox.Show(aaiue.ToString(), "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
                    int udpPort = ((peer != null) ? int.Parse(peer.ConfOptions["udpPort"]) : 0);
                    int kadPort = ((peer != null) ? int.Parse(peer.ConfOptions["kadPort"]) : 0);
                    PeerConfigurationModel vm  = new PeerConfigurationModel(udpPort, kadPort);
                    PeerSettingsDialog     dlg = new PeerSettingsDialog();
                    dlg.DataContext = vm;
                    dlg.Activate();
                    dlg.ShowDialog();
                    if (dlg.DialogResult.HasValue && dlg.DialogResult.Value)
                    {
                        peer.Configure(vm.UdpPort.ToString(), vm.KademliaPort.ToString());
                        keepTry = true;
                    }
                    else
                    {
                        keepTry = false;
                    }
                }
                catch (FileNotFoundException)
                {
                    this.splashThread.Abort();
                    MessageBox.Show("Unable to find the file containing information about nodes. Download this file and retry.",
                                    "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(0);
                    keepTry = false;
                }
                catch (Exception e)
                {
                    this.splashThread.Abort();
                    MessageBox.Show(e.ToString(), "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(0);
                    keepTry = false;
                }
            }
            if (peer == null)
            {
                Environment.Exit(0);
            }
            playerModel = new AudioPlayerModel(peer);
            listModel   = new SearchListModel(peer);
            listModel.StreamRequested += playerModel.SetResourceHandler;
            this.InitializeComponent();
            object item = this.FindName("StreamPlayer");

            if ((item != null) && (item is AudioPlayer))
            {
                AudioPlayer p = item as AudioPlayer;
                p.SetDataContext(playerModel);
            }
            item = this.FindName("KadSearchList");
            if ((item != null))
            {
                SearchList s = item as SearchList;
                s.SetDataContext(listModel);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Handler for the peer configuration menu item. This method shows the Peer configuration dialog.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void peer_config_item_Click(object sender, RoutedEventArgs e)
 {
     PeerConfigurationModel vm = new PeerConfigurationModel(int.Parse(peer.ConfOptions["udpPort"]),int.Parse(peer.ConfOptions["kadPort"]));
     PeerSettingsDialog dlg = new PeerSettingsDialog();
     dlg.DataContext = vm;
     dlg.Owner = this;
     dlg.ShowDialog();
     if (dlg.DialogResult.HasValue && dlg.DialogResult.Value)
     {
         peer.Configure(vm.UdpPort.ToString(), vm.KademliaPort.ToString());
         MessageBox.Show(this, "Peer Settings successfully changed", "Peer Settings", MessageBoxButton.OK, MessageBoxImage.Information);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Default constructor. This constructor starts the splash in a different thread and the try to run the Peer.
 /// If the peer port is already in use a Peer Configuration dialog will be shown. If everything goes well the
 /// the model will be instantiated and the data context will be set. The splash screen will disappear when all
 /// GUI element have been loaded.
 /// </summary>
 public MainWindow()
 {
     bool keepTry = true;
     while (keepTry)
     {
         this.splashThread = new Thread(() =>
         {
             System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => new AppSplashDialog().Show()));
             System.Windows.Threading.Dispatcher.Run();
         });
         splashThread.SetApartmentState(ApartmentState.STA);
         splashThread.IsBackground = true;
         splashThread.Start();
         try
         {
             peer = new Peer();
             peer.RunLayers(true);
             keepTry = false;
         }
         catch (SocketException aaiue)
         {
             this.splashThread.Abort();
             MessageBox.Show(aaiue.ToString(), "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
             int udpPort = ((peer != null) ? int.Parse(peer.ConfOptions["udpPort"]) : 0);
             int kadPort = ((peer != null) ? int.Parse(peer.ConfOptions["kadPort"]) : 0);
             PeerConfigurationModel vm = new PeerConfigurationModel(udpPort, kadPort);
             PeerSettingsDialog dlg = new PeerSettingsDialog();
             dlg.DataContext = vm;
             dlg.Activate();
             dlg.ShowDialog();
             if (dlg.DialogResult.HasValue && dlg.DialogResult.Value)
             {
                 peer.Configure(vm.UdpPort.ToString(), vm.KademliaPort.ToString());
                 keepTry = true;
             }
             else
             {
                 keepTry = false;
             }
         }
         catch (FileNotFoundException)
         {
             this.splashThread.Abort();
             MessageBox.Show("Unable to find the file containing information about nodes. Download this file and retry.",
                                 "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
             Environment.Exit(0);
             keepTry = false;
         }
         catch (Exception e)
         {
             this.splashThread.Abort();
             MessageBox.Show(e.ToString(), "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
             Environment.Exit(0);
             keepTry = false;
         }
     }
     if (peer == null) Environment.Exit(0);
     playerModel = new AudioPlayerModel(peer);
     listModel = new SearchListModel(peer);
     listModel.StreamRequested += playerModel.SetResourceHandler;
     this.InitializeComponent();
     object item = this.FindName("StreamPlayer");
     if ((item != null)&&(item is AudioPlayer))
     {
         AudioPlayer p = item as AudioPlayer;
         p.SetDataContext(playerModel);
     }
     item = this.FindName("KadSearchList");
     if ((item != null))
     {
         SearchList s = item as SearchList;
         s.SetDataContext(listModel);
     }
 }