コード例 #1
0
        public override async Task <bool> OpenFileAsync(ICloudFile fileToDownload, bool forceDownload = false, bool showOpenWith = false)
        {
            var          sourceObject = new Uri(fileToDownload.DownloadSourceLocation);
            IStorageFile file         = null;

            if (fileToDownload.IsQualifiedAsSmallDownload() && !forceDownload)
            {
                file = await StorageFile.CreateStreamedFileFromUriAsync(fileToDownload.Name,
                                                                        sourceObject,
                                                                        null);
            }
            else
            {
                //TODO: Add feature to send as attachment. :D
                //TODO: Verify the code waits till the background download is complete before launching the file.
                var downloader = new BackgroundDownloader();
                file = await DownloadManager.DownloadStorageFileAsync(fileToDownload);

                DownloadOperation operation = downloader.CreateDownload(sourceObject, file);
                var result = await operation.StartAsync();

                file = result.ResultFile;
            }

            //SAD: the following did not work somehow
            //var result = await _liveClient.BackgroundDownloadAsync(objectToDownload.DownloadSourceLocation,);
            //var options = new LauncherOptions();
            //options.DisplayApplicationPicker = true;
            //var result2 = await _liveClient.GetAsync(objectToDownload.Id);

            bool launchResult;

            //Consider LaunchUriAsync(...) for else part?
            if (showOpenWith)
            {
                var options = new LauncherOptions {
                    DisplayApplicationPicker = true
                };
                launchResult = await Launcher.LaunchFileAsync(file, options);
            }
            else
            {
                launchResult = await Launcher.LaunchFileAsync(file);
            }

            return(launchResult);
        }
コード例 #2
0
        public override async Task<bool> OpenFileAsync(ICloudFile fileToDownload, bool forceDownload = false, bool showOpenWith = false)
        {
            var sourceObject = new Uri(fileToDownload.DownloadSourceLocation);
            IStorageFile file = null;
            if (fileToDownload.IsQualifiedAsSmallDownload() && !forceDownload)
            {
                file = await StorageFile.CreateStreamedFileFromUriAsync(fileToDownload.Name,
                                                                                     sourceObject,
                                                                                     null);
            }
            else
            {
                //TODO: Add feature to send as attachment. :D
                //TODO: Verify the code waits till the background download is complete before launching the file.
                var downloader = new BackgroundDownloader();
                file = await DownloadManager.DownloadStorageFileAsync(fileToDownload);
                DownloadOperation operation = downloader.CreateDownload(sourceObject, file);
                var result = await operation.StartAsync();
                file = result.ResultFile;
            }

            //SAD: the following did not work somehow
            //var result = await _liveClient.BackgroundDownloadAsync(objectToDownload.DownloadSourceLocation,);
            //var options = new LauncherOptions();
            //options.DisplayApplicationPicker = true;
            //var result2 = await _liveClient.GetAsync(objectToDownload.Id);

            bool launchResult;
            //Consider LaunchUriAsync(...) for else part?
            if (showOpenWith)
            {
                var options = new LauncherOptions {DisplayApplicationPicker = true};
                launchResult = await Launcher.LaunchFileAsync(file, options);
            }
            else
                launchResult = await Launcher.LaunchFileAsync(file);

            return launchResult;
        }