Esempio n. 1
0
 private DocumentFile CreateFile(DownloadDetails details, DownloadDetails.RootDirectoryDetails root, bool useExistingFile)
 {
     lock (LockFile)
     {
         return(useExistingFile ? details.FindOrCreateFile(root) : details.CreateNewFile(root));
     }
 }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        public void StopDownload(DownloadDetails downloadDetails)
        {
            if (_downloadTasks.TryRemove(downloadDetails, out var downloadTask))
            {
                downloadTask.Abort();
            }

            DownloadManager.Instance.TriggerDownloadCancelledEvent(downloadDetails);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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 });
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
 public DownloadDetails UpdateDownloadDetails(DownloadDetails downloadDetails)
 {
     return(AddDownloadDetails(downloadDetails));
 }
Esempio n. 9
0
 internal void TriggerDownloadCompletedEvent(DownloadDetails details)
 {
     details.UpdateStatus(DownloadDetails.Status.Downloaded);
     OnDownloadCompleted?.Invoke(this, details);
 }
Esempio n. 10
0
 internal void TriggerDownloadProgressChangedEvent(DownloadDetails details, long downloadedSize, long totalSize)
 {
     OnDownloadProgressChanged?.Invoke(this, details, downloadedSize, totalSize);
 }
Esempio n. 11
0
 internal void TriggerDownloadErrorOccurredEvent(DownloadDetails details, Exception errorDetails)
 {
     details.UpdateStatus(DownloadDetails.Status.Error);
     OnDownloadErrorOccurred?.Invoke(this, details, errorDetails);
 }
Esempio n. 12
0
 internal void TriggerDownloadCancelledEvent(DownloadDetails details)
 {
     details.UpdateStatus(DownloadDetails.Status.Paused);
     OnDownloadCancelled?.Invoke(this, details);
 }
Esempio n. 13
0
 internal void TriggerDownloadStartedEvent(DownloadDetails details, long fileSize)
 {
     details.UpdateStatus(DownloadDetails.Status.Downloading);
     OnDownloadStarted?.Invoke(this, details, fileSize);
 }