void PerformSaveResult(out ResourceCatalogResult saveResult, Guid workspaceID, IResource resource, StringBuilder contents, bool overwriteExisting, string savedPath, string reason = "") { var fileManager = new TxFileManager(); using (TransactionScope tx = new TransactionScope(TransactionScopeOption.RequiresNew)) { try { var resources = _resourceCatalog.GetResources(workspaceID); var conflicting = resources.FirstOrDefault(r => resource.ResourceID != r.ResourceID && r.GetResourcePath(workspaceID) != null && r.GetResourcePath(workspaceID).Equals(savedPath + "\\" + resource.ResourceName, StringComparison.InvariantCultureIgnoreCase) && r.ResourceName.Equals(resource.ResourceName, StringComparison.InvariantCultureIgnoreCase)); if (conflicting != null && !conflicting.IsNewResource || conflicting != null && !overwriteExisting) { saveResult = ResourceCatalogResultBuilder.CreateDuplicateMatchResult(string.Format(ErrorResource.TypeConflict, conflicting.ResourceType)); return; } contents = GetExistingResource(resource, contents, reason, resources); var directoryName = SetResourceFilePath(workspaceID, resource, ref savedPath); var xml = SaveToDisk(resource, contents, directoryName, fileManager); var updated = AddToCatalog(resource, resources, fileManager, xml); _resourceCatalog.AddToActivityCache(resource); Dev2Logger.Debug($"Removing Execution Plan for {resource.ResourceID} for workspace {workspaceID}", GlobalConstants.WarewolfDebug); _resourceCatalog.RemoveFromResourceActivityCache(workspaceID, resource); Dev2Logger.Debug($"Removed Execution Plan for {resource.ResourceID} for workspace {workspaceID}", GlobalConstants.WarewolfDebug); Dev2Logger.Debug($"Adding Execution Plan for {resource.ResourceID} for workspace {workspaceID}", GlobalConstants.WarewolfDebug); _resourceCatalog.Parse(workspaceID, resource); Dev2Logger.Debug($"Added Execution Plan for {resource.ResourceID} for workspace {workspaceID}", GlobalConstants.WarewolfDebug); tx.Complete(); saveResult = ResourceCatalogResultBuilder.CreateSuccessResult($"{(updated ? "Updated" : "Added")} {resource.ResourceType} '{resource.ResourceName}'"); } catch (Exception e) { Dev2Logger.Warn($"Error saving {resource.ResourceName}. " + e.Message, GlobalConstants.WarewolfWarn); Transaction.Current.Rollback(); //the process should not be terminated because of just one failure saveResult = ResourceCatalogResultBuilder.CreateFailResult(string.Format(ErrorResource.ErrorDuringSaveCallback, resource.ResourceID) + "' message " + e.Message); } } }
ResourceCatalogResult DeleteImpl(Guid workspaceID, IEnumerable <IResource> resources, List <IResource> workspaceResources, bool deleteVersions = true) { var resource = resources.FirstOrDefault(); if (workspaceID == Guid.Empty && deleteVersions && resource != null) { var explorerItems = _serverVersionRepository.GetVersions(resource.ResourceID); explorerItems?.ForEach(a => _serverVersionRepository.DeleteVersion(resource.ResourceID, a.VersionInfo.VersionNumber, resource.GetResourcePath(workspaceID))); } workspaceResources.Remove(resource); if (resource != null && _dev2FileWrapper.Exists(resource.FilePath)) { _dev2FileWrapper.Delete(resource.FilePath); } if (resource != null) { var messages = new List <ICompileMessageTO> { new CompileMessageTO { ErrorType = ErrorType.Critical, MessageID = Guid.NewGuid(), MessagePayload = "The resource has been deleted", MessageType = CompileMessageType.ResourceDeleted, ServiceID = resource.ResourceID } }; UpdateDependantResourceWithCompileMessages(workspaceID, resource, messages); } if (workspaceID == GlobalConstants.ServerWorkspaceID && resource != null) { ServiceActionRepo.Instance.RemoveFromCache(resource.ResourceID); ServerAuthorizationService.Instance.Remove(resource.ResourceID); } _resourceCatalog.RemoveFromResourceActivityCache(workspaceID, resource); return(ResourceCatalogResultBuilder.CreateSuccessResult("Success")); }