Ejemplo n.º 1
0
        public static TemplateDefinition LoadCardDefinition(XmlNode node)
        {
            TemplateDefinition ret = new TemplateDefinition();
            ret.src = node.Attributes["src"].Value;
            if (node.Attributes["default"] != null)
            {
                ret.defaultTemplate = bool.Parse(node.Attributes["default"].Value);
            }
            foreach (XmlNode subNode in node)
            {
                if (SkipNode(subNode))
                {
                    continue;
                }
                if (subNode.Name.Equals("textblocks"))
                {
                    ret.LoadTextBlocks(subNode);
                }
                if (subNode.Name.Equals("overlayblocks"))
                {
                    ret.LoadOverlayBlocks(subNode);
                }
                if (subNode.Name.Equals("matches"))
                {
                    ret.LoadMatches(subNode);
                }
            }

            return (ret);
        }
Ejemplo n.º 2
0
 public void AddTemplate(TemplateDefinition cardDef)
 {
     if (templates.Contains(cardDef))
     {
         templates.Remove(cardDef);
     }
     templates.Add(cardDef);
 }
Ejemplo n.º 3
0
        private bool TemplateMatch(Dictionary<string, string> values, TemplateDefinition template)
        {
            bool ret = false;
            int found = 0;
            foreach (Property prop in template.Matches)
            {
                if (values.ContainsKey(prop.Name))
                {
                    if (values[prop.Name] == prop.Value)
                    {
                        found++;
                    }
                }
            }
            if (found == (template.Matches.Count))
            {
                ret = true;
            }

            return(ret);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Image GenerateProxy(BlockManager manager, string rootPath, TemplateDefinition template, Dictionary<string,string> values)
        {
            var path = Path.Combine(rootPath, template.src);
            Bitmap temp = GraphicUtils.LoadImage(path,PixelFormat.Format32bppArgb);

            using (Graphics graphics = Graphics.FromImage(temp))
            {
                foreach (LinkDefinition overlay in template.GetOverLayBlocks(values))
                {
                    BlockDefinition block = manager.GetBlock(overlay.Block);
                    if (block.type != "overlay")
                    {
                        continue;
                    }
                    block.src = Path.Combine(rootPath, block.src);
                    GraphicUtils.MergeOverlay(graphics, block);
                }

                foreach (LinkDefinition section in template.GetTextBlocks(values))
                {
                    List<Property> clonedProps = new List<Property>();
                    BlockDefinition block = manager.GetBlock(section.Block);
                    if (block.type != "text")
                    {
                        continue;
                    }
                    clonedProps.AddRange(section.NestedProperties);

                    foreach (Property prop in section.NestedProperties)
                    {
                        if (!values.ContainsKey(prop.Name))
                        {
                            clonedProps.Remove(prop);
                        }
                        if (clonedProps.Contains(prop) && (values[prop.Name] == null || values[prop.Name].Length == 0))
                        {
                            clonedProps.Remove(prop);
                        }
                    }

                    StringBuilder toWrite = new StringBuilder();
                    if (clonedProps.Count > 1)
                    {
                        for (int i = 0; i < clonedProps.Count; i++)
                        {
                            string propertyName = clonedProps[i].Name;
                            string format = clonedProps[i].Format.Replace("{}", values[propertyName]);
                            if (i < (clonedProps.Count - 1))
                            {
                                toWrite.Append(string.Format("{0} {1}", format, section.Separator));
                            }
                            else
                            {
                                toWrite.Append(format);
                            }
                        }

                    }
                    else
                    {
                        if (clonedProps.Count > 0)
                        {
                            string propertyName = clonedProps[0].Name;
                            string format = clonedProps[0].Format.Replace("{}", values[propertyName]);
                            toWrite.Append(format);
                        }
                    }
                    GraphicUtils.WriteString(graphics, block, toWrite.ToString());
                }
            }

            return (temp);
        }
Ejemplo n.º 7
0
        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 (value.Equals(NullConstant) && CheckNullConstant(values, property))
                {
                    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);
        }
Ejemplo n.º 8
0
        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);
        }