コード例 #1
0
        private async Task CreateFolderAsync()
        {
            var dialog = new ContentDialog();

            dialog.Title = App.ResourceLoader.GetString("CreateNewFolder");
            var box = new TextBox()
            {
                Header        = App.ResourceLoader.GetString("FolderName"),
                AcceptsReturn = false,
                SelectedText  = App.ResourceLoader.GetString("NewFolderName")
            };

            dialog.Content             = box;
            dialog.PrimaryButtonText   = App.ResourceLoader.GetString("OK");
            dialog.SecondaryButtonText = App.ResourceLoader.GetString("Cancel");
            var result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                IndicatorService.GetDefault().ShowBar();
                await WebDavItemService.GetDefault().CreateFolder(WebDavNavigationService.CurrentItem, box.Text);

                await WebDavNavigationService.ReloadAsync();

                IndicatorService.GetDefault().HideBar();
            }
        }
コード例 #2
0
        private async Task Move()
        {
            try
            {
                IndicatorService.GetDefault().ShowBar();
                foreach (var davItem in _itemsToMove)
                {
                    await WebDavItemService.GetDefault().MoveToFolder(davItem, WebDavNavigationService.CurrentItem);
                }
            }
            finally
            {
                IndicatorService.GetDefault().HideBar();
                await WebDavNavigationService.ReloadAsync();

                await NavigationService.NavigateAsync(typeof(FilesPage), WebDavNavigationService.CurrentItem, new SuppressNavigationTransitionInfo());
            }
            for (int i = 0; i < NavigationService.Frame.BackStackDepth; i++)
            {
                if (NavigationService.Frame.BackStack[i].SourcePageType == typeof(SelectFolderPage))
                {
                    NavigationService.Frame.BackStack.RemoveAt(i);
                }
            }
        }
コード例 #3
0
        private async Task UploadFilesAsync()
        {
            FileOpenPicker picker = new FileOpenPicker();

            picker.FileTypeFilter.Add("*");
            picker.SuggestedStartLocation = PickerLocationId.ComputerFolder;
            var files = await picker.PickMultipleFilesAsync();

            _tokenSource = new CancellationTokenSource();
            var button = new Button();

            button.Content             = App.ResourceLoader.GetString("Cancel");
            button.HorizontalAlignment = HorizontalAlignment.Center;
            button.Command             = new DelegateCommand(() =>
            {
                _tokenSource.Cancel(false);
                IndicatorService.GetDefault().HideBar();
            });
            _executionSession = await RequestExtendedExecutionAsync();

            try
            {
                foreach (var file in files)
                {
                    if (!_tokenSource.IsCancellationRequested)
                    {
                        var progress = new Progress <HttpProgress>(async httpProgress =>
                        {
                            if (_tokenSource.IsCancellationRequested)
                            {
                                return;
                            }
                            await Dispatcher.DispatchAsync(() =>
                            {
                                var text = string.Format(App.ResourceLoader.GetString("UploadingFile"), file.DisplayName);
                                text    += Environment.NewLine + new BytesToSuffixConverter().Convert(httpProgress.BytesSent, null, null, null) + " - " + new ProgressToPercentConverter().Convert(httpProgress, null, null, null);
                                IndicatorService.GetDefault().ShowBar(text, button);

                                if (httpProgress.BytesSent == httpProgress.TotalBytesToSend && files.Count - 1 == files.ToList().IndexOf(file))
                                {
                                    IndicatorService.GetDefault().HideBar();
                                    SelectionMode = ListViewSelectionMode.Single;
                                }
                            });
                        });
                        await WebDavItemService.GetDefault().UploadAsync(WebDavNavigationService.CurrentItem, file, _tokenSource.Token, progress);
                    }
                }
            }
            catch (TaskCanceledException) { }
            finally
            {
                ClearExecutionSession(_executionSession);
                IndicatorService.GetDefault().HideBar();
                await WebDavNavigationService.ReloadAsync();
            }
        }
コード例 #4
0
 public SelectFolderPageViewModel()
 {
     HomeCommand = new DelegateCommand(async() => await WebDavNavigationService.NavigateAsync(new DavItem {
         EntityId = Configuration.ServerUrl
     }));
     AcceptCommand = new DelegateCommand(async() => await AcceptSelection());
     CancelCommand = new DelegateCommand(async() =>
     {
         await WebDavNavigationService.ReloadAsync();
         await NavigationService.NavigateAsync(typeof(FilesPage), SelectedItem, new SuppressNavigationTransitionInfo());
     });
     CreateFolderCommand = new DelegateCommand(async() => await CreateFolderAsync());
 }
