private DocumentFile CreateFile(DownloadDetails details, DownloadDetails.RootDirectoryDetails root, bool useExistingFile) { lock (LockFile) { return(useExistingFile ? details.FindOrCreateFile(root) : details.CreateNewFile(root)); } }
public DownloadDetails AddDownloadDetails(string url, string downloadLocation, string fileName, string mimeType) { var downloadId = GetNextDownloadId(); var downloadDetails = new DownloadDetails(downloadId, url, fileName, downloadLocation, mimeType); return(AddDownloadDetails(downloadDetails)); }
public void StopDownload(DownloadDetails downloadDetails) { if (_downloadTasks.TryRemove(downloadDetails, out var downloadTask)) { downloadTask.Abort(); } DownloadManager.Instance.TriggerDownloadCancelledEvent(downloadDetails); }
private DownloadDetails AddDownloadDetails(DownloadDetails downloadDetails) { _downloadDetails.AddOrUpdate(downloadDetails.DownloadId ?? Int32.MaxValue, downloadDetails, (previous, current) => downloadDetails); var connection = DatabaseConnectionManager.GetConnection(); connection.InsertOrReplace(downloadDetails); connection.Commit(); return(downloadDetails); }
public void Update(DownloadDetails downloadDetails) { DownloadStatus = downloadDetails.DownloadStatus; ContentUri = ContentUri ?? downloadDetails.ContentUri; if (DownloadStatus == (int)Status.Downloaded) { CurrentProgress.Update(0, 0); } CurrentProgress.Update(downloadDetails.CurrentProgress); }
public void ResumeDownloadTask(DownloadManagerConfiguration configuration, DownloadDetails downloadDetails) { if (_downloadTasks.TryRemove(downloadDetails, out var downloadTask)) { downloadTask.Abort(); } downloadTask = new Thread(OnDownloadTaskStarted); _downloadTasks.AddOrUpdate(downloadDetails, downloadTask, (details, thread) => downloadTask); downloadTask.Start(new object[] { configuration, downloadDetails, true }); }
public void OpenFile(DownloadDetails details) { CheckWhetherDownloadManagerIsConfigured(); var task = new Task <DocumentFile>(() => { if (StorageUtils.IsInAnyStorageDevices(_configuration.Context, details.DownloadDirectory, out string rootDirectory) == false) { throw new System.Exception($"Could not locate the root directory for the download location, '{details.DownloadDirectory}'."); } var rootDirectoryDocument = _configuration.StoragePermissionsHandler.RequestStoragePermission(rootDirectory); var rootDetails = new DownloadDetails.RootDirectoryDetails(rootDirectory, rootDirectoryDocument); return(details.FindFile(rootDetails)); }); task.ContinueWith(result => { try { var foundFile = result.Result; if (foundFile == null) { throw new FileNotFoundException($"The file '{details.FileName}' could not be located. Perhaps it was moved or deleted."); } TriggerOpenFileIntent(_configuration.Context, foundFile.Uri, details.MimeType); } catch (ActivityNotFoundException ex) { OnOpenRequestError?.Invoke(this, ex); } catch (FileNotFoundException ex) { OnOpenRequestError?.Invoke(this, ex); } catch { /* IGNORED */ } }); task.Start(); }
public DownloadDetails UpdateDownloadDetails(DownloadDetails downloadDetails) { return(AddDownloadDetails(downloadDetails)); }
internal void TriggerDownloadCompletedEvent(DownloadDetails details) { details.UpdateStatus(DownloadDetails.Status.Downloaded); OnDownloadCompleted?.Invoke(this, details); }
internal void TriggerDownloadProgressChangedEvent(DownloadDetails details, long downloadedSize, long totalSize) { OnDownloadProgressChanged?.Invoke(this, details, downloadedSize, totalSize); }
internal void TriggerDownloadErrorOccurredEvent(DownloadDetails details, Exception errorDetails) { details.UpdateStatus(DownloadDetails.Status.Error); OnDownloadErrorOccurred?.Invoke(this, details, errorDetails); }
internal void TriggerDownloadCancelledEvent(DownloadDetails details) { details.UpdateStatus(DownloadDetails.Status.Paused); OnDownloadCancelled?.Invoke(this, details); }
internal void TriggerDownloadStartedEvent(DownloadDetails details, long fileSize) { details.UpdateStatus(DownloadDetails.Status.Downloading); OnDownloadStarted?.Invoke(this, details, fileSize); }