Example #1
0
        static void StartDownload(ClientEngine clientEngine, TorrentSettings torrentDefaultSettings)
        {
            string baseDir = Path.Combine(Path.Combine(
                                              Environment.GetFolderPath(Environment.SpecialFolder.Personal), "var"),
                                          "MonoTorrent");

            Debug.WriteLine(string.Format("Base Dir is {0}", baseDir));

            var torrent = Torrent.Load(Path.Combine(baseDir, TorrentFileName));

            (torrent.Files[0] as TorrentFile).Priority = Priority.Highest;
            (torrent.Files[1] as TorrentFile).Priority = Priority.DoNotDownload;
            (torrent.Files[2] as TorrentFile).Priority = Priority.DoNotDownload;
            long   targetDownloadSize = (torrent.Files[0] as TorrentFile).Length;
            long   totalSize          = torrent.Size;
            double targetPercentage   = (double)targetDownloadSize / totalSize;

            Debug.WriteLine(string.Format("Intend to download {0}/{1} = {2}",
                                          targetDownloadSize, totalSize, targetPercentage));

            var torrentManager  = new TorrentManager(torrent, Path.Combine(baseDir, "Downloads"), torrentDefaultSettings);
            var progressMonitor = new PartialDownloadProgressMonitor(torrentManager);

            progressMonitor.FileDownloaded += new EventHandler <FileDownloadedEventArgs>(progressMonitor_FileDownloaded);

            clientEngine.Register(torrentManager);

            torrentManager.TorrentStateChanged += new EventHandler <TorrentStateChangedEventArgs>(torrentManager_TorrentStateChanged);
            // Start downloading
            torrentManager.Start();

            // Keep running while the torrent isn't stopped or paused.
            while (torrentManager.State != TorrentState.Stopped &&
                   torrentManager.State != TorrentState.Paused)
            {
                Debug.WriteLine(string.Format("Progress: {0}", torrentManager.Progress));
                System.Threading.Thread.Sleep(2000);
            }

            Console.Read();
        }
Example #2
0
        static void StartDownload(ClientEngine clientEngine, TorrentSettings torrentDefaultSettings)
        {
            string baseDir = Path.Combine(Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder.Personal), "var"),
            "MonoTorrent");
              Debug.WriteLine(string.Format("Base Dir is {0}", baseDir));

              var torrent = Torrent.Load(Path.Combine(baseDir, TorrentFileName));
              (torrent.Files[0] as TorrentFile).Priority = Priority.Highest;
              (torrent.Files[1] as TorrentFile).Priority = Priority.DoNotDownload;
              (torrent.Files[2] as TorrentFile).Priority = Priority.DoNotDownload;
              long targetDownloadSize = (torrent.Files[0] as TorrentFile).Length;
              long totalSize = torrent.Size;
              double targetPercentage = (double)targetDownloadSize / totalSize;
              Debug.WriteLine(string.Format("Intend to download {0}/{1} = {2}",
            targetDownloadSize, totalSize, targetPercentage));

              var torrentManager = new TorrentManager(torrent, Path.Combine(baseDir, "Downloads"), torrentDefaultSettings);
              var progressMonitor = new PartialDownloadProgressMonitor(torrentManager);
              progressMonitor.FileDownloaded += new EventHandler<FileDownloadedEventArgs>(progressMonitor_FileDownloaded);

              clientEngine.Register(torrentManager);

              torrentManager.TorrentStateChanged += new EventHandler<TorrentStateChangedEventArgs>(torrentManager_TorrentStateChanged);
              // Start downloading
              torrentManager.Start();

              // Keep running while the torrent isn't stopped or paused.
              while (torrentManager.State != TorrentState.Stopped &&
            torrentManager.State != TorrentState.Paused) {
            Debug.WriteLine(string.Format("Progress: {0}", torrentManager.Progress));
            System.Threading.Thread.Sleep(2000);
              }

              Console.Read();
        }