コード例 #5
0
        private async Task DeleteItems(List <DavItem> items)
        {
            ContentDialog dialog = new ContentDialog();

            if (items.Count == 1)
            {
                var item = items.First();
                dialog.Title = App.ResourceLoader.GetString("deleteFileConfirmation");
                if (item.IsCollection)
                {
                    dialog.Title = App.ResourceLoader.GetString("deleteFolderConfirmation");
                }
                dialog.Content = item.DisplayName;
            }
            else
            {
                dialog.Title = App.ResourceLoader.GetString("deleteMultipleConfirmation");
                int i = 0;
                foreach (var item in items)
                {
                    if (i < 3)
                    {
                        dialog.Content += item.DisplayName + Environment.NewLine;
                        i++;
                    }
                    else
                    {
                        dialog.Content += "...";
                        break;
                    }
                }
            }
            dialog.PrimaryButtonText   = App.ResourceLoader.GetString("yes");
            dialog.SecondaryButtonText = App.ResourceLoader.GetString("no");
            var result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                IndicatorService.GetDefault().ShowBar();
                await WebDavItemService.GetDefault().DeleteItemAsync(items.Cast <DavItem>().ToList());

                SelectionMode = ListViewSelectionMode.Single;
                await WebDavNavigationService.ReloadAsync();

                IndicatorService.GetDefault().HideBar();
            }
        }
コード例 #6
0
 public FilesPageViewModel()
 {
     _syncedFolderService       = new SyncedFoldersService();
     UploadItemCommand          = new DelegateCommand(async() => await UploadFilesAsync());
     RefreshCommand             = new DelegateCommand(async() => await WebDavNavigationService.ReloadAsync());
     AddToSyncCommand           = new DelegateCommand <object>(async parameter => await RegisterFolderForSync(parameter));
     DownloadCommand            = new DelegateCommand <DavItem>(async item => await DownloadFilesAsync(FilesPage.GetSelectedItems(item)));
     DeleteCommand              = new DelegateCommand <DavItem>(async item => await DeleteItems(FilesPage.GetSelectedItems(item)));
     SwitchSelectionModeCommand = new DelegateCommand(() => SelectionMode = SelectionMode == ListViewSelectionMode.Multiple ? ListViewSelectionMode.Single : ListViewSelectionMode.Multiple);
     ShowPropertiesCommand      = new DelegateCommand <DavItem>(async item => await NavigationService.NavigateAsync(typeof(DetailsPage), item, new SuppressNavigationTransitionInfo()));
     AddFolderCommand           = new DelegateCommand(async() => await CreateFolderAsync());
     HomeCommand = new DelegateCommand(async() => await WebDavNavigationService.NavigateAsync(new DavItem {
         EntityId = Configuration.ServerUrl
     }));
     MoveCommand   = new DelegateCommand <DavItem>(async item => await NavigationService.NavigateAsync(typeof(SelectFolderPage), FilesPage.GetSelectedItems(item), new SuppressNavigationTransitionInfo()));
     RenameCommand = new DelegateCommand <DavItem>(async item => await Rename(item));
     OpenCommand   = new DelegateCommand <DavItem>(async item => await OpenFileAsync(item));
 }
コード例 #7
0
        private async Task Rename(DavItem item)
        {
            var dialog = new ContentDialog();

            dialog.Title = App.ResourceLoader.GetString("RenameTitle");
            var box = new TextBox();

            box.Header        = App.ResourceLoader.GetString("NewName");
            box.AcceptsReturn = false;
            try
            {
                box.Text         = Path.GetExtension(item.DisplayName);
                box.SelectedText = Path.GetFileNameWithoutExtension(item.DisplayName);
            }
            catch (ArgumentException)
            {
                box.Text = item.DisplayName;
            }

            dialog.Content             = box;
            dialog.PrimaryButtonText   = App.ResourceLoader.GetString("OK");
            dialog.SecondaryButtonText = App.ResourceLoader.GetString("Cancel");
            var result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                if (string.IsNullOrWhiteSpace(box.Text))
                {
                    return;
                }
                IndicatorService.GetDefault().ShowBar();
                await WebDavItemService.GetDefault().Rename(item, box.Text);

                await WebDavNavigationService.ReloadAsync();

                IndicatorService.GetDefault().HideBar();
            }
        }