示例#1
0
        public ResourceCatalogResult SaveImpl(Guid workspaceID, IResource resource, StringBuilder contents, bool overwriteExisting, string savedPath, string reason)
        {
            ResourceCatalogResult saveResult = null;

            Dev2.Common.Utilities.PerformActionInsideImpersonatedContext(Dev2.Common.Utilities.ServerUser, () => { PerformSaveResult(out saveResult, workspaceID, resource, contents, overwriteExisting, savedPath, reason); });
            return(saveResult);
        }
示例#2
0
        public ResourceCatalogResult SaveResources(Guid workspaceID, List <DuplicateResourceTO> resourceMap, bool overrideExisting, string reason, string user)
        {
            ResourceCatalogResult saveResult = null;

            Dev2.Common.Utilities.PerformActionInsideImpersonatedContext(Dev2.Common.Utilities.ServerUser, () => { PerformSaveBulkResult(out saveResult, workspaceID, resourceMap, overrideExisting, user, reason); });
            return(saveResult);
        }
示例#3
0
        public ResourceCatalogResult SaveResource(Guid workspaceID, IResource resource, StringBuilder contents, string savedPath, string reason, string user)
        {
            _serverVersionRepository.StoreVersion(resource, user, reason, workspaceID, savedPath);
            ResourceCatalogResult saveResult = null;

            Dev2.Common.Utilities.PerformActionInsideImpersonatedContext(Dev2.Common.Utilities.ServerUser, () => { PerformSaveResult(out saveResult, workspaceID, resource, contents, true, savedPath); });
            return(saveResult);
        }
示例#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);
                }
            }
        }
示例#5
0
        void PerformSaveBulkResult(out ResourceCatalogResult saveResult, Guid workspaceID, List <DuplicateResourceTO> resourceMap, bool overwriteExisting, string user = "", string reason = "")
        {
            var resourceResults = new List <ResourceCatalogResult>();

            foreach (var mapper in resourceMap)
            {
                var resource    = mapper.NewResource;
                var destination = mapper.DestinationPath;
                var content     = mapper.ResourceContents;

                _serverVersionRepository.StoreVersion(resource, user, reason, workspaceID, destination);
                PerformSaveResult(out saveResult, workspaceID, resource, content, overwriteExisting, destination, reason);
                ServerExplorerRepository.Instance.UpdateItem(resource);
                resourceResults.Add(saveResult);
            }
            //TODO: all these results should be returned with this method
            saveResult = resourceResults.Last();
        }
        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;
                }
            }
        }