Exemple #1
0
        public async Task <ReturnResult> DeleteItemsAsync(IEnumerable <PathWithType> source, bool showDialog, bool permanently, bool registerHistory)
        {
            bool deleteFromRecycleBin = false;

            foreach (PathWithType item in source)
            {
                if (await recycleBinHelpers.IsRecycleBinItem(item.Path))
                {
                    deleteFromRecycleBin = true;
                    break;
                }
            }

            PostedStatusBanner banner;

            if (permanently)
            {
                banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(string.Empty,
                                                                                                    associatedInstance.FilesystemViewModel.WorkingDirectory,
                                                                                                    0,
                                                                                                    ReturnResult.InProgress,
                                                                                                    FileOperationType.Delete);
            }
            else
            {
                banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(string.Empty,
                                                                                                    associatedInstance.FilesystemViewModel.WorkingDirectory,
                                                                                                    0,
                                                                                                    ReturnResult.InProgress,
                                                                                                    FileOperationType.Recycle);
            }

            ReturnResult returnStatus = ReturnResult.InProgress;

            banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

            if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on
            {
                ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(
                    deleteFromRecycleBin,
                    !deleteFromRecycleBin ? permanently : deleteFromRecycleBin,
                    associatedInstance.ContentPage.SelectedItemsPropertiesViewModel);

                await dialog.ShowAsync();

                if (dialog.Result != DialogResult.Delete) // Delete selected  items if the result is Yes
                {
                    return(ReturnResult.Cancelled);       // Return if the result isn't delete
                }

                permanently = dialog.PermanentlyDelete;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            IStorageHistory history;
            var             rawStorageHistory = new List <IStorageHistory>();

            bool originalPermanently = permanently;

            foreach (PathWithType item in source)
            {
                if (await recycleBinHelpers.IsRecycleBinItem(item.Path))
                {
                    permanently = true;
                }
                else
                {
                    permanently = originalPermanently;
                }

                rawStorageHistory.Add(await filesystemOperations.DeleteAsync(item, banner.Progress, banner.ErrorCode, permanently, cancellationToken));
            }

            if (rawStorageHistory.TrueForAll((item) => item != null))
            {
                history = new StorageHistory(
                    rawStorageHistory[0].OperationType,
                    rawStorageHistory.SelectMany((item) => item.Source).ToList(),
                    rawStorageHistory.SelectMany((item) => item.Destination).ToList());

                if (!permanently && registerHistory)
                {
                    App.HistoryWrapper.AddHistory(history);
                }
            }

            banner.Remove();
            sw.Stop();

            PostBannerHelpers.PostBanner_Delete(returnStatus, permanently ? FileOperationType.Delete : FileOperationType.Recycle, sw, associatedInstance);

            return(returnStatus);
        }
        public async Task <ReturnResult> DeleteItemsAsync(IEnumerable <IStorageItemWithPath> source, bool showDialog, bool permanently, bool registerHistory)
        {
            try
            {
                PostedStatusBanner banner;
                if (permanently)
                {
                    banner = associatedInstance.StatusCenterActions.PostBanner(string.Empty,
                                                                               associatedInstance.FilesystemViewModel.WorkingDirectory,
                                                                               0,
                                                                               ReturnResult.InProgress,
                                                                               FileOperationType.Delete);
                }
                else
                {
                    banner = associatedInstance.StatusCenterActions.PostBanner(string.Empty,
                                                                               associatedInstance.FilesystemViewModel.WorkingDirectory,
                                                                               0,
                                                                               ReturnResult.InProgress,
                                                                               FileOperationType.Recycle);
                }

                var returnStatus = ReturnResult.InProgress;
                banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

                var pathsUnderRecycleBin = GetPathsUnderRecycleBin(source);

                if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on
                {
                    var deleteFromRecycleBin = pathsUnderRecycleBin.Count > 0;

                    List <FilesystemItemsOperationItemModel> incomingItems = new List <FilesystemItemsOperationItemModel>();

                    for (int i = 0; i < source.Count(); i++)
                    {
                        incomingItems.Add(new FilesystemItemsOperationItemModel(FilesystemOperationType.Delete, source.ElementAt(i).Path ?? source.ElementAt(i).Item.Path, null));
                    }

                    FilesystemOperationDialog dialog = FilesystemOperationDialogViewModel.GetDialog(new FilesystemItemsOperationDataModel(
                                                                                                        FilesystemOperationType.Delete,
                                                                                                        false,
                                                                                                        !deleteFromRecycleBin ? permanently : deleteFromRecycleBin,
                                                                                                        !deleteFromRecycleBin,
                                                                                                        incomingItems,
                                                                                                        new List <FilesystemItemsOperationItemModel>()));

                    ContentDialogResult result = await dialog.ShowAsync();

                    if (result != ContentDialogResult.Primary)
                    {
                        banner.Remove();
                        return(ReturnResult.Cancelled); // Return if the result isn't delete
                    }

                    // Delete selected items if the result is Yes
                    permanently = dialog.ViewModel.PermanentlyDelete;
                }

                var sw = new Stopwatch();
                sw.Start();

                IStorageHistory history;
                var             rawStorageHistory = new List <IStorageHistory>();

                bool  originalPermanently = permanently;
                float progress;
                for (int i = 0; i < source.Count(); i++)
                {
                    if (pathsUnderRecycleBin.Contains(source.ElementAt(i).Path))
                    {
                        permanently = true;
                    }
                    else
                    {
                        permanently = originalPermanently;
                    }

                    rawStorageHistory.Add(await filesystemOperations.DeleteAsync(source.ElementAt(i), null, banner.ErrorCode, permanently, cancellationToken));
                    progress = ((float)i / (float)source.Count()) * 100.0f;
                    ((IProgress <float>)banner.Progress).Report(progress);
                }

                if (rawStorageHistory.Any() && rawStorageHistory.TrueForAll((item) => item != null))
                {
                    history = new StorageHistory(
                        rawStorageHistory[0].OperationType,
                        rawStorageHistory.SelectMany((item) => item.Source).ToList(),
                        rawStorageHistory.SelectMany((item) => item.Destination).ToList());

                    if (!permanently && registerHistory)
                    {
                        App.HistoryWrapper.AddHistory(history);
                    }
                }

                banner.Remove();
                sw.Stop();

                PostBannerHelpers.PostBanner_Delete(returnStatus, permanently ? FileOperationType.Delete : FileOperationType.Recycle, sw, associatedInstance);
                return(returnStatus);
            }
            catch (System.Exception ex)
            {
                NLog.LogManager.GetCurrentClassLogger().Warn($"Delete items operation failed:\n{ex}");
                return(ReturnResult.Failed);
            }
        }
Exemple #3
0
        public async Task <ReturnResult> DeleteItemsAsync(IEnumerable <IStorageItemWithPath> source, bool showDialog, bool permanently, bool registerHistory)
        {
            PostedStatusBanner banner;

            if (permanently)
            {
                banner = associatedInstance.StatusCenterActions.PostBanner(string.Empty,
                                                                           associatedInstance.FilesystemViewModel.WorkingDirectory,
                                                                           0,
                                                                           ReturnResult.InProgress,
                                                                           FileOperationType.Delete);
            }
            else
            {
                banner = associatedInstance.StatusCenterActions.PostBanner(string.Empty,
                                                                           associatedInstance.FilesystemViewModel.WorkingDirectory,
                                                                           0,
                                                                           ReturnResult.InProgress,
                                                                           FileOperationType.Recycle);
            }

            var returnStatus = ReturnResult.InProgress;

            banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus();

            var pathsUnderRecycleBin = GetPathsUnderRecycleBin(source);

            if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on
            {
                var deleteFromRecycleBin = pathsUnderRecycleBin.Count > 0;

                ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(
                    deleteFromRecycleBin,
                    !deleteFromRecycleBin ? permanently : deleteFromRecycleBin,
                    associatedInstance.ContentPage.SelectedItemsPropertiesViewModel);

                if (Interacts.Interaction.IsAnyContentDialogOpen())
                {
                    // Can show only one dialog at a time
                    banner.Remove();
                    return(ReturnResult.Cancelled);
                }
                await dialog.ShowAsync();

                if (dialog.Result != DialogResult.Delete) // Delete selected items if the result is Yes
                {
                    banner.Remove();
                    return(ReturnResult.Cancelled); // Return if the result isn't delete
                }

                permanently = dialog.PermanentlyDelete;
            }

            var sw = new Stopwatch();

            sw.Start();

            IStorageHistory history;
            var             rawStorageHistory = new List <IStorageHistory>();

            bool  originalPermanently = permanently;
            float progress;

            for (int i = 0; i < source.Count(); i++)
            {
                if (pathsUnderRecycleBin.Contains(source.ElementAt(i).Path))
                {
                    permanently = true;
                }
                else
                {
                    permanently = originalPermanently;
                }

                rawStorageHistory.Add(await filesystemOperations.DeleteAsync(source.ElementAt(i), null, banner.ErrorCode, permanently, cancellationToken));
                progress = ((float)i / (float)source.Count()) * 100.0f;
                ((IProgress <float>)banner.Progress).Report(progress);
            }

            if (rawStorageHistory.Any() && rawStorageHistory.TrueForAll((item) => item != null))
            {
                history = new StorageHistory(
                    rawStorageHistory[0].OperationType,
                    rawStorageHistory.SelectMany((item) => item.Source).ToList(),
                    rawStorageHistory.SelectMany((item) => item.Destination).ToList());

                if (!permanently && registerHistory)
                {
                    App.HistoryWrapper.AddHistory(history);
                }
            }

            banner.Remove();
            sw.Stop();

            PostBannerHelpers.PostBanner_Delete(returnStatus, permanently ? FileOperationType.Delete : FileOperationType.Recycle, sw, associatedInstance);

            return(returnStatus);
        }