ResourceCatalogResult CompileAndSave(Guid workspaceID, IResource resource, StringBuilder contents, string savedPath = "", string reason = "") { // Find the service before edits ;) var beforeService = _resourceCatalog.GetDynamicObjects <DynamicService>(workspaceID, resource.ResourceID).FirstOrDefault(); ServiceAction beforeAction = null; if (beforeService != null) { beforeAction = beforeService.Actions.FirstOrDefault(); if (reason?.Equals(GlobalConstants.SaveReasonForDeploy) ?? false) { beforeService.DisplayName = resource.ResourceName; beforeService.Name = resource.ResourceName; } } var result = _resourceCatalog.SaveImpl(workspaceID, resource, contents, savedPath, reason); if (result != null && result.Status == ExecStatus.Success) { if (workspaceID == GlobalConstants.ServerWorkspaceID) { CompileTheResourceAfterSave(workspaceID, resource, contents, beforeAction); UpdateResourceDependencies(resource, contents); SavedResourceCompileMessage(workspaceID, resource, result.Message); } if (ResourceSaved != null && workspaceID == GlobalConstants.ServerWorkspaceID) { ResourceSaved(resource); } } return(result); }
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.SaveImpl(workspaceID, resource, contents, savePath)); }