public async Task MoveOther(List <DownloadItem> _items, DownloadGroup _group) { string pathFrom = System.IO.Path.Combine(_settings.DownloadFolder, _group.Name, "extracted", _items[0].GroupID.ToString()); string[] files = Directory.GetFiles(pathFrom); string pathTo = Path.Combine(_settings.MoveFolder, "Other"); if (!Directory.Exists(pathTo)) { Directory.CreateDirectory(pathTo); } foreach (string file in files) { string fileTo = Path.Combine(pathTo, Path.GetFileName(file)); if (File.Exists(fileTo)) { File.Delete(fileTo); } File.Move(file, fileTo); } await SocketHandler.Instance.SendIDFinish(_items[0]); foreach (DownloadItem item in _items) { item.State = DownloadItem.States.Finished; } _context.Items.UpdateRange(_items); _context.SaveChanges(); _isMoving = false; }
public ActionResult Delete() { int id = int.Parse(Request.Form["id"]); Download download = downloadContext.downloadLists.Find(id); downloadContext.downloadLists.Remove(download); downloadContext.SaveChanges(); return(Content("删除成功")); }
public IActionResult AccountCreate(AccountModel acc) { Downloader.IDownloader downloader = DownloadHelper.GetDownloader(acc.Hoster); if (downloader.IsFree) { acc.IsPremium = true; } _context.Accounts.Add(acc); _context.SaveChanges(); return(RedirectToAction("Accounts")); }
public async Task CheckAccount(AccountModel account) { //Console.WriteLine("Checke Account " + account.Name); AccountProfile profile = await _account.GetProfile(account); IDownloader downloader = DownloadHelper.GetDownloader(profile); if (downloader == null) { Console.WriteLine("No downloader for profile"); return; } AccountModel model = null; try { model = await downloader.GetAccountInfo(profile); } catch (Exception ex) { Console.WriteLine("Fehler beim holen der Accountinfos"); Console.WriteLine(ex.Message); } if (model == null) { return; } _context.Accounts.Update(model); _context.SaveChanges(); try { _context.SaveChanges(); } catch { } await SocketHandler.Instance.SendAITrafficDay(model); }
static void ExcelReader() { TimeZoneInfo Pacific_Standard_Time = TimeZoneInfo.FindSystemTimeZoneById(timeZone); DateTime dateTime_Pacific = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, Pacific_Standard_Time); var dateString = dateTime_Pacific.ToString("yyyyMMdd"); DirectoryInfo dir = new DirectoryInfo(filePath); string partialName = $"{fileName}-{dateString}"; FileInfo[] file = dir.GetFiles(partialName + "*.csv", SearchOption.TopDirectoryOnly).OrderByDescending(p => p.CreationTimeUtc).ToArray(); if (file == null || file.Length <= 0) { } System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); FileStream stream = File.Open(file[0].FullName, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateCsvReader(stream); ExcelDataSetConfiguration excelDataSetConfiguration = new ExcelDataSetConfiguration { ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true } }; var dataSet = excelReader.AsDataSet(excelDataSetConfiguration); var dataTable = dataSet.Tables[0]; IMapper mapper = config.CreateMapper(); List <DataRow> rows = new List <DataRow>(dataTable.Rows.OfType <DataRow>()); List <DATRateData> result = mapper.Map <List <DataRow>, List <DATRateData> >(rows); using (var context = new DownloadContext()) { context.DatRatesData.AddRange(result); context.SaveChanges(); } excelReader.Close(); }
public IActionResult Reset(int id) { DownloadItem item = _context.Items.Single(i => i.ID == id); DownloadGroup group = _context.Groups.Single(g => g.ID == item.DownloadGroupID); string filePath = System.IO.Path.Combine(_settings.DownloadFolder, group.Name, "files", item.Name); try { System.IO.File.Delete(filePath); } catch { } SocketHandler.Instance.SendIDReset(item); item.State = DownloadItem.States.Waiting; _context.Update(item); _context.SaveChanges(); return(RedirectToAction("Show", "Downloads", new { id = group.ID })); }
public IActionResult Edit(DownloadGroup group) { _context.Groups.Update(group); _context.SaveChanges(); return(RedirectToAction("Show", new { id = group.ID })); }
public async void CheckQuery(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { await Task.Delay(5000); if (queryUpdate.Count == 0 && queryAdd.Count == 0) { continue; } object[] temp; if (queryUpdate.Count > 0) { temp = new object[queryUpdate.Count + 10]; queryUpdate.CopyTo(temp); queryUpdate.Clear(); foreach (object obj in temp) { if (obj != null) { _context.Update(obj); } } } if (queryAdd.Count > 0) { temp = new object[queryAdd.Count + 10]; queryAdd.CopyTo(temp); queryAdd.Clear(); foreach (object obj in temp) { if (obj != null) { _context.Add(obj); } } } int x = 0; while (true) { try { _context.SaveChanges(); break; } catch { } x++; if (x >= 10) { Log("Query Too many tries"); break; } await Task.Delay(500); } } }