コード例 #1
0
        void UpdateDependantResourceWithCompileMessages(Guid workspaceID, IResource resource, IList <ICompileMessageTO> messages)
        {
            var resourceId         = resource.ResourceID;
            var dependants         = _resourceCatalog.GetDependentsAsResourceForTrees(workspaceID, resourceId);
            var dependsMessageList = new List <ICompileMessageTO>();

            foreach (var dependant in dependants)
            {
                var affectedResource = _resourceCatalog.GetResource(workspaceID, dependant.ResourceID);
                foreach (var compileMessageTO in messages)
                {
                    compileMessageTO.WorkspaceID = workspaceID;
                    compileMessageTO.UniqueID    = dependant.UniqueID;
                    if (affectedResource != null)
                    {
                        compileMessageTO.ServiceName = affectedResource.ResourceName;
                        compileMessageTO.ServiceID   = affectedResource.ResourceID;
                    }
                    dependsMessageList.Add(compileMessageTO.Clone());
                }
                if (affectedResource != null)
                {
                    Common.UpdateResourceXml(_resourceCatalog, workspaceID, affectedResource, messages);
                }
            }
            CompileMessageRepo.Instance.AddMessage(workspaceID, dependsMessageList);
        }
コード例 #2
0
        ResourceCatalogResult UpdateResourceName(Guid workspaceID, IResource resource, string newName, string resourcePath)
        {
            //rename where used
            RenameWhereUsed(_resourceCatalog.GetDependentsAsResourceForTrees(workspaceID, resource.ResourceID), workspaceID, resourcePath, newName);

            //rename resource
            var resourceContents = _resourceCatalog.GetResourceContents(workspaceID, resource.ResourceID);

            var resourceElement = resourceContents.ToXElement();
            //xml name attibute
            var    nameAttrib = resourceElement.Attribute("Name");
            string oldName    = null;

            if (nameAttrib == null)
            {
                resourceElement.Add(new XAttribute("Name", newName));
            }
            else
            {
                oldName = nameAttrib.Value;
                nameAttrib.SetValue(newName);
            }
            //xaml
            var actionElement = resourceElement.Element("Action");
            var xaml          = actionElement?.Element("XamlDefinition");

            xaml?.SetValue(xaml.Value
                           .Replace("x:Class=\"" + oldName, "x:Class=\"" + newName)
                           .Replace("ToolboxFriendlyName=\"" + oldName, "ToolboxFriendlyName=\"" + newName)
                           .Replace("DisplayName=\"" + oldName, "DisplayName=\"" + newName));
            //xml display name element
            var displayNameElement = resourceElement.Element("DisplayName");

            displayNameElement?.SetValue(newName);

            //delete old resource in local workspace without updating dependants with compile messages
            lock (Common.GetFileLock(resource.FilePath))
            {
                if (_dev2FileWrapper.Exists(resource.FilePath))
                {
                    lock (Common.GetFileLock(resource.FilePath))
                    {
                        _dev2FileWrapper.Delete(resource.FilePath);
                    }
                }
            }

            var resPath = resource.GetResourcePath(workspaceID);

            var savePath          = resPath;
            var resourceNameIndex = resPath.LastIndexOf(resource.ResourceName, StringComparison.InvariantCultureIgnoreCase);

            if (resourceNameIndex >= 0)
            {
                savePath = resPath.Substring(0, resourceNameIndex);
            }
            resource.ResourceName = newName;
            var contents = resourceElement.ToStringBuilder();

            return(((ResourceCatalog)_resourceCatalog).SaveImpl(workspaceID, resource, contents, savePath));
        }