private List <IResource> GetResourcesToMoveFrom(string sourceLocation) { var resourceList = _resourceCatalog.GetResourceList(GlobalConstants.ServerWorkspaceID); return(resourceList.Where( resource => { var upper = resource.GetResourcePath(GlobalConstants.ServerWorkspaceID).ToUpper(); return upper.StartsWith(sourceLocation.ToUpper()); }).Where(resource => !(resource is ManagementServiceResource)).ToList()); }
public void GetSource(Guid sourceId) { if (Source == null) { var dbSources = _catalog.GetResourceList <DbSource>(GlobalConstants.ServerWorkspaceID); Source = dbSources.Cast <TSource>().FirstOrDefault(p => p.ResourceID.Equals(sourceId)); if (Source == null) { _errorResult.AddError(string.Format(ErrorResource.ErrorRetrievingDBSourceForResource, Service?.Source?.ResourceID, Service?.Source?.ResourceName)); } } }
IEnumerable <IExplorerItem> SaveFolders(string sourceLocation, string destination, string newName, bool fixRefences) { var resourcesToUpdate = new List <IResource>(); var resourceUpdateMap = new Dictionary <Guid, Guid>(); var resourceList = _resourceCatalog.GetResourceList(GlobalConstants.ServerWorkspaceID); var items = new List <IExplorerItem>(); var resourceToMove = resourceList.Where(resource => { var upper = resource.GetResourcePath(GlobalConstants.ServerWorkspaceID).ToUpper(); return(upper.StartsWith(sourceLocation.ToUpper())); }).Where(resource => !(resource is ManagementServiceResource)).ToList(); var destPath = destination + "\\" + newName; var actualPath = destPath.TrimStart('\\'); var trimEnd = destination.TrimStart('\\').TrimEnd('\\'); var parentItem = ServerExplorerRepository.Instance.Find(item => item.ResourcePath.ToLowerInvariant().TrimEnd('\\').Equals(trimEnd)); if (parentItem == null) { var itemToAdd = new ServerExplorerItem(newName, Guid.NewGuid(), "Folder", new List <IExplorerItem>(), Permissions.Contribute, actualPath) { IsFolder = true }; ServerExplorerRepository.Instance.AddItem(itemToAdd, GlobalConstants.ServerWorkspaceID); items.Add(itemToAdd); } else { var itemToAdd = new ServerExplorerItem(newName, Guid.NewGuid(), "Folder", new List <IExplorerItem>(), Permissions.Contribute, actualPath) { IsFolder = true, Parent = parentItem }; parentItem.Children.Add(itemToAdd); items.Add(itemToAdd); } foreach (var resource in resourceToMove) { try { var result = _resourceCatalog.GetResourceContents(GlobalConstants.ServerWorkspaceID, resource.ResourceID); var xElement = result.ToXElement(); var newResource = new Resource(xElement) { IsUpgraded = true }; var newResourceId = Guid.NewGuid(); var oldResourceId = resource.ResourceID; newResource.ResourceID = newResourceId; var fixedResource = xElement.ToStringBuilder(); var resourcePath = resource.GetResourcePath(GlobalConstants.ServerWorkspaceID); var savePath = resourcePath; var resourceNameIndex = resourcePath.LastIndexOf(resource.ResourceName, StringComparison.InvariantCultureIgnoreCase); if (resourceNameIndex >= 0) { savePath = resourcePath.Substring(0, resourceNameIndex); } savePath = savePath.ReplaceFirst(sourceLocation, destPath); var subActualPath = savePath.TrimStart('\\'); var subTrimEnd = subActualPath.TrimStart('\\').TrimEnd('\\'); var idx = subTrimEnd.LastIndexOf("\\", StringComparison.InvariantCultureIgnoreCase); var name = subTrimEnd.Substring(idx + 1); var subItem = ServerExplorerRepository.Instance.Find(item => item.ResourcePath.ToLowerInvariant().TrimEnd('\\').Equals(subTrimEnd)); var itemToAdd = new ServerExplorerItem(name, Guid.NewGuid(), "Folder", new List <IExplorerItem>(), Permissions.Contribute, subTrimEnd) { IsFolder = true, Parent = subItem }; ServerExplorerRepository.Instance.AddItem(itemToAdd, GlobalConstants.ServerWorkspaceID); _resourceCatalog.SaveResource(GlobalConstants.ServerWorkspaceID, newResource, fixedResource, savePath); resourcesToUpdate.Add(newResource); resourceUpdateMap.Add(oldResourceId, newResourceId); SaveTests(oldResourceId, newResourceId); ServerExplorerRepository.Instance.UpdateItem(newResource); } catch (Exception e) { Dev2Logger.Error(e.Message, e, GlobalConstants.WarewolfError); } } if (fixRefences) { try { using (var tx = new TransactionScope()) { FixReferences(resourcesToUpdate, resourceUpdateMap); tx.Complete(); } } catch (Exception e) { Transaction.Current.Rollback(); throw new Exception("Failure Fixing references", e); } } return(items); }