public void Delete()
        {
            ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(DialogOwner, "Its subitems will not be removed.");
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                Model.Delete();
                if (Parent != null)
                {
                    Parent.Children.Remove(this);
                    foreach (var item in Children)
                    {
                        if (item is MarkdownCategoryViewModel)
                        {
                            MarkdownCategoryViewModel child = (MarkdownCategoryViewModel)item;
                            child.Parent         = Parent;
                            child.Model.ParentId = (Parent as MarkdownCategoryViewModel).Model.id;
                            Parent.Children.Add(child);
                            child.Model.Save();
                        }
                        else
                        {
                            MarkdownDocumentViewModel child = (MarkdownDocumentViewModel)item;
                            child.Parent = Parent;

                            MarkdownCategoryDocument link = new MarkdownCategoryDocument(Model.Connection);
                            link.MarkdownCategoryId = (Parent as MarkdownCategoryViewModel).Model.id;
                            link.MarkdownDocumentId = child.Model.id;
                            link.Create();
                            Parent.Children.Add(child);
                        }
                    }
                }
                else
                {
                    if (UniverseVm.MarkdownTree.Items.Contains(this))
                    {
                        UniverseVm.MarkdownTree.Items.Remove(this);
                    }
                    foreach (var item in Children)
                    {
                        if (item is MarkdownCategoryViewModel)
                        {
                            MarkdownCategoryViewModel child = (MarkdownCategoryViewModel)item;
                            child.Parent         = null;
                            child.Model.ParentId = null;
                            child.Model.Save();
                            UniverseVm.MarkdownTree.Items.Add(child);
                        }
                        else
                        {
                            MarkdownDocumentViewModel child = (MarkdownDocumentViewModel)item;
                            UniverseVm.MarkdownTree.Items.Add(child);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <SvnOrigin>          items   = new List <SvnOrigin>();
            List <ISvnRepositoryItem> refresh = new List <ISvnRepositoryItem>();

            foreach (ISvnRepositoryItem i in e.Selection.GetSelection <ISvnRepositoryItem>())
            {
                if (i.Origin == null || i.Origin.Target.Revision != SvnRevision.Head || i.Origin.IsRepositoryRoot)
                {
                    break;
                }

                items.Add(i.Origin);
                refresh.Add(i);
            }

            if (items.Count == 0)
            {
                return;
            }

            string logMessage;

            Uri[] uris;
            using (ConfirmDeleteDialog d = new ConfirmDeleteDialog())
            {
                d.Context = e.Context;
                d.SetUris(items);

                if (!e.DontPrompt && d.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                logMessage = d.LogMessage;
                uris       = d.Uris;
            }

            try
            {
                e.GetService <IProgressRunner>().RunModal(CommandStrings.Deleting,
                                                          delegate(object sender, ProgressWorkerArgs a)
                {
                    SvnDeleteArgs da = new SvnDeleteArgs();
                    da.LogMessage    = logMessage;

                    a.Client.RemoteDelete(uris, da);
                });
            }
            finally
            {
                // TODO: Don't refresh each item; refresh each parent!
                foreach (ISvnRepositoryItem r in refresh)
                {
                    r.RefreshItem(true);
                }
            }
        }
Ejemplo n.º 3
0
 public void Delete()
 {
     if (_deleteButton.IsExist())
     {
         _deleteButton.ClickByJS();
         Wait.WaitForAjaxReady(SimsBy.CssSelector(".locking-mask"));
         var confirmDialog = new ConfirmDeleteDialog();
         confirmDialog.ClickContinueDelete();
     }
 }
Ejemplo n.º 4
0
        public void Delete()
        {
            ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(DialogOwner, string.Format("Scene: {0}", Model.Name));
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                Model.Delete();
                ChapterVm.DeleteScene(this);
            }
        }
Ejemplo n.º 5
0
        public void Delete()
        {
            ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(DialogOwner, string.Format("Note Document: {0}", Model.Name));
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                Model.Delete();
                UniverseVm.MarkdownTree.RemoveFromTree(this);
            }
        }
Ejemplo n.º 6
0
        public void Delete()
        {
            ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(DialogOwner, string.Format("File: {0}", Model.Name));
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                Model.Delete();
                FileBrowserVm.Files.Remove(this);
            }
        }
Ejemplo n.º 7
0
        public void Delete()
        {
            ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(DialogOwner, string.Format("Story: {0}", Model.Name));
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                Model.Delete();
                UniverseVm.DeleteSubItem(this);
            }
        }
