private IEnumerable <IMacro> InstallMacros(XElement macroElements, int userId = 0) { if (string.Equals(Constants.Packaging.MacrosNodeName, macroElements.Name.LocalName) == false) { throw new ArgumentException("Must be \"" + Constants.Packaging.MacrosNodeName + "\" as root", "macroElements"); } return(_packagingService.ImportMacros(macroElements, userId)); }
private async Task UnpackMacros(IEnumerable <XElement> elements) { foreach (var element in elements) { var name = (string)element.Element("name"); await Out.WriteLineFormattedAsync("Importing Macro '{0}'", name); packagingService.ImportMacros(element); } }
internal override SyncAttempt <IMacro> DeserializeCore(XElement node) { LogHelper.Debug <MacroSerializer>("<< DeserailizeCore Macro"); var item = _packaingService.ImportMacros(node).FirstOrDefault(); // other bits. if (item == null) { return(SyncAttempt <IMacro> .Fail(node.NameFromNode(), ChangeType.Import, "Package Service import failed")); } LogHelper.Debug <MacroSerializer>("<<< DeserailizeCore - General properties"); if (node.Element("name") != null) { item.Name = node.Element("name").Value; } if (node.Element("scriptType") != null) { item.ControlType = node.Element("scriptType").Value; } if (node.Element("scriptAssembly") != null) { item.ControlAssembly = node.Element("scriptAssembly").Value; } if (node.Element("xslt") != null) { item.XsltPath = node.Element("xslt").Value; } if (node.Element("scriptingFile") != null) { item.ScriptPath = node.Element("scriptingFile").Value; } LogHelper.Debug <MacroSerializer>("<<< DeserailizeCore - Defaults"); item.UseInEditor = node.Element("useInEditor").ValueOrDefault(false); item.CacheDuration = node.Element("refreshRate").ValueOrDefault(0); item.CacheByMember = node.Element("cacheByMember").ValueOrDefault(false); item.CacheByPage = node.Element("cacheByPage").ValueOrDefault(false); item.DontRender = node.Element("dontRender").ValueOrDefault(true); LogHelper.Debug <MacroSerializer>("<<< DeserailizeCore - Properties"); List <string> propertiesToRemove = new List <string>(); var properties = node.Element("properties"); if (properties != null && properties.HasElements) { foreach (var property in properties.Elements("property")) { var alias = property.Attribute("alias").Value; var itemProperty = item.Properties.FirstOrDefault(x => string.Equals(x.Alias, alias, StringComparison.OrdinalIgnoreCase) == true); if (itemProperty != null) { LogHelper.Debug <MacroSerializer>("<<< Updating Property: {0}", () => alias); itemProperty.Alias = alias; itemProperty.Name = property.Attribute("name").Value; itemProperty.EditorAlias = property.Attribute("propertyType").Value; } } } foreach (var property in item.Properties) { var nodeProp = properties.Elements("property").FirstOrDefault(x => x.Attribute("alias").Value == property.Alias); if (nodeProp == null) { propertiesToRemove.Add(property.Alias); } } if (propertiesToRemove.Any()) { foreach (var alias in propertiesToRemove) { LogHelper.Debug <MacroSerializer>("<<< Removing Property : {0}", () => alias); item.Properties.Remove(alias); } } LogHelper.Debug <MacroSerializer>("<<< DeserailizeCore - Saving"); ApplicationContext.Current.Services.MacroService.Save(item); LogHelper.Debug <MacroSerializer>("<<< DeserailizeCore - Return"); return(SyncAttempt <IMacro> .Succeed(item.Name, item, ChangeType.Import)); }