Ejemplo n.º 1
0
        ResourceCatalogResult PerformUpdate(Guid workspaceID, string oldCategory, string newCategory, IEnumerable <IResource> resourcesToUpdate)
        {
            try
            {
                var hasError = false;
                foreach (var resource in resourcesToUpdate.ToList())
                {
                    var resourceCatalogResult = UpdateResourcePath(workspaceID, resource, oldCategory, newCategory);
                    if (resourceCatalogResult.Status != ExecStatus.Success)
                    {
                        hasError = true;
                    }
                }

                var failureResult = ResourceCatalogResultBuilder.CreateFailResult($"<CompilerMessage>Failed to Category from \'{oldCategory}\' to \'{newCategory}\'</CompilerMessage>");
                var successResult = ResourceCatalogResultBuilder.CreateSuccessResult($"<CompilerMessage>Updated Category from \'{oldCategory}\' to \'{newCategory}\'</CompilerMessage>");

                return(hasError ? failureResult : successResult);
            }
            catch (Exception err)
            {
                Dev2Logger.Error("Rename Category error", err, GlobalConstants.WarewolfError);
                return(ResourceCatalogResultBuilder.CreateFailResult($"<CompilerMessage>Failed to Category from \'{oldCategory}\' to \'{newCategory}\'</CompilerMessage>"));
            }
        }
Ejemplo n.º 2
0
        public ResourceCatalogResult RenameResource(Guid workspaceID, Guid?resourceID, string newName, string resourcePath)
        {
            GlobalConstants.HandleEmptyParameters(resourceID, "resourceID");
            GlobalConstants.HandleEmptyParameters(newName, "newName");
            var resourcesToUpdate = _resourceCatalog.GetResources(workspaceID).Where(resource => resource.ResourceID == resourceID).ToArray();

            try
            {
                if (!resourcesToUpdate.Any())
                {
                    return(ResourceCatalogResultBuilder.CreateFailResult($"{ErrorResource.FailedToFindResource} '{resourceID}' to '{newName}'"));
                }
                _versionRepository.StoreVersion(_resourceCatalog.GetResource(Guid.Empty, resourceID.Value), "unknown", "Rename", workspaceID, resourcePath);

                //rename and save to workspace
                var renameResult = UpdateResourceName(workspaceID, resourcesToUpdate[0], newName, resourcePath);
                if (renameResult.Status != ExecStatus.Success)
                {
                    return(ResourceCatalogResultBuilder.CreateFailResult($"{ErrorResource.FailedToRenameResource} '{resourceID}' to '{newName}'"));
                }
            }
            catch (Exception err)
            {
                Dev2Logger.Error(err, GlobalConstants.WarewolfError);
                return(ResourceCatalogResultBuilder.CreateFailResult($"{ErrorResource.FailedToRenameResource} '{resourceID}' to '{newName}'"));
            }
            return(ResourceCatalogResultBuilder.CreateSuccessResult($"Renamed Resource \'{resourceID}\' to \'{newName}\'"));
        }
Ejemplo n.º 3
0
        private ResourceCatalogResult DeleteImpl(Guid workspaceID, IEnumerable <IResource> resources, List <IResource> workspaceResources, bool deleteVersions = true)
        {
            IResource resource = resources.FirstOrDefault();

            if (workspaceID == Guid.Empty && deleteVersions)
            {
                if (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)
            {
                if (resource != null)
                {
                    ServiceActionRepo.Instance.RemoveFromCache(resource.ResourceID);
                    ServerAuthorizationService.Instance.Remove(resource.ResourceID);
                }
            }

            ((ResourceCatalog)_resourceCatalog).RemoveFromResourceActivityCache(workspaceID, resource);
            return(ResourceCatalogResultBuilder.CreateSuccessResult("Success"));
        }
Ejemplo n.º 4
0
        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);
                }
            }
        }
Ejemplo n.º 5
0
 public ResourceCatalogResult DeleteResource(Guid workspaceID, Guid resourceID, string type, bool deleteVersions)
 {
     try
     {
         if (workspaceID != GlobalConstants.ServerWorkspaceID)
         {
             return(DeleteFromWorkspace(workspaceID, resourceID, type, deleteVersions));
         }
         foreach (var wid in _resourceCatalog.WorkspaceResources.Keys)
         {
             var result = DeleteFromWorkspace(wid, resourceID, type, deleteVersions);
             if (wid == GlobalConstants.ServerWorkspaceID && result.Status != ExecStatus.Success)
             {
                 return(result);
             }
         }
         return(ResourceCatalogResultBuilder.CreateSuccessResult("Success"));
     }
     catch (Exception err)
     {
         Dev2Logger.Error("Delete Error", err, GlobalConstants.WarewolfError);
         throw;
     }
 }
        private void PerformSaveResult(out ResourceCatalogResult saveResult, Guid workspaceID, IResource resource, StringBuilder contents, bool overwriteExisting, string savedPath)
        {
            var fileManager = new TxFileManager();

            using (TransactionScope tx = new TransactionScope())
            {
                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;
                    }
                    var res = resources.FirstOrDefault(p => p.ResourceID == resource.ResourceID);
                    if (res != null)                                   //Found Existing resource
                    {
                        if (res.ResourceName != resource.ResourceName) // Renamed while open
                        {
                            var resourceXml = contents.ToXElement();
                            resourceXml.SetAttributeValue("Name", res.ResourceName);
                            resourceXml.SetElementValue("DisplayName", res.ResourceName);
                            var actionElement = resourceXml.Element("Action");
                            var xamlElement   = actionElement?.Element("XamlDefinition");
                            if (xamlElement != null)
                            {
                                var xamlContent = xamlElement.Value;
                                xamlElement.Value = xamlContent.
                                                    Replace("x:Class=\"" + resource.ResourceName + "\"", "x:Class=\"" + res.ResourceName + "\"")
                                                    .Replace("Flowchart DisplayName=\"" + resource.ResourceName + "\"", "Flowchart DisplayName=\"" + res.ResourceName + "\"");
                            }
                            resource.ResourceName = res.ResourceName;
                            contents = resourceXml.ToStringBuilder();
                        }
                    }
                    var directoryName = SetResourceFilePath(workspaceID, resource, ref savedPath);

                    #region Save to disk

                    var xml = SaveToDisk(resource, contents, directoryName, fileManager);

                    #endregion

                    #region Add to catalog

                    var updated = AddToCatalog(resource, resources, fileManager, xml);

                    #endregion
                    Dev2Logger.Debug($"Removing Execution Plan for {resource.ResourceID} for workspace {workspaceID}");
                    ((ResourceCatalog)_resourceCatalog).RemoveFromResourceActivityCache(workspaceID, resource);
                    Dev2Logger.Debug($"Removed Execution Plan for {resource.ResourceID} for workspace {workspaceID}");
                    Dev2Logger.Debug($"Adding Execution Plan for {resource.ResourceID} for workspace {workspaceID}");
                    ((ResourceCatalog)_resourceCatalog).Parse(workspaceID, resource.ResourceID);
                    Dev2Logger.Debug($"Added Execution Plan for {resource.ResourceID} for workspace {workspaceID}");
                    tx.Complete();
                    saveResult = ResourceCatalogResultBuilder.CreateSuccessResult($"{(updated ? "Updated" : "Added")} {resource.ResourceType} '{resource.ResourceName}'");
                }
                catch (Exception)
                {
                    Transaction.Current.Rollback();
                    throw;
                }
            }
        }