IDev2Activity LoadResource(Guid resourceId) { Dev2Logger.Debug("Getting Resource to Execute", GlobalConstants.WarewolfDebug); var startActivity = _resourceCatalog.Parse(_workspace.ID, resourceId); startActivity = CloneResource(startActivity); if (startActivity is null) { throw new InvalidOperationException(GlobalConstants.NoStartNodeError); } Dev2Logger.Debug("Got Resource to Execute", GlobalConstants.WarewolfDebug); return(startActivity); }
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); } } }