예제 #1
0
        public void Initialize()
        {
            Settings.Logger.Inizialize();
            Settings.User.readFromFile();

            // web server
            if (Settings.User.StartWebOnAppLoad)
            {
                startWeb();
            }

            if (File.Exists(".session_state"))
            {
                var data = File.ReadAllBytes(".session_state");
                using (var entry = Core.Util.lazy_bdecode(data))
                {
                    _torrentSession.load_state(entry);
                }
            }

            // http://www.libtorrent.org/reference-Alerts.html
            Alert2Func[typeof(Core.torrent_added_alert)] = a => TorrentAddedAlert((Core.torrent_added_alert)a);
            Alert2Func[typeof(Core.state_update_alert)]  = a => OnTorrentUpdateAlert((Core.state_update_alert)a);
            //Alert2Func[typeof(Core.torrent_paused_alert)] = a => OnTorrentPausedAlert((Core.torrent_paused_alert)a);
            //Alert2Func[typeof(Core.torrent_resumed_alert)] = a => OnTorrentResumedAlert((Core.torrent_resumed_alert)a);
            //Alert2Func[typeof(Core.torrent_removed_alert)] = a => OnTorrentRemovedAlert((Core.torrent_removed_alert)a); // torrent removed from torrentSession, always ok
            //Alert2Func[typeof(Core.torrent_deleted_alert)] = a => OnTorrentDeletedAlert((Core.torrent_deleted_alert)a); // finished deleting file for removed torrent
            Alert2Func[typeof(Core.torrent_error_alert)] = a => OnTorrentErrorAlert((Core.torrent_error_alert)a);
            //Alert2Func[typeof(Core.stats_alert)] = a => OnStatsAlert((Core.stats_alert)a);
            Alert2Func[typeof(Core.dht_stats_alert)]     = a => OnDhtStatsAlert((Core.dht_stats_alert)a);
            Alert2Func[typeof(Core.dht_bootstrap_alert)] = a => OnDhtBootstrapAlert((Core.dht_bootstrap_alert)a);

            Alert2Func[typeof(Core.save_resume_data_alert)]        = a => OnSaveResumeDataAlert((Core.save_resume_data_alert)a);
            Alert2Func[typeof(Core.save_resume_data_failed_alert)] = a => OnSaveResumeDataFailedAlert((Core.save_resume_data_failed_alert)a);

            Alert2Func[typeof(Core.piece_finished_alert)] = a => OnPieceFinishedAlert((Core.piece_finished_alert)a);

            //_torrentSession.start_lsd();
            _torrentSession.start_natpmp();
            _torrentSession.start_upnp();

            DhtSettings dhts = _torrentSession.get_dht_settings();

            dhts.aggressive_lookups = true;
            _torrentSession.set_dht_settings(dhts);

            _torrentSession.start_dht();

            var alertMask = Core.AlertMask.error_notification
                            | Core.AlertMask.peer_notification
                            | Core.AlertMask.port_mapping_notification
                            | Core.AlertMask.storage_notification
                            | Core.AlertMask.tracker_notification
                            | Core.AlertMask.status_notification
                            | Core.AlertMask.ip_block_notification
                            | Core.AlertMask.progress_notification
                            | Core.AlertMask.stats_notification | Core.AlertMask.dht_notification
            ;

            _torrentSession.set_alert_mask(alertMask);
            _torrentSession.set_alert_callback(HandlePendingAlertCallback);
            _torrentSession.set_session_callback(HandleAlertCallback);



            _dispatcherTimer.Elapsed += new ElapsedEventHandler(dispatcherTimer_Tick);
            _dispatcherTimer.Interval = Settings.Application.DISPATCHER_INTERVAL;
            _dispatcherTimer.Start();

            _sessionStatusDispatcherTimer.Elapsed += new ElapsedEventHandler(sessionStatusDispatcher_Tick);
            _sessionStatusDispatcherTimer.Interval = 1000;
            _sessionStatusDispatcherTimer.Start();
        }