Пример #1
0
        public void Load(string[] args)
        {
            _logger.Info("Loading BitTorrent session.");

            _sessionHandler.Load();

            _logger.Info("Loading plugins.");

            foreach (var plugin in _extensionFactory.GetAll <IPlugin>()
                     .Where(e => _extensionFactory.IsEnabled(e.GetId())))
            {
                plugin.Load();
                _plugins.Add(plugin);
            }

            _httpServer.Start();
        }
        protected override async Task Execute(CancellationToken token)
        {
            log.LogInformation("Starting...");
            var location    = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
            var sessionFile = Path.Combine(location, $"{config.User}.session.dat");

            session.Load(sessionFile);
            api.Delay.Disable();
            if (!api.IsUserAuthenticated)
            {
                var logInResult = await api.LoginAsync().ConfigureAwait(false);

                if (!logInResult.Succeeded)
                {
                    log.LogError("Authentication failed: [{0}]", logInResult.Info.Message);
                    return;
                }

                session.Save(sessionFile);
            }
            else
            {
                log.LogInformation("User is already authenticated");
            }

            api.Delay.Enable();
            var currentUser = await api.GetCurrentUserAsync().ConfigureAwait(false);

            if (!currentUser.Succeeded)
            {
                log.LogError("Failed to retrieve user: {0}", currentUser.Info.Message);
                return;
            }

            log.LogInformation("Started for user: {0}...", currentUser.Value.FullName);
            await Internal(currentUser.Value, token).ConfigureAwait(false);

            session.Save(sessionFile);
            log.LogInformation("Completed");
        }