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));
            }
        }
        IExplorerRepositoryResult RenameExplorerItem(IExplorerItem itemToRename, Guid workSpaceId)
        {
            IEnumerable <IResource> item =
                ResourceCatalogue.GetResourceList(workSpaceId)
                .Where(
                    a =>
                    (a.ResourceName == itemToRename.DisplayName.Trim()) &&
                    (a.ResourceID == itemToRename.ResourceId));

            if (item.Any())
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.ItemAlreadyExistInPath));
            }
            ResourceCatalogResult result = ResourceCatalogue.RenameResource(workSpaceId, itemToRename.ResourceId, itemToRename.DisplayName, itemToRename.ResourcePath);

            return(new ExplorerRepositoryResult(result.Status, result.Message));
        }
        private ResourceCatalogResult RenameChildrenPaths(string oldPath, string newName)
        {
            var resourcesToRename =
                ResourceCatalogue.GetResourceList(GlobalConstants.ServerWorkspaceID)
                .Where(a => a.GetResourcePath(GlobalConstants.ServerWorkspaceID).StartsWith(oldPath)).ToList();

            if (resourcesToRename.Count == 0)
            {
                var resourceCatalogResult = new ResourceCatalogResult {
                    Status = ExecStatus.Success
                };
                return(resourceCatalogResult);
            }
            ResourceCatalogResult result = ResourceCatalogue.RenameCategory(GlobalConstants.ServerWorkspaceID, oldPath, newName, resourcesToRename);

            return(result);
        }
        IExplorerRepositoryResult RenameExplorerItem(IExplorerItem itemToRename, Guid workSpaceId)
        {
            IEnumerable <IResource> item =
                ResourceCatalogue.GetResourceList(workSpaceId)
                .Where(
                    a =>
                    (a.ResourceName == itemToRename.DisplayName.Trim()) &&
                    (a.ResourcePath == itemToRename.ResourcePath.Trim()));

            if (item.Any())
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, "There is an item that exists with the same name and path"));
            }
            ResourceCatalogResult result = ResourceCatalogue.RenameResource(workSpaceId, itemToRename.ResourceId, itemToRename.DisplayName);

            return(new ExplorerRepositoryResult(result.Status, result.Message));
        }
        public IExplorerRepositoryResult MoveItem(IExplorerItem itemToMove, string newPath, Guid workSpaceId)
        {
            IEnumerable <IResource> item =
                ResourceCatalogue.GetResourceList(workSpaceId)
                .Where(
                    a =>
                    (a.ResourcePath == newPath));

            if (item.Any())
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, "There is an item that exists with the same name and path"));
            }
            MoveVersions(itemToMove, newPath);
            ResourceCatalogResult result = ResourceCatalogue.RenameCategory(workSpaceId, itemToMove.ResourcePath, newPath, new List <IResource> {
                ResourceCatalogue.GetResource(workSpaceId, itemToMove.ResourceId)
            });

            _file.Delete(string.Format("{0}.xml", DirectoryStructureFromPath(itemToMove.ResourcePath)));

            return(new ExplorerRepositoryResult(result.Status, result.Message));
        }
        public IExplorerRepositoryResult MoveItem(IExplorerItem itemToMove, string newPath, Guid workSpaceId)
        {
            if (itemToMove.ResourceType == "Folder")
            {
                var movePath = itemToMove.DisplayName;
                if (!string.IsNullOrWhiteSpace(newPath))
                {
                    movePath = newPath + "\\" + itemToMove.DisplayName;
                }
                var oldPath = itemToMove.ResourcePath;
                Directory.Move(DirectoryStructureFromPath(oldPath), DirectoryStructureFromPath(movePath));
                MoveChildren(itemToMove, newPath);
                return(new ExplorerRepositoryResult(ExecStatus.Success, ""));
            }
            IEnumerable <IResource> item = ResourceCatalogue.GetResourceList(workSpaceId).Where(a => a.GetResourcePath(workSpaceId) == newPath);

            if (item.Any())
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.ItemAlreadyExistInPath));
            }
            return(MoveSingeItem(itemToMove, newPath, workSpaceId));
        }
        public IExplorerRepositoryResult DeleteFolder(string path, bool deleteContents, Guid workSpaceId)
        {
            if (!Directory.Exists(DirectoryStructureFromPath(path)))
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, string.Format(ErrorResource.RequestedFolderDoesNotExistOnServer, path)));
            }
            var resourceList = ResourceCatalogue.GetResourceList(workSpaceId);

            if (!deleteContents && resourceList.Count(a => a.GetResourcePath(workSpaceId) == path) > 0)
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, string.Format(ErrorResource.RequestedFolderDoesNotExistOnServer, path)));
            }
            if (path.Trim() == "")
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.CannotDeleteRootPath));
            }
            try
            {
                var testResourceIDsToDelete = resourceList.Where(resource => resource.GetResourcePath(workSpaceId).StartsWith(path));
                var guids = testResourceIDsToDelete.Select(resourceToDelete => resourceToDelete.ResourceID);
                Directory.Delete(DirectoryStructureFromPath(path), true);


                foreach (var guid in guids)
                {
                    TestCatalog.DeleteAllTests(guid);
                }


                return(new ExplorerRepositoryResult(ExecStatus.Success, ""));
            }
            catch (Exception err)
            {
                return(new ExplorerRepositoryResult(ExecStatus.Fail, err.Message));
            }
        }