Ejemplo n.º 8
0
        internal static void DeleteEquipmentSystem(EquipmentSystem equipmentSystem)
        {
            var dialog = new ConfirmDeleteDialog();

            if ((bool)dialog.ShowDialog())
            {
                database.EquipmentSystems.Remove(equipmentSystem);

                Save();
                RefreshSystemList();
            }
        }
Ejemplo n.º 9
0
        internal static void DeleteEquipment(Equipment selectedItem, ListView equipmentGroupsListView, int equipmentGroupingId, ListView systemListView, int systemId)
        {
            var dialog = new ConfirmDeleteDialog();

            if ((bool)dialog.ShowDialog())
            {
                database.EquipmentListing.Remove(selectedItem);
                Save();
                RefreshSystemList();

                systemListView.SelectedItem          = systemList.First(s => s.Id == systemId);
                equipmentGroupsListView.SelectedItem =
                    ((EquipmentSystem)systemListView.SelectedItem).EquipmentGroupings.First(e => e.Id == equipmentGroupingId);
            }
        }
Ejemplo n.º 10
0
        public static async Task <bool> ConfirmDelete(string caption = null)
        {
            ConfirmDeleteDialog dialog = new ConfirmDeleteDialog();

            if (caption != null)
            {
                dialog.Title = caption;
            }

            ContentDialogResult result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 11
0
        internal static void DeleteEquipmentGrouping(EquipmentGrouping equipmentGrouping, ListView list)
        {
            var dialog = new ConfirmDeleteDialog();

            if ((bool)dialog.ShowDialog())
            {
                EquipmentSystem selectedSystem = null;

                foreach (var system in database.EquipmentSystems)
                {
                    if (system.EquipmentGroupings.Any(e => e.Id == equipmentGrouping.Id))
                    {
                        selectedSystem = system;
                    }
                }
                database.EquipmentGroupings.Remove(equipmentGrouping);

                Save();
                RefreshSystemList();
                list.SelectedItem = systemList.First(s => s.Id == selectedSystem.Id);
            }
        }
Ejemplo n.º 12
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.SlimContentPage.SelectedItems.Count);

                if (UIHelpers.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);
        }
Ejemplo n.º 13
0
        public async Task <ReturnResult> DeleteItemAsync(IStorageItem source, bool showDialog, bool permanently, bool registerHistory)
        {
            PostedStatusBanner banner;
            bool deleteFromRecycleBin = recycleBinHelpers.IsPathUnderRecycleBin(source.Path);

            if (deleteFromRecycleBin)
            {
                permanently = true;
            }

            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();

            if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on
            {
                ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(
                    deleteFromRecycleBin,
                    permanently,
                    associatedInstance.SlimContentPage.SelectedItems.Count);

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

                if (dialog.Result != DialogResult.Delete) // Delete selected item 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 = await filesystemOperations.DeleteAsync(source, banner.Progress, banner.ErrorCode, permanently, cancellationToken);

            ((IProgress <float>)banner.Progress).Report(100.0f);

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

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

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

            return(returnStatus);
        }
Ejemplo n.º 14
0
        private static async Task DeleteItem(StorageDeleteOption deleteOption, IShellPage AppInstance, IProgress <uint> progress)
        {
            var deleteFromRecycleBin = AppInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath);

            List <ListedItem> selectedItems = new List <ListedItem>();

            foreach (ListedItem selectedItem in AppInstance.ContentPage.SelectedItems)
            {
                selectedItems.Add(selectedItem);
            }

            if (App.AppSettings.ShowConfirmDeleteDialog == true) //check if the setting to show a confirmation dialog is on
            {
                var dialog = new ConfirmDeleteDialog(deleteFromRecycleBin, deleteOption);
                await dialog.ShowAsync();

                if (dialog.Result != MyResult.Delete) //delete selected  item(s) if the result is yes
                {
                    return;                           //return if the result isn't delete
                }
                deleteOption = dialog.PermanentlyDelete;
            }

            int itemsDeleted = 0;

            foreach (ListedItem storItem in selectedItems)
            {
                uint progressValue = (uint)(itemsDeleted * 100.0 / selectedItems.Count);
                if (selectedItems.Count > 3)
                {
                    progress.Report((uint)progressValue);
                }

                IStorageItem item;
                try
                {
                    if (storItem.PrimaryItemAttribute == StorageItemTypes.File)
                    {
                        item = await ItemViewModel.GetFileFromPathAsync(storItem.ItemPath, AppInstance);
                    }
                    else
                    {
                        item = await ItemViewModel.GetFolderFromPathAsync(storItem.ItemPath, AppInstance);
                    }

                    await item.DeleteAsync(deleteOption);
                }
                catch (UnauthorizedAccessException)
                {
                    if (deleteOption == StorageDeleteOption.Default)
                    {
                        // Try again with fulltrust process
                        if (App.Connection != null)
                        {
                            var result = await App.Connection.SendMessageAsync(new ValueSet()
                            {
                                { "Arguments", "FileOperation" },
                                { "fileop", "MoveToBin" },
                                { "filepath", storItem.ItemPath }
                            });
                        }
                    }
                    else
                    {
                        // Try again with DeleteFileFromApp
                        if (!NativeDirectoryChangesHelper.DeleteFileFromApp(storItem.ItemPath))
                        {
                            Debug.WriteLine(System.Runtime.InteropServices.Marshal.GetLastWin32Error());
                        }
                    }
                }
                catch (FileLoadException)
                {
                    // try again
                    if (storItem.PrimaryItemAttribute == StorageItemTypes.File)
                    {
                        item = await ItemViewModel.GetFileFromPathAsync(storItem.ItemPath, AppInstance);
                    }
                    else
                    {
                        item = await ItemViewModel.GetFolderFromPathAsync(storItem.ItemPath, AppInstance);
                    }

                    await item.DeleteAsync(deleteOption);
                }

                if (deleteFromRecycleBin)
                {
                    // Recycle bin also stores a file starting with $I for each item
                    var iFilePath = Path.Combine(Path.GetDirectoryName(storItem.ItemPath), Path.GetFileName(storItem.ItemPath).Replace("$R", "$I"));
                    await(await ItemViewModel.GetFileFromPathAsync(iFilePath)).DeleteAsync(StorageDeleteOption.PermanentDelete);
                }

                AppInstance.FilesystemViewModel.RemoveFileOrFolder(storItem);
                itemsDeleted++;
            }
        }
