public MoveManagerService(IConfiguration configuration, DownloadSettings settings) { var optionsBuilder = new DbContextOptionsBuilder <DownloadContext>(); string datapath = Path.Combine(settings.DownloadFolder, "database.db"); optionsBuilder.UseSqlite("Data Source=" + datapath); _context = new DownloadContext(optionsBuilder.Options); _settings = DownloadSettings.Load(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <DownloadContext>(); services.AddSingleton(DownloadSettings.Load()); services.AddSingleton <AccountHelper>(); services.AddSingleton <IHostedService, DownloadManagerService>(); services.AddSingleton <IHostedService, AccountManagerService>(); services.AddSingleton <IHostedService, ExtractManagerService>(); services.AddSingleton <IHostedService, MoveManagerService>(); services.AddControllersWithViews(); }
public SettingsController(DownloadContext context) { _context = context; _settings = DownloadSettings.Load();; }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { CheckQuery(stoppingToken); while (!stoppingToken.IsCancellationRequested) { await Task.Delay(TimeSpan.FromSeconds(_settings.IntervalDownload), stoppingToken); if (stoppingToken.IsCancellationRequested) { break; } if (_isDownloading) { continue; } _isDownloading = true; List <DownloadGroup> groups = new List <DownloadGroup>(); try { _settings = DownloadSettings.Load(); groups = _context.Groups.Where(g => g.IsTemp == false).ToList(); } catch (Exception e) { Log("Load Error: " + e.Message); } bool flagDownload = false; foreach (DownloadGroup group in groups) { if (!_context.Items.Any(i => i.DownloadGroupID == group.ID && i.State == DownloadItem.States.Waiting)) { Log("No Items in " + group.Name); continue; } Log("Checked Group found item: " + group.Name); IEnumerable <DownloadItem> _items = _context.Items.Where(i => i.DownloadGroupID == group.ID && i.State == DownloadItem.States.Waiting).OrderBy(i => i.Name); foreach (DownloadItem _item in _items) { IDownloader downloader = DownloadHelper.GetDownloader(_item); if (downloader == null) { Log("Download Interface Error - " + _item.ID.ToString() + " - " + _item.Hoster); _item.State = DownloadItem.States.Error; queryUpdate.Add(_item); queryAdd.Add(new DownloadError(1, _item, new Exception("No DownloadInterface for " + _item.Hoster))); await SocketHandler.Instance.SendIDError(_item); continue; } if (downloader.IsFree) { flagDownload = true; StartDownload(group, _item, new AccountProfile(new AccountModel())); break; } else { AccountProfile profile = await _account.GetFreeProfile(_item); if (profile != null) { flagDownload = true; StartDownload(group, _item, profile); break; } else { Log("No Account for hoster: " + downloader.Identifier); _item.State = DownloadItem.States.Error; queryUpdate.Add(_item); queryAdd.Add(new DownloadError(2, _item, new Exception("No Account for " + downloader.Identifier))); await SocketHandler.Instance.SendIDError(_item); continue; } } } if (flagDownload) { break; } } if (!flagDownload) { _isDownloading = false; } } }