public IExplorerRepositoryResult DeleteFolder(string path, bool deleteContents, Guid workSpaceId)
        {
            if (!Directory.Exists(DirectoryStructureFromPath(path)))
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, "Requested folder does not exist on server. Folder: " + path));
            }
            if (!deleteContents && ResourceCatalogue.GetResourceList(workSpaceId).Count(a => a.ResourcePath == path) > 0)
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, "Requested folder contains existing valid resources " + path));
            }
            if (path.Trim() == "")
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, "You may not delete the root path"));
            }
            try
            {
                path = path + "\\";
                List <ResourceCatalogResult> deletedResources = ResourceCatalogue.GetResourceList(workSpaceId)
                                                                .Where(a => a.ResourcePath.StartsWith(path))
                                                                .Select(a => ResourceCatalogue.DeleteResource(workSpaceId, a.ResourceName, a.ResourceType.ToString())).ToList();
                if (deletedResources.Any(a => a.Status != ExecStatus.Success))
                {
                    return(new ExplorerRepositoryResult(ExecStatus.Fail, "Failed to delete child items"));
                }

                Directory.Delete(DirectoryStructureFromPath(path), true);
                return(new ExplorerRepositoryResult(ExecStatus.Success, ""));
            }
            catch (Exception err)
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, err.Message));
            }
        }
Beispiel #2
0
        public IExplorerRepositoryResult DeleteItem(IExplorerItem itemToDelete, Guid workSpaceId)
        {
            if (itemToDelete == null)
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.ItemToDeleteWasNull));
            }
            if (itemToDelete.ResourceType == "Folder")
            {
                return(DeleteFolder(itemToDelete, workSpaceId));
            }
            var result = ResourceCatalogue.DeleteResource(workSpaceId, itemToDelete.ResourceId, itemToDelete.ResourceType);

            TestCatalog.DeleteAllTests(itemToDelete.ResourceId);
            if (result.Status == ExecStatus.Success)
            {
                var itemDeleted = Find(_root, itemToDelete.ResourceId);
                if (itemDeleted != null)
                {
                    var parent = Find(_root, item => item.ResourcePath == GetSavePath(itemDeleted));
                    if (parent != null)
                    {
                        parent.Children.Remove(itemDeleted);
                    }
                    else
                    {
                        _root.Children.Remove(itemDeleted);
                    }
                }
            }
            return(new ExplorerRepositoryResult(result.Status, result.Message));
        }
        public IExplorerRepositoryResult DeleteItem(IExplorerItem itemToDelete, Guid workSpaceId)
        {
            if (itemToDelete == null)
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, "Item to delete was null"));
            }
            switch (itemToDelete.ResourceType)
            {
            case ResourceType.Folder:
            {
                return(DeleteFolder(itemToDelete.ResourcePath, true, workSpaceId));
            }

            default:
                ResourceCatalogResult result = ResourceCatalogue.DeleteResource(workSpaceId, itemToDelete.DisplayName, itemToDelete.ResourceType.ToString());
                return(new ExplorerRepositoryResult(result.Status, result.Message));
            }
        }