Ejemplo n.º 15
0
        public async void DeleteItem_Click(object sender, RoutedEventArgs e)
        {
            if (App.AppSettings.ShowConfirmDeleteDialog == true) //check if the setting to show a confirmation dialog is on
            {
                var dialog = new ConfirmDeleteDialog();
                await dialog.ShowAsync();

                if (dialog.Result != MyResult.Delete) //delete selected  item(s) if the result is yes
                {
                    return;                           //return if the result isn't delete
                }
            }

            try
            {
                var CurrentInstance             = App.CurrentInstance;
                List <ListedItem> selectedItems = new List <ListedItem>();
                foreach (ListedItem selectedItem in CurrentInstance.ContentPage.SelectedItems)
                {
                    selectedItems.Add(selectedItem);
                }
                int itemsDeleted = 0;
                if (selectedItems.Count > 3)
                {
                    (App.CurrentInstance as ModernShellPage).UpdateProgressFlyout(InteractionOperationType.DeleteItems, itemsDeleted, selectedItems.Count);
                }

                foreach (ListedItem storItem in selectedItems)
                {
                    if (selectedItems.Count > 3)
                    {
                        (App.CurrentInstance as ModernShellPage).UpdateProgressFlyout(InteractionOperationType.DeleteItems, ++itemsDeleted, selectedItems.Count);
                    }
                    IStorageItem item;
                    try
                    {
                        if (storItem.PrimaryItemAttribute == StorageItemTypes.File)
                        {
                            item = await StorageFile.GetFileFromPathAsync(storItem.ItemPath);
                        }
                        else
                        {
                            item = await StorageFolder.GetFolderFromPathAsync(storItem.ItemPath);
                        }

                        await item.DeleteAsync(App.InteractionViewModel.PermanentlyDelete);
                    }
                    catch (FileLoadException)
                    {
                        // try again
                        if (storItem.PrimaryItemAttribute == StorageItemTypes.File)
                        {
                            item = await StorageFile.GetFileFromPathAsync(storItem.ItemPath);
                        }
                        else
                        {
                            item = await StorageFolder.GetFolderFromPathAsync(storItem.ItemPath);
                        }

                        await item.DeleteAsync(App.InteractionViewModel.PermanentlyDelete);
                    }

                    CurrentInstance.ViewModel.RemoveFileOrFolder(storItem);
                }
                App.CurrentInstance.NavigationToolbar.CanGoForward = false;
            }
            catch (UnauthorizedAccessException)
            {
                MessageDialog AccessDeniedDialog = new MessageDialog("Access Denied", "Unable to delete this item");
                await AccessDeniedDialog.ShowAsync();
            }
            catch (FileNotFoundException)
            {
                Debug.WriteLine("Attention: Tried to delete an item that could be found");
            }

            App.InteractionViewModel.PermanentlyDelete = StorageDeleteOption.Default; //reset PermanentlyDelete flag
        }
