コード例 #1
0
 public BitTorrentService(BitTorrentManager manager,
                          PieceLevelTorrentManager pieceLevelManager)
 {
     _manager           = manager;
     _pieceLevelManager = pieceLevelManager;
     _cacheRegistry     = _manager.CacheRegistry;
 }
コード例 #2
0
        public static void SetupTorrentWatcher(BitTorrentManager manager, 
            string torrentsDir)
        {
            TorrentFolderWatcher watcher =
            new TorrentFolderWatcher(torrentsDir, "*.torrent");
              watcher.TorrentFound += delegate(object sender, TorrentWatcherEventArgs e) {
            try {
              // This is a hack to work around the issue where a file triggers the event
              // before it has finished copying. As the filesystem still has an exclusive lock
              // on the file, monotorrent can't access the file and throws an exception.
              // The best way to handle this depends on the actual application.
              // Generally the solution is: Wait a few hundred milliseconds
              // then try load the file.
              System.Threading.Thread.Sleep(500);

              Torrent t = Torrent.Load(e.TorrentPath);
              Logger.WriteLineIf(LogLevel.Verbose, _log_props,
            string.Format("Torrent file {1} at {0} loaded", e.TorrentPath, t.Name));

              manager.AddTorrentToTracker(t);
            } catch (Exception ex) {
              Logger.WriteLineIf(LogLevel.Error, _log_props,
            string.Format("Error loading torrent from disk: {0}", ex.ToString()));
            }
              };

              watcher.Start();
              // We have two levels in the torrents directory.
              // The FileSystemWatcher is instantiated in Start().
              watcher.FileSystemWatcher.IncludeSubdirectories = true;
              watcher.ForceScan();
        }
コード例 #3
0
ファイル: BitTorrentService.cs プロジェクト: xujyan/hurricane
 public BitTorrentService(BitTorrentManager manager, 
     PieceLevelTorrentManager pieceLevelManager)
 {
     _manager = manager;
       _pieceLevelManager = pieceLevelManager;
       _cacheRegistry = _manager.CacheRegistry;
 }
コード例 #4
0
        public static void SetupTorrentWatcher(BitTorrentManager manager,
                                               string torrentsDir)
        {
            TorrentFolderWatcher watcher =
                new TorrentFolderWatcher(torrentsDir, "*.torrent");

            watcher.TorrentFound += delegate(object sender, TorrentWatcherEventArgs e) {
                try {
                    // This is a hack to work around the issue where a file triggers the event
                    // before it has finished copying. As the filesystem still has an exclusive lock
                    // on the file, monotorrent can't access the file and throws an exception.
                    // The best way to handle this depends on the actual application.
                    // Generally the solution is: Wait a few hundred milliseconds
                    // then try load the file.
                    System.Threading.Thread.Sleep(500);

                    Torrent t = Torrent.Load(e.TorrentPath);
                    Logger.WriteLineIf(LogLevel.Verbose, _log_props,
                                       string.Format("Torrent file {1} at {0} loaded", e.TorrentPath, t.Name));

                    manager.AddTorrentToTracker(t);
                } catch (Exception ex) {
                    Logger.WriteLineIf(LogLevel.Error, _log_props,
                                       string.Format("Error loading torrent from disk: {0}", ex.ToString()));
                }
            };

            watcher.Start();
            // We have two levels in the torrents directory.
            // The FileSystemWatcher is instantiated in Start().
            watcher.FileSystemWatcher.IncludeSubdirectories = true;
            watcher.ForceScan();
        }
コード例 #5
0
 public PieceLevelTorrentManager(BitTorrentManager manager, BitTorrentCache bittorrentCache,
     DictionaryServiceProxy dhtProxy, TorrentHelper torrentHelper, int pieceInfoServerPort)
 {
     _manager = manager;
       _dhtProxy = dhtProxy;
       _bittorrentCache = bittorrentCache;
       _torrentHelper = torrentHelper;
       _pieceInfoServerPort = pieceInfoServerPort;
       _pieceInfoServer = new HttpPieceInfoServer(_pieceInfoServerPort, this);
 }
コード例 #6
0
 public PieceLevelTorrentManager(BitTorrentManager manager, BitTorrentCache bittorrentCache,
                                 DictionaryServiceProxy dhtProxy, TorrentHelper torrentHelper, int pieceInfoServerPort)
 {
     _manager             = manager;
     _dhtProxy            = dhtProxy;
     _bittorrentCache     = bittorrentCache;
     _torrentHelper       = torrentHelper;
     _pieceInfoServerPort = pieceInfoServerPort;
     _pieceInfoServer     = new HttpPieceInfoServer(_pieceInfoServerPort, this);
 }