private void DownloadResource(object parameter)
        {
            var resourceInfo = parameter as ResourceInfo;

            if (resourceInfo == null)
            {
                return;
            }
            var parameters = new SingleFileDownloadPageParameters
            {
                ResourceInfo = resourceInfo
            };

            _navigationService.Navigate(PageTokens.SingleFileDownload.ToString(), parameters.Serialize());
        }
Ejemplo n.º 2
0
        public FileInfoPageViewModel(INavigationService navigationService, IResourceLoader resourceLoader, DialogService dialogService)
        {
            _navigationService = navigationService;
            _resourceLoader    = resourceLoader;
            _dialogService     = dialogService;

            Directory = DirectoryService.Instance;

            //DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
            //dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(ShareImageHandler);
            DownloadCommand = new DelegateCommand(() =>
            {
                var parameters = new SingleFileDownloadPageParameters
                {
                    ResourceInfo = ResourceInfo
                };
                _navigationService.Navigate(PageTokens.SingleFileDownload.ToString(), parameters.Serialize());
            });
            DeleteResourceCommand = new DelegateCommand(DeleteResource);
            RenameResourceCommand = new DelegateCommand(RenameResource);
            MoveResourceCommand   = new RelayCommand(MoveResource);
        }
        public override async void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            base.OnNavigatedTo(e, viewModelState);

            var client = await ClientService.GetClient();

            if (client == null)
            {
                return;
            }

            _cts = new CancellationTokenSource();

            var parameters   = SingleFileDownloadPageParameters.Deserialize(e.Parameter);
            var resourceInfo = parameters?.ResourceInfo;

            if (resourceInfo == null)
            {
                return;
            }

            if (resourceInfo.ContentType == "dav/directory")
            {
                ResourceInfo = new ResourceInfo
                {
                    Name        = resourceInfo.Name + ".zip",
                    ContentType = "application/zip"
                };
            }
            else
            {
                ResourceInfo = resourceInfo;
            }

            var savePicker = new FileSavePicker();

            savePicker.FileTypeChoices.Add(ResourceInfo.ContentType, new List <string> {
                Path.GetExtension(ResourceInfo.Name)
            });
            savePicker.SuggestedFileName = ResourceInfo.Name;

            var localFile = await savePicker.PickSaveFileAsync();

            if (localFile == null)
            {
                return;
            }

            _currentFile = localFile;

            // Prevent updates to the remote version of the file until
            // we finish making changes and call CompleteUpdatesAsync.
            CachedFileManager.DeferUpdates(localFile);

            try
            {
                IProgress <HttpProgress>        progress = new Progress <HttpProgress>(ProgressHandler);
                Windows.Storage.Streams.IBuffer buffer;
                switch (resourceInfo.ContentType)
                {
                case "dav/directory":
                    buffer = await client.DownloadDirectoryAsZip(ResourceInfo.Path, _cts, progress);

                    break;

                default:
                    buffer = await client.Download(ResourceInfo.Path + "/" + ResourceInfo.Name, _cts, progress);

                    break;
                }
                await FileIO.WriteBufferAsync(localFile, buffer);
            }
            catch (ResponseError e2)
            {
                ResponseErrorHandlerService.HandleException(e2);
            }

            // Let Windows know that we're finished changing the file so
            // the other app can update the remote version of the file.
            // Completing updates may require Windows to ask for user input.
            var status = await CachedFileManager.CompleteUpdatesAsync(localFile);

            if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
            {
                //this.textBlock.Text = "Path " + file.Name + " was saved.";
            }
            else
            {
                //this.textBlock.Text = "Path " + file.Name + " couldn't be saved.";
            }

            _navigationService.GoBack();
        }