Inheritance: IDisposable, IPeer
Exemplo n.º 1
0
 /// <summary>
 /// Constructor that initializes the commands and the local reference to the peer
 /// </summary>
 /// <param name="peer">Peer that will be used to get information from the network</param>
 public SearchListModel(Peer peer=null)
 {
     this.peer = peer;
     Query = "";
     Search = new AlwaysExecuteCommand(searchFn);
     RaiseStartStream = new AlwaysExecuteCommand(startStream);
 }
Exemplo n.º 2
0
 //    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();
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor that initializes all commands and the reference to the Peer.
 /// </summary>
 /// <param name="p"></param>
 public AudioPlayerModel(Peer p = null)
 {
     //player.Done += new PlayerEx.DoneEventHandler(player_Done);
        //player.SetVolume(200, 200);
     player.PlaybackStopped += new EventHandler(playback_stopped);
     this.peer = p;
     Play = new AlwaysExecuteCommand(play);
     Pause = new AlwaysExecuteCommand(pause);
     Stop = new AlwaysExecuteCommand(stop);
     Close = new AlwaysExecuteCommand(close);
     MaxVolume = 1.0F;
     Volume = 0.4F;
 }
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);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor that initializes the commands and the local reference to the peer
 /// </summary>
 /// <param name="p">Peer that will be used to get information</param>
 public LocalStoreModel(Peer p = null)
 {
     peer = p;
     RefreshList = new AlwaysExecuteCommand(refreshList);
     refreshList();
 }