/// <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); } }
// private static readonly ILog log = LogManager.GetLogger(typeof(PeerRunner)); /// <summary> /// Main method of the class. /// </summary> /// <param name="args">List of arguments passed to the method from terminal</param> static void Main(string[] args) { bool withoutInterface = true; using (Peer p = new Peer()) { if (args.Length % 2 != 0) { // log.Error("Error in parsing options"); return; } else { bool storeConf = false; for (int i = 0; i < args.Length; i += 2) { if (args[i] == "--udpPort" || args[i] == "-u") { p.ConfOptions["udpPort"] = args[i + 1]; } else if (args[i] == "--kadPort" || args[i] == "-k") { p.ConfOptions["kadPort"] = args[i + 1]; } else if ((args[i] == "--store" || args[i] == "-s") && (args[i + 1] == "1")) { storeConf = true; } else if ((args[i] == "--with_interface" || args[i] == "-i") && (args[i + 1] == "1")) { withoutInterface = false; } } if (storeConf) { p.Configure(p.ConfOptions["udpPort"], p.ConfOptions["kadPort"]); } } p.RunLayers(withoutInterface); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate Host"); Console.ReadLine(); } }
/// <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); } }