public static ConditionalDefinition LoadConditional(XmlNode node) { ConditionalDefinition ret = new ConditionalDefinition(); foreach (XmlNode subNode in node.ChildNodes) { if (TemplateDefinition.SkipNode(subNode)) { continue; } if (ret.ifNode != null && subNode.Name == "if") { break; } if (subNode.Name == "if") { ret.ifNode = subNode; } if (subNode.Name == "elseif") { ret.elseifNodeList.Add(subNode); } if (subNode.Name == "else") { ret.elseNode = subNode; } if (subNode.Name == "switch") { ret.switchNode = subNode; } } return(ret); }
public static LinkDefinition LoadLink(XmlNode node) { LinkDefinition ret = new LinkDefinition(); ret.Block = node.Attributes["block"].Value; if (node.Attributes["separator"] != null) { ret.Separator = node.Attributes["separator"].Value; } if (node.HasChildNodes) { foreach (XmlNode subNode in node.ChildNodes) { if (TemplateDefinition.SkipNode(subNode)) { continue; } Property prop = new Property(); prop.Name = subNode.Attributes["name"].Value; prop.Value = string.Empty; if (subNode.Attributes["format"] != null) { prop.Format = subNode.Attributes["format"].Value.Contains("{}") ? subNode.Attributes["format"].Value : "{}"; } ret.NestedProperties.Add(prop); } } return(ret); }
private List <LinkDefinition> ResolveCase(Dictionary <string, string> values, XmlNode node, string property, out bool breakValue) { List <LinkDefinition> ret = new List <LinkDefinition>(); string value = null; string contains = null; breakValue = true; if (node.Attributes["value"] != null) { value = node.Attributes["value"].Value; } if (node.Attributes["contains"] != null) { contains = node.Attributes["contains"].Value; } if (node.Attributes["break"] != null) { breakValue = bool.Parse(node.Attributes["break"].Value); } if (value != null) { if (values.ContainsKey(property) && values[property] == value) { foreach (XmlNode subNode in node.ChildNodes) { if (TemplateDefinition.SkipNode(subNode)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(subNode); ret.Add(link); } } } if (contains != null) { if (values.ContainsKey(property) && values[property].Contains(contains)) { foreach (XmlNode subNode in node.ChildNodes) { if (TemplateDefinition.SkipNode(subNode)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(subNode); ret.Add(link); } } } return(ret); }
internal List <LinkDefinition> LoadLinksFromNode(XmlNode node) { List <LinkDefinition> ret = new List <LinkDefinition>(); foreach (XmlNode subNode in node.ChildNodes) { if (TemplateDefinition.SkipNode(subNode)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(subNode); ret.Add(link); } return(ret); }
internal List <LinkDefinition> ResolveSwitch(Dictionary <string, string> values) { List <LinkDefinition> ret = new List <LinkDefinition>(); string property = switchNode.Attributes["property"].Value; bool currentBreak = true; bool foundMatch = false; foreach (XmlNode childNode in switchNode.ChildNodes) { if (TemplateDefinition.SkipNode(childNode)) { continue; } if (childNode.Name == "case") { List <LinkDefinition> list = ResolveCase(values, childNode, property, out currentBreak); foundMatch = (list.Count > 0); ret.AddRange(list); } if ((!foundMatch || !currentBreak) && childNode.Name == "default") { foreach (XmlNode node in childNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } foundMatch = true; currentBreak = true; } if (foundMatch && currentBreak) { break; } } return(ret); }
public static new BlockDefinition LoadSectionDefinition(BlockManager manager, XmlNode node) { BlockDefinition ret = new BlockDefinition(); ret.Manager = manager; ret.type = "overlay"; foreach (XmlNode prop in node.ChildNodes) { if (TemplateDefinition.SkipNode(prop)) { continue; } if (prop.Name.Equals("location")) { ret.location.x = int.Parse(prop.Attributes["x"].Value); ret.location.y = int.Parse(prop.Attributes["y"].Value); //if (prop.Attributes["rotate"] != null) //{ // ret.location.rotate = int.Parse(prop.Attributes["rotate"].Value); //} //if (prop.Attributes["altrotate"] != null) //{ // ret.location.altrotate = bool.Parse(prop.Attributes["altrotate"].Value); //} //if (prop.Attributes["flip"] != null) //{ // ret.location.flip = bool.Parse(prop.Attributes["flip"].Value); //} } if (prop.Name.Equals("size")) { ret.wordwrap.height = int.Parse(prop.Attributes["height"].Value); ret.wordwrap.width = int.Parse(prop.Attributes["width"].Value); } } return(ret); }
internal List <LinkDefinition> ResolveIf(Dictionary <string, string> values) { List <LinkDefinition> ret = new List <LinkDefinition>(); string property = ifNode.Attributes["property"].Value; string value = null; string contains = null; bool loadElse = false; bool foundMatch = false; if (ifNode.Attributes["value"] != null) { value = ifNode.Attributes["value"].Value; } if (ifNode.Attributes["contains"] != null) { contains = ifNode.Attributes["contains"].Value; } if (value != null) { if (values.ContainsKey(property) && values[property] == value) { foreach (XmlNode node in ifNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } foundMatch = true; } else { if (elseifNodeList.Count == 0 && ret.Count == 0) { loadElse = true; } } } if (!foundMatch) { foreach (XmlNode elseIfNode in elseifNodeList) { string elseIfValue = null; if (elseIfNode.Attributes["value"] != null) { elseIfValue = elseIfNode.Attributes["value"].Value; } if (elseIfValue != null && !foundMatch) { if (values.ContainsKey(property) && values[property] == elseIfValue) { foreach (XmlNode node in elseIfNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } loadElse = false; foundMatch = true; } } } } if (value != null && loadElse) { if (elseNode != null) { foreach (XmlNode node in elseNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } } } if (foundMatch) { return(ret); } if (contains != null) { if (values.ContainsKey(property) && values[property].Contains(contains)) { foreach (XmlNode node in ifNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } foundMatch = true; } else { if (elseifNodeList.Count == 0 && ret.Count == 0) { loadElse = true; } } } if (!foundMatch) { foreach (XmlNode elseIfNode in elseifNodeList) { string elseIfContains = null; if (elseIfNode.Attributes["value"] != null) { elseIfContains = elseIfNode.Attributes["value"].Value; } if (elseIfContains != null && !foundMatch) { if (values.ContainsKey(property) && values[property].Contains(elseIfContains)) { foreach (XmlNode node in elseIfNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } loadElse = false; foundMatch = true; } } } } if (contains != null && loadElse) { if (elseNode != null) { foreach (XmlNode node in elseNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } } } return(ret); }
public static BlockDefinition LoadSectionDefinition(BlockManager manager, XmlNode node) { BlockDefinition ret = new BlockDefinition(); ret.Manager = manager; ret.id = node.Attributes["id"].Value; ret.type = node.Attributes["type"].Value; if (node.Attributes["src"] != null) { ret.src = node.Attributes["src"].Value; } foreach (XmlNode prop in node.ChildNodes) { if (TemplateDefinition.SkipNode(prop)) { continue; } if (prop.Name.Equals("location")) { ret.location.x = int.Parse(prop.Attributes["x"].Value); ret.location.y = int.Parse(prop.Attributes["y"].Value); if (prop.Attributes["rotate"] != null) { ret.location.rotate = int.Parse(prop.Attributes["rotate"].Value); } if (prop.Attributes["altrotate"] != null) { ret.location.altrotate = bool.Parse(prop.Attributes["altrotate"].Value); } if (prop.Attributes["flip"] != null) { ret.location.flip = bool.Parse(prop.Attributes["flip"].Value); } } if (prop.Name.Equals("text")) { ret.text.color = ColorTranslator.FromHtml(prop.Attributes["color"].Value); ret.text.size = int.Parse(prop.Attributes["size"].Value); if (prop.Attributes["font"] != null) { string relativePath = prop.Attributes["font"].Value; string rootPath = manager.RootPath; string combined = Path.Combine(rootPath, relativePath); if (File.Exists(combined)) { ret.text.font = relativePath; } } } if (prop.Name.Equals("border")) { ret.border.color = ColorTranslator.FromHtml(prop.Attributes["color"].Value); ret.border.size = int.Parse(prop.Attributes["size"].Value); } if (prop.Name.Equals("wordwrap")) { ret.wordwrap.height = int.Parse(prop.Attributes["height"].Value); ret.wordwrap.width = int.Parse(prop.Attributes["width"].Value); if (prop.Attributes["align"] != null) { ret.wordwrap.align = prop.Attributes["align"].Value; } if (prop.Attributes["valign"] != null) { ret.wordwrap.valign = prop.Attributes["valign"].Value; } if (prop.Attributes["shrinktofit"] != null) { ret.wordwrap.shrinkToFit = bool.Parse(prop.Attributes["shrinktofit"].Value); } } } return(ret); }
private List <LinkDefinition> IfValue(Dictionary <string, string> values, string property, string value, out bool foundMatch) { List <LinkDefinition> ret = new List <LinkDefinition>(); bool loadElse = false; foundMatch = false; if (value != null) { if (values.ContainsKey(property) && values[property] == value) { foreach (XmlNode node in ifNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } foundMatch = true; } else { if (elseifNodeList.Count == 0 && ret.Count == 0) { loadElse = true; } } if (value.Equals(NullConstant) && CheckNullConstant(values, property)) { foreach (XmlNode node in ifNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } foundMatch = true; loadElse = false; } } if (!foundMatch) { string elseIfProperty = property; foreach (XmlNode elseIfNode in elseifNodeList) { if (elseIfNode.Attributes["property"] != null) { elseIfProperty = elseIfNode.Attributes["property"].Value; } string elseIfValue = null; if (elseIfNode.Attributes["value"] != null) { elseIfValue = elseIfNode.Attributes["value"].Value; } if (elseIfValue != null && !foundMatch) { if (values.ContainsKey(elseIfProperty) && values[elseIfProperty] == elseIfValue) { foreach (XmlNode node in elseIfNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } loadElse = false; foundMatch = true; } if (value.Equals(NullConstant) && CheckNullConstant(values, elseIfProperty)) { foreach (XmlNode node in elseIfNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } foundMatch = true; loadElse = false; } } } } if (value != null && loadElse) { if (elseNode != null) { foreach (XmlNode node in elseNode.ChildNodes) { if (TemplateDefinition.SkipNode(node)) { continue; } LinkDefinition link = LinkDefinition.LoadLink(node); ret.Add(link); } } } return(ret); }