public void DownloadItemSerializationSaveTest()
        {
            var engine  = new DcEngine();
            var manager = new DownloadManager(engine);

            manager.Save("test.xml");
        }
Esempio n. 2
0
        public TransferManager(DcEngine engine)
        {
            ConnectionWaitTimeout     = 30;
            DownloadInactivityTimeout = 60;
            UploadInactivityTimeout   = 30;

            _engine = engine;
        }
Esempio n. 3
0
        public SearchManager(DcEngine engine)
        {
            _engine = engine;

            _engine.Hubs.HubAdded   += Hubs_HubAdded;
            _engine.Hubs.HubRemoved += Hubs_HubRemoved;

            _engine.ActiveStatusChanged += (sender, args) => _lastSearchAt = DateTime.Now.AddSeconds(-10);

            MinimumSearchInterval = 20;
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // DcEngine is the main thing we will work with
            // use EngineSettings structure to set various settings of the engine
            Engine = new DcEngine();

            // we need to have at least one hub connection to work with
            var hubSettings = new HubSettings {
                HubAddress = "_write_your_hub_address_here_",
                HubName    = "My hub",
                Nickname   = "sharpdc"
            };

            var hubConnection = new HubConnection(hubSettings);

            // we want to see the hub connection status changes for debug puropses
            hubConnection.ConnectionStatusChanged += (sender, e) => Console.WriteLine("Hub " + e.Status);

            // add this connection to the engine
            Engine.Hubs.Add(hubConnection);

            // this event will be called when at least one hub will be connected and logged in
            Engine.ActiveStatusChanged += delegate {
                // to download a file we need to have a magnet-link
                var magnet = new Magnet("magnet:?xt=urn:tree:tiger:3UOKTPAQUGWGKWFIL75ZDMTTQLWF5AM2BAXBVEA&xl=63636810&dn=TiX_1_zvukovoy_barrier.avi");

                Console.WriteLine("Downloading the " + magnet.FileName);

                // the file will be saved in the current folder by default
                // you can provide custom file name:
                // engine.DownloadFile(magnet, "C:\\Temp\\my_name.avi");

                Engine.DownloadFile(magnet);
            };

            // we want to know when we have download complete
            Engine.DownloadManager.DownloadCompleted += (sender, e) => Console.WriteLine("Download is complete! Press enter to exit.");

            Console.WriteLine("Welcome to the sharpdc example");
            Console.WriteLine("We try to download a file");
            Console.WriteLine("Press enter to exit");

            // the engine to work needs Update() method to be called periodically
            // we can call it manually or use built-in method StartAsync()
            // that will use System.Threading.Timer to call Update() with 200 msec interval
            Engine.StartAsync();

            // would be cool to see download progress if any
            // so we call DisplayDownloadInfo method in other thread
            new ThreadStart(DisplayDownloadInfo).BeginInvoke(null, null);

            Console.ReadLine();
        }
Esempio n. 5
0
        public StatisticsManager(DcEngine engine, bool decayRates = true)
        {
            _engine = engine;
            engine.TransferManager.TransferAdded   += TransferManager_TransferAdded;
            engine.TransferManager.TransferRemoved += TransferManager_TransferRemoved;

            if (decayRates)
            {
                var updateInterval = TimeSpan.FromHours(12);
                _updateTimer = new Timer(PeriodicAction, null, updateInterval, updateInterval);
            }
        }
Esempio n. 6
0
        public void Initialize()
        {
            var settings = EngineSettings.Default;

            settings.ActiveMode       = Settings.ActiveMode;
            settings.UseSparseFiles   = true;
            settings.AutoSelectPort   = true;
            settings.ReconnectTimeout = 45;

            if (Settings.TCPPort != 0)
            {
                settings.TcpPort = Settings.TCPPort;
            }

            if (Settings.UDPPort != 0)
            {
                settings.UdpPort = Settings.UDPPort;
            }

            _engine = new DcEngine(settings);
            _engine.TagInfo.Version = "livedc";

            _hubManager = new DcHubManager(this, _client);

            if (File.Exists(SharePath))
            {
                try
                {
                    _engine.Share = MemoryShare.CreateFromXml(SharePath);
                    _engine.Share.Reload();
                }
                catch (Exception x)
                {
                    logger.Error("Unable to load share from {0} because {1}", SharePath, x.Message);
                }
            }

            if (_engine.Share == null)
            {
                _engine.Share = new MemoryShare();
            }

            if (Settings.StorageAutoSelect)
            {
                _engine.Settings.PathDownload = StorageHelper.GetBestSaveDirectory();
            }
            else
            {
                _engine.Settings.PathDownload = Settings.StoragePath;
            }

            if (File.Exists(IncompletePath))
            {
                try
                {
                    _engine.DownloadManager.Load(IncompletePath);
                }
                catch (Exception x)
                {
                    logger.Error("Unable to load downloads {0}", x.Message);
                }
            }

            Settings.Nickname = "livedc" + Guid.NewGuid().ToString().GetMd5Hash().Substring(0, 8);

            _engine.ActiveStatusChanged += delegate { OnStatusChanged(); };

            _engine.StartAsync();
            _engine.Connect();

            if (!string.IsNullOrEmpty(Settings.PortCheckUrl))
            {
                LiveApi.PortCheckUri = Settings.PortCheckUrl;
            }

            ThreadPool.QueueUserWorkItem(o => AutoConfiguration());
        }
Esempio n. 7
0
 public DownloadManager(DcEngine engine)
 {
     _engine = engine;
 }
Esempio n. 8
0
 public UploadCacheManager(DcEngine engine)
 {
     _engine          = engine;
     CacheUseSpeed    = new SpeedAverage();
     CacheReadAverage = new MovingAverage(TimeSpan.FromSeconds(10));
 }