コード例 #1
0
ファイル: DownloadManager.cs プロジェクト: sathukorale/xdm
        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();
        }