Exemplo n.º 1
0
        public void AddTorrent(string pathToTorrentFile)
        {
            Messenger.Default.Send(new AddTorrentShowDialog((dialogResult) =>
            {
                if (dialogResult == true)
                {
                    ViewModelLocator locator = new ViewModelLocator();
                    var addTorrentViewModel  = locator.AddTorrent;

                    TorrentManager manager = new TorrentManager(addTorrentViewModel.Torrent, addTorrentViewModel.PathToFolder, tSettings);
                    if (!engine.Contains(manager.InfoHash))
                    {
                        saveLoadManager.Add(manager);

                        engine.Register(manager);

                        manager.Start();

                        TorrentManagerWrapper wrapper = new TorrentManagerWrapper(manager);

                        Torrents.Add(wrapper);
                    }
                }
            }, pathToTorrentFile));
        }
Exemplo n.º 2
0
        public void OnTorrentAdded(object sender, TorrentActionEventArgs args)
        {
            Torrent torrent = bitTorrentManager.GetTorrent(args.Handle);

            // Marshall the collection call back to the window thread, torrent will be captured
            Action dispatchAction = () => Torrents.Add(torrent);

            this.currentDispatcher.BeginInvoke(dispatchAction);
        }
Exemplo n.º 3
0
        public PeriodicTorrent AddTorrent(TorrentWrapper torrent, bool startImmediately)
        {
            // Apply settings
            torrent.Settings.UseDht           = SettingsManager.EnableDHT;
            torrent.Settings.MaxConnections   = SettingsManager.MaxConnectionsPerTorrent;
            torrent.Settings.MaxDownloadSpeed = SettingsManager.MaxDownloadSpeed;
            torrent.Settings.MaxUploadSpeed   = SettingsManager.MaxUploadSpeed;
            torrent.Settings.UploadSlots      = SettingsManager.UploadSlotsPerTorrent;
            var periodicTorrent = new PeriodicTorrent(torrent);

            Task.Factory.StartNew(() =>
            {
                Client.Register(torrent);
                if (startImmediately)
                {
                    torrent.Start();
                }
            });
            Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Add(periodicTorrent)));
            return(periodicTorrent);
        }
Exemplo n.º 4
0
        void uTorrent_ListRefreshedEvent(ListRefreshedEventArgs ev)
        {
            if (ev.Torrents.Count != Torrents.Count)
            {
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                {
                    Torrents.Clear();
                    ViewTorrents.Refresh();
                });
            }

            long dSpeed = 0, uSpeed = 0;

            // new or updated torrents
            foreach (Torrent tor in ev.Torrents)
            {
                dSpeed += tor.DownloadSpeed;
                uSpeed += tor.UploadSpeed;

                //logger.Trace(tor.ToString());

                bool foundTorrent = false;
                foreach (Torrent torExisting in Torrents)
                {
                    if (tor.Hash == torExisting.Hash)
                    {
                        foundTorrent = true;

                        // update details
                        torExisting.Availability      = tor.Availability;
                        torExisting.Downloaded        = tor.Downloaded;
                        torExisting.DownloadSpeed     = tor.DownloadSpeed;
                        torExisting.ETA               = tor.ETA;
                        torExisting.Label             = tor.Label;
                        torExisting.Name              = tor.Name;
                        torExisting.PeersConnected    = tor.PeersConnected;
                        torExisting.PeersInSwarm      = tor.PeersInSwarm;
                        torExisting.PercentProgress   = tor.PercentProgress;
                        torExisting.Ratio             = tor.Ratio;
                        torExisting.Remaining         = tor.Remaining;
                        torExisting.SeedsConnected    = tor.SeedsConnected;
                        torExisting.SeedsInSwarm      = tor.SeedsInSwarm;
                        torExisting.Size              = tor.Size;
                        torExisting.Status            = tor.Status;
                        torExisting.TorrentQueueOrder = tor.TorrentQueueOrder;
                        torExisting.Uploaded          = tor.Uploaded;
                        torExisting.UploadSpeed       = tor.UploadSpeed;

                        break;
                    }
                }

                if (!foundTorrent)
                {
                    System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
                    {
                        Torrents.Add(tor);
                    });
                }
            }

            DownloadSpeedSummaryFormatted = Utils.FormatByteSize((long)dSpeed) + "/sec";
            UploadSpeedSummaryFormatted   = Utils.FormatByteSize((long)uSpeed) + "/sec";

            System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate()
            {
                ViewTorrents.Refresh();
            });
        }