Ejemplo n.º 16
0
        public async Task <ReturnResult> DeleteItemsAsync(IEnumerable <IStorageItemWithPath> source, bool showDialog, bool permanently, bool registerHistory)
        {
            bool deleteFromRecycleBin = false;

            foreach (IStorageItemWithPath 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 (IStorageItemWithPath 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);
        }
Ejemplo n.º 17
0
        public async Task <ReturnResult> DeleteItemAsync(IStorageItem source, bool showDialog, bool permanently, bool registerHistory)
        {
            PostedStatusBanner banner;
            bool deleteFromRecycleBin = await recycleBinHelpers.IsRecycleBinItem(source);

            if (deleteFromRecycleBin)
            {
                permanently = true;
            }

            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,
                    permanently,
                    associatedInstance.ContentPage.SelectedItemsPropertiesViewModel);

                await dialog.ShowAsync();

                if (dialog.Result != DialogResult.Delete) // Delete selected item 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 = await filesystemOperations.DeleteAsync(source, banner.Progress, banner.ErrorCode, permanently, cancellationToken);

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

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

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

            return(returnStatus);
        }
Ejemplo n.º 18
0
        private async Task <FilesystemResult> DeleteItemAsync(StorageDeleteOption deleteOption, IShellPage AppInstance, IProgress <uint> progress)
        {
            var deleted = (FilesystemResult)false;
            var deleteFromRecycleBin = AppInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath);

            List <ListedItem> selectedItems = new List <ListedItem>();

            foreach (ListedItem selectedItem in AppInstance.ContentPage.SelectedItems)
            {
                selectedItems.Add(selectedItem);
            }

            if (App.AppSettings.ShowConfirmDeleteDialog == true) //check if the setting to show a confirmation dialog is on
            {
                var dialog = new ConfirmDeleteDialog(deleteFromRecycleBin, deleteOption, AppInstance.ContentPage.SelectedItemsPropertiesViewModel);
                await dialog.ShowAsync();

                if (dialog.Result != MyResult.Delete) //delete selected  item(s) if the result is yes
                {
                    return((FilesystemResult)true);   //return if the result isn't delete
                }
                deleteOption = dialog.PermanentlyDelete;
            }

            int itemsDeleted = 0;

            foreach (ListedItem storItem in selectedItems)
            {
                uint progressValue = (uint)(itemsDeleted * 100.0 / selectedItems.Count);
                if (selectedItems.Count > 3)
                {
                    progress.Report(progressValue);
                }

                if (storItem.PrimaryItemAttribute == StorageItemTypes.File)
                {
                    deleted = await AppInstance.FilesystemViewModel.GetFileFromPathAsync(storItem.ItemPath)
                              .OnSuccess(t => t.DeleteAsync(deleteOption).AsTask());
                }
                else
                {
                    deleted = await AppInstance.FilesystemViewModel.GetFolderFromPathAsync(storItem.ItemPath)
                              .OnSuccess(t => t.DeleteAsync(deleteOption).AsTask());
                }

                if (deleted.ErrorCode == FilesystemErrorCode.ERROR_UNAUTHORIZED)
                {
                    // Try again with fulltrust process
                    if (AppInstance.FilesystemViewModel.Connection != null)
                    {
                        var response = await AppInstance.FilesystemViewModel.Connection.SendMessageAsync(new ValueSet()
                        {
                            { "Arguments", "FileOperation" },
                            { "fileop", "DeleteItem" },
                            { "filepath", storItem.ItemPath },
                            { "permanently", deleteOption == StorageDeleteOption.PermanentDelete }
                        });

                        deleted = (FilesystemResult)(response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success);
                    }
                }
                else if (deleted.ErrorCode == FilesystemErrorCode.ERROR_INUSE)
                {
                    // TODO: retry or show dialog
                    await DialogDisplayHelper.ShowDialogAsync("FileInUseDeleteDialog/Title".GetLocalized(), "FileInUseDeleteDialog/Text".GetLocalized());
                }

                if (deleteFromRecycleBin)
                {
                    // Recycle bin also stores a file starting with $I for each item
                    var iFilePath = Path.Combine(Path.GetDirectoryName(storItem.ItemPath), Path.GetFileName(storItem.ItemPath).Replace("$R", "$I"));
                    await AppInstance.FilesystemViewModel.GetFileFromPathAsync(iFilePath)
                    .OnSuccess(t => t.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask());
                }

                if (deleted)
                {
                    await AppInstance.FilesystemViewModel.RemoveFileOrFolderAsync(storItem);

                    itemsDeleted++;
                }
                else
                {
                    // Stop at first error
                    return(deleted);
                }
            }
            return((FilesystemResult)true);
        }