/// <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); } }
/// <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); } }
/// <summary> /// Sets Data Context for this Control /// </summary> /// <param name="model">Model to be set</param> public void SetDataContext(SearchListModel model) { vm = model; this.DataContext = vm; }