public FileResult DownloadDocument(int EquipmentId, int DocumentId) { var data = _equipmentService.GetEquiipmentInfoById(EquipmentId); var document = data.EquipmentDocuments.Where(a => a.Id == DocumentId).FirstOrDefault(); string filePath = _hostingEnvironment.WebRootPath + "\\EquipmentDocuments\\" + document.Document; string fileName = document.Document; //filePath = $"{this.Request.Host}"; byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); //16/09/19 aakansha var model = new DownloadHistory(); model.DownloadDateTime = DateTime.UtcNow; model.DocumentName = Path.GetFileName(filePath); model.DocumentPath = filePath; model.DocumentFormat = Path.GetExtension(filePath); model.DocumentType = "EquipmentDocuments"; model.ProcessTypeId = (int)ProcessType.Download; model.UserId = _workContext.CurrentCustomer.Id; _companyProfileService.InsertDownloadHistory(model); return(File(fileBytes, "application/force-download", fileName)); }
void downloadInfo() { try { IsBusy = true; string rssXml = tryDownloadRss(); rssXml = cacheManager(rssXml); if (string.IsNullOrWhiteSpace(rssXml)) { IsBusy = false; return; } VersionsInfoData.Clear(); VersionsInfoData = DownloadHistory.ParseInfo(rssXml); } catch (Exception ex) { ExceptionLogger.LogExceptionToFile(ex); LogWindow.AddMessage(LogType.Error, ex.Message); } finally { IsBusy = false; } }
private static bool NewDatasetAvailable(DownloadHistory downloadHistory, DatasetFile datasetFromFeed, DirectoryInfo downloadDirectory) { Console.WriteLine(datasetFromFeed.DatasetUrl); if (string.IsNullOrEmpty(datasetFromFeed.LastUpdated)) { return(true); } if (downloadHistory == null) { Console.WriteLine("Download history is null, NewDatasetAvailable"); return(true); } if (!LocalFileExists(downloadHistory, downloadDirectory, datasetFromFeed)) { Console.WriteLine("LocalFile does not exist, NewDatasetAvailable"); return(true); } var originalDatasetLastUpdated = DateTime.Parse(downloadHistory.LastUpdated, System.Globalization.CultureInfo.InvariantCulture); var datasetFromFeedLastUpdated = DateTime.Parse(datasetFromFeed.LastUpdated, System.Globalization.CultureInfo.InvariantCulture); Console.WriteLine($"originalDatasetLastUpdated = {originalDatasetLastUpdated} , datasetFromFeedLastUpdated = {datasetFromFeedLastUpdated}"); var updatedDatasetAvailable = originalDatasetLastUpdated < datasetFromFeedLastUpdated; if (updatedDatasetAvailable) { Console.WriteLine($"updatedDatasetAvailable = {updatedDatasetAvailable}"); } return(updatedDatasetAvailable); }
/// <summary> /// Removes a record from the database /// </summary> /// <param name="record">the record you want to remove</param> public static void RemoveRecord(DownloadHistory historyRecord) { if (historyRecord != null && DLHistory.GetHistoryEntryById(historyRecord.Id) != null) { DLHistory.RemoveRecord(historyRecord); } }
/// <summary> /// Insert a record into the database /// </summary> /// <param name="record">The record</param> public static void InsertRecord(DownloadHistory historyRecord) { if (historyRecord != null && DLHistory.GetHistory().Where(v => v.VideoId == historyRecord.VideoId).ToList().Count <= 0) { DLHistory.InsertRecord(historyRecord); } }
public DownloadItem(DownloadHistory history) { //When a new instance of DownloadItem is created with this constructor, it is being used to show it as history. There will not be a download button InitializeComponent(); isHistory = true; historyRecord = history; new Thread(async() => { try { //Because for some reason assigning 5 to a property that already is 5 makes it work. ? It doesn't show the elipse radius without this. bunifuElipse1.ElipseRadius = 5; pbYoutubeThumbnail.Load(history.ThumbnailLink); theVideo = await client.GetVideoAsync(history.VideoId); } catch { } }).Start(); lblStatus.Location = pbLoad.Location; lblStatus.Text = history.DownloadDate; btnDownload.Enabled = true; pbLoad.Visible = false; lblExit.Enabled = true; string completeString = ""; string subAuthor = ""; string subTitle = ""; if (history.Title.Length > 33) { subTitle = history.Title.Substring(0, 33) + "..."; completeString += subTitle + " "; } else { completeString += history.Title + " "; } if (history.ChannelTitle.Length > 23) { subAuthor = history.ChannelTitle.Substring(0, 23) + "..."; completeString += subAuthor + " "; } else { completeString += history.ChannelTitle + " "; } completeString += history.Duration; lblTitle.Text = completeString; }
public IActionResult UploadDocument() { var formData = this.Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString()); String[] EqpDocumentIds = formData["EqpDocumentId"].Split(","); String[] EquipmentIds = formData["EquipmentId"].Split(","); var data = _equipmentService.GetEquiipmentInfoById(Convert.ToInt32(EquipmentIds[0])); // Checking no of files injected in Request object if (Request.Form.Files.Count > 0) { var documentFile = Request.Form.Files[0]; try { if (documentFile != null) { string saveFilePath = _hostingEnvironment.WebRootPath + "\\EquipmentDocuments"; var filePath = Path.Combine(saveFilePath, documentFile.FileName); using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write)) { documentFile.CopyToAsync(fileStream); } data.EquipmentDocuments.Add(new EquipmentDocuments() { Document = documentFile.FileName, EqpDocumentId = Convert.ToInt32(EqpDocumentIds[0]) }); _equipmentService.Updateequipment(data); //16/09/19 aakansha var model = new DownloadHistory(); model.DownloadDateTime = DateTime.UtcNow; model.DocumentName = Path.GetFileName(filePath); model.DocumentPath = filePath; model.DocumentFormat = Path.GetExtension(filePath); model.DocumentType = "EquipmentDocuments"; model.ProcessTypeId = (int)ProcessType.Upload; model.UserId = _workContext.CurrentCustomer.Id; _companyProfileService.InsertDownloadHistory(model); return(Json(data.Id)); } } catch (Exception ex) { return(Json(data.Id)); } } else { return(Json(data.Id)); } return(Json(data.Id)); }
/// <summary> /// Removes a record from the database /// </summary> /// <param name="record">the record you want to remove</param> public static void RemoveRecord(DownloadHistory historyRecord) { using (Youtube2Mp3DatabaseEntities db = new Youtube2Mp3DatabaseEntities()) { db.DownloadHistory.Attach(historyRecord); db.DownloadHistory.Remove(historyRecord); SaveAndCloseDataBase(db); } }
public void InsertDownloadHistory(DownloadHistory DownloadHistory) { if (DownloadHistory == null) { throw new ArgumentNullException(nameof(DownloadHistory)); } _downloadHistoryRepository.Insert(DownloadHistory); }
private static bool LocalFileExists(DownloadHistory downloadHistory, DirectoryInfo downloadDirectory, DatasetFile dataset) { if (downloadHistory.FilePath != null) { var filePath = new FileInfo(Path.Combine(downloadDirectory.FullName, downloadHistory.FilePath)); return(filePath.Exists); } else { return(LocalFileExists(downloadDirectory, dataset)); } }
/// <summary> /// Insert a record into the database /// </summary> /// <param name="record">The record</param> public static void InsertRecord(DownloadHistory historyRecord) { using (Youtube2Mp3DatabaseEntities db = new Youtube2Mp3DatabaseEntities()) { if (db.DownloadHistory.Count() > 0) { historyRecord.Id = db.DownloadHistory.Max(i => i.Id) + 1; } else { historyRecord.Id = 0; } db.DownloadHistory.Add(historyRecord); SaveAndCloseDataBase(db); } }
private static bool NewDatasetAvailable(DownloadHistory downloadHistory, DatasetFile datasetFromFeed, DirectoryInfo downloadDirectory) { if (downloadHistory == null) { return(true); } if (!LocalFileExists(downloadHistory, downloadDirectory, datasetFromFeed)) { return(true); } var originalDatasetLastUpdated = DateTime.Parse(downloadHistory.Downloaded); var datasetFromFeedLastUpdated = DateTime.Parse(datasetFromFeed.LastUpdated); var updatedDatasetAvailable = originalDatasetLastUpdated < datasetFromFeedLastUpdated; return(updatedDatasetAvailable); }
protected void lnkDownload_Click(object sender, EventArgs e) { if (Session["userId"] != null) { try { var DownloadsObj = new DownloadHistory { Email = Session["Email"].ToString(), Id = User.Identity.GetUserId(), DateCreated = DateTime.Now, }; _db.DownloadHistories.Add(DownloadsObj); _db.SaveChanges(); } catch { } } }
private static void DownloadItems(qbtService service, IEnumerable <SyndicationItem> items) { Utils.Log("Processing {0} RSS feed items.", items.Count()); DownloadHistory history = new DownloadHistory(); history.ReadHistory(); foreach (SyndicationItem item in items) { string subject = item.Title.Text; var link = item.Links.FirstOrDefault(); if (link != null) { string torrentUrl = link.Uri.ToString(); if (history.Contains(torrentUrl)) { Utils.Log("Skipping item for {0} (downloaded already).", subject, torrentUrl); continue; } Utils.Log("Sending link for {0} ({1}) to QBT...", subject, torrentUrl); if (service.DownloadTorrent(torrentUrl, "freeleech")) { history.AddHistory(item); } else { Utils.Log("Error: torrent add failed."); } } } history.WriteHistory(); }
protected void btnAddCart_Click(object sender, EventArgs e) { try { if (isLogin) { if (isValidDownload) { DataTable file = FilesUploadService.FilesUpload_GetByTop("1", "ProductId='" + id + "'", ""); if (file.Rows.Count == 0) { WebMsgBox.Show("File này không còn tồn tại trong hệ thống!"); return; } DownloadHistory history = new DownloadHistory(); history.UserId = cus.Id; history.FileId = file.Rows[0]["Id"].ToString(); history.DownloadedDate = DateTime.Now.ToString("MM/dd/yyyy"); DownloadHistoryService.DownloadHistory_Insert(history); Response.Redirect(file.Rows[0]["WebContentLink"].ToString(), false); } else { WebMsgBox.Show("Bạn chỉ có thể tải miễn phí 2 lần/ngày"); } } else { Response.Redirect("/thanh-vien/dang-nhap", false); } } catch (Exception ex) { MailSender.SendMail("", "", "Error System", ex.Message + "\n" + ex.StackTrace); } }
public void RemoveHistory(DownloadHistory history) => histories.Remove(history);
private static async Task StartDownloadAsync() { DatasetService datasetService; if (userpath.Length > 1) { datasetService = new DatasetService(userpath); } else { datasetService = new DatasetService(); } List <DatasetFile> datasetToDownload = datasetService.GetSelectedFiles(); List <DatasetFile> updatedDatasetToDownload = new List <DatasetFile>(); DownloadLog downloadLog = new DownloadLog(); downloadLog.TotalDatasetsToDownload = datasetToDownload.Count; var appSettings = applicationService.GetAppSettings(); long totalSizeUpdatedFiles = 0; var downloader = new FileDownloader(); foreach (var localDataset in datasetToDownload) { var fileLog = new DatasetFileLog(localDataset); try { Console.WriteLine(localDataset.DatasetId + " - " + localDataset.Title); DirectoryInfo downloadDirectory = GetDownloadDirectory(appSettings, localDataset); DatasetFile datasetFromFeed = datasetService.GetDatasetFile(localDataset); DownloadHistory downloadHistory = datasetService.GetFileDownloaHistory(datasetFromFeed.Url); bool newDatasetAvailable = NewDatasetAvailable(downloadHistory, datasetFromFeed, downloadDirectory); if (newDatasetAvailable) { Console.WriteLine("Updated version of dataset is available."); } if (newDatasetAvailable) { Console.WriteLine("Starting download process."); downloader.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) => { fileLog.HumanReadableSize = HumanReadableBytes(totalFileSize.Value); totalSizeUpdatedFiles += totalFileSize.Value; Console.CursorLeft = 0; Console.Write($"{progressPercentage}% ({HumanReadableBytes(totalBytesDownloaded)}/{HumanReadableBytes(totalFileSize.Value)}) "); // add som extra whitespace to blank out previous updates }; var downloadRequest = new DownloadRequest(localDataset.Url, downloadDirectory, localDataset.IsRestricted()); localDataset.FilePath = await downloader.StartDownload(downloadRequest, appSettings); Console.WriteLine(); downloadLog.Updated.Add(fileLog); updatedDatasetToDownload.Add(localDataset); } else { fileLog.Message = "Not necessary to download dataset."; downloadLog.NotUpdated.Add(fileLog); Console.WriteLine("Not necessary to download dataset."); localDataset.FilePath = downloadHistory.FilePath; updatedDatasetToDownload.Add(localDataset); } } catch (Exception e) { updatedDatasetToDownload.Add(localDataset); fileLog.Message = "Error while downloading dataset: " + e.Message; downloadLog.Faild.Add(fileLog); Console.WriteLine("Error while downloading dataset: " + e.Message); } Console.WriteLine("-------------"); } downloadLog.TotalSizeOfDownloadedFiles = HumanReadableBytes(totalSizeUpdatedFiles); datasetService.WriteToDownloadLogFile(downloadLog); datasetService.WriteToDownloadFile(updatedDatasetToDownload); datasetService.WriteToDownloadHistoryFile(updatedDatasetToDownload); }
void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { DownloadHistory.Add(SearchRequest); DownloadSuccess?.Invoke(SearchRequest); }
public DownloadHistoryViewModel(DownloadHistory originalHistory) { this.OriginalHistory = originalHistory; _ = PrepareAsync(); }
public static bool DownloadHistory_Update(DownloadHistory data) { return(db.DownloadHistory_Update(data)); }
public static bool DownloadHistory_Insert(DownloadHistory data) { return(db.DownloadHistory_Insert(data)); }
private static async Task StartDownloadAsync(ConfigFile config) { var appSettings = ApplicationService.GetAppSettings(); var datasetService = new DatasetService(config); var updatedDatasetToDownload = new List <Download>(); var downloadLog = new DownloadLog(); var downloader = new FileDownloader(); var datasetToDownload = datasetService.GetSelectedFilesToDownload(); var downloadUsage = config.DownloadUsage; downloadLog.TotalDatasetsToDownload = datasetToDownload.Count; foreach (var localDataset in datasetToDownload) { var updatedDatasetFileToDownload = new List <DatasetFile>(); if (localDataset.Subscribe) { Log.Information("Subscribe to Dataset files"); var datasetFilesFromFeed = datasetService.GetDatasetFiles(localDataset); var filterDatasetFromFeed = datasetFilesFromFeed.Where(p => localDataset.Projections.Where(s => s.Selected == false).All(p2 => p2.Epsg != p.Projection)).ToList(); if (localDataset.AutoDeleteFiles) { Log.Debug("Delete files"); localDataset.Files = RemoveFiles(filterDatasetFromFeed, localDataset.Files, config); } if (localDataset.AutoAddFiles) { Log.Debug("Add new files"); localDataset.Files = AddFiles(filterDatasetFromFeed, localDataset.Files); } } foreach (var datasetFile in localDataset.Files) { var fileLog = new DatasetFileLog(datasetFile); try { Console.WriteLine(datasetFile.DatasetId + " - " + datasetFile.Title); DirectoryInfo downloadDirectory = GetDownloadDirectory(config, datasetFile); DatasetFile datasetFromFeed = datasetService.GetDatasetFile(datasetFile); DownloadHistory downloadHistory = datasetService.GetFileDownloaHistory(datasetFile.Url); bool newDatasetAvailable = NewDatasetAvailable(downloadHistory, datasetFromFeed, downloadDirectory); if (newDatasetAvailable) { Console.WriteLine("Updated version of dataset is available."); Console.WriteLine("Starting download process."); downloader.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) => { Console.CursorLeft = 0; Console.Write($"{progressPercentage}% ({HumanReadableBytes(totalBytesDownloaded)}/{HumanReadableBytes(totalFileSize.Value)}) "); // add som extra whitespace to blank out previous updates }; var downloadRequest = new DownloadRequest(datasetFile.Url, downloadDirectory, datasetFile.IsRestricted()); datasetFile.FilePath = await downloader.StartDownload(downloadRequest, appSettings); downloadLog.Updated.Add(fileLog); Console.WriteLine(); downloadUsage?.Entries.Add(new DownloadUsageEntries(datasetFile)); updatedDatasetFileToDownload.Add(datasetFile); } else { fileLog.Message = "Not necessary to download dataset." + datasetFromFeed.LastUpdated; downloadLog.NotUpdated.Add(fileLog); Console.WriteLine("Not necessary to download dataset."); datasetFile.FilePath = downloadHistory.FilePath; updatedDatasetFileToDownload.Add(datasetFile); } datasetFile.DownloadSuccess = true; } catch (Exception e) { Log.Error(e, "Error while downloading file " + datasetFile.Title); updatedDatasetFileToDownload.Add(datasetFile); fileLog.Message = "Error while downloading dataset: " + e.Message; downloadLog.Faild.Add(fileLog); Console.WriteLine("Error while downloading dataset: " + e.Message); datasetFile.DownloadSuccess = true; } Console.WriteLine("-------------"); } updatedDatasetToDownload.Add(localDataset); } Log.Information("Send download usage"); datasetService.SendDownloadUsage(downloadUsage); Log.Information("Write to config file"); datasetService.WriteToConfigFile(updatedDatasetToDownload); Log.Information("Write to download history file"); datasetService.WriteToDownloadHistoryFile(updatedDatasetToDownload); Log.Information("Write to download log file"); datasetService.WriteToDownloadLogFile(downloadLog); }
private void ConvertToMp3(string filePath) { //Start converting into .mp3 convertTask = Task.Factory.StartNew(async() => { lblStatus.Invoke((MethodInvoker)(() => { isConverting = true; pbLoad.BackgroundImage = null; pbLoad.Image = Properties.Resources.load25x25; lblStatus.Text = "Converting..."; })); FFMpegConverter = new NReco.VideoConverter.FFMpegConverter(); FFMpegConverter.FFMpegToolPath = BLIO.rootFolder + "\\Video\\"; FFMpegConverter.ConvertProgress += (o, args) => { try { pbDownload.Invoke((MethodInvoker)(() => { pbDownload.Value = (int)Math.Round((args.Processed.TotalMilliseconds / args.TotalDuration.TotalMilliseconds) * 100); if (pbDownload.Value >= 99) { tmrCheckProgress.Start(); } })); } catch (InvalidOperationException) { }//Thread aborted, can't do things with the controls anymore Console.WriteLine(string.Format("Progress: {0} / {1}\r\n", args.Processed, args.TotalDuration)); }; pathToSong = GetValidFilePath(BLSettings.MP3Path, theVideo.Title, "." + BLSettings.AudioType); try { //Create directory in case it doesnt exist Directory.CreateDirectory(Path.GetDirectoryName(pathToSong)); await Task.Run(() => FFMpegConverter.ConvertMedia(filePath, pathToSong, BLSettings.AudioType)); if (File.Exists(pathToSong)) { DownloadHistory historyRecord = new DownloadHistory(); historyRecord.ChannelTitle = theVideo.Author; historyRecord.DownloadDate = DateTime.Now.ToString(); historyRecord.Duration = theVideo.Duration.ToString(); historyRecord.ThumbnailLink = "http://img.youtube.com/vi/" + theVideo.Id + "/0.jpg"; historyRecord.Title = theVideo.Title; historyRecord.VideoId = theVideo.Id; UCHistory history = (UCHistory)this.Parent.Parent.Parent.Controls["ucHistory"]; DownloadItem item = new DownloadItem(historyRecord); item.theVideo = theVideo; history.AddHistory(item); BLHistory.InsertRecord(historyRecord); if (BLSettings.KeepMp4) { File.Move(BLIO.rootFolder + "\\Video\\" + RemoveIllegalCharacters(Path.GetFileNameWithoutExtension(filePath)) + "." + BLSettings.VideoType, BLSettings.VideoPath + "\\" + RemoveIllegalCharacters(Path.GetFileNameWithoutExtension(filePath)) + "." + BLSettings.VideoType); } else { File.Delete(BLIO.rootFolder + "\\Video\\" + RemoveIllegalCharacters(filePath) + "." + BLSettings.VideoType); } } } catch (NullReferenceException) { } //Nullreference exception occurs when aborting the convert task }, ctsConvert.Token); }