Exemple #1
0
        public IDictionary <string, string> WorkOnElement(IAwareXmlTextReader xmlReader)
        {
            if (xmlReader.Name == "div" && xmlReader.GetAttribute("class") == "value")
            {
                string value = string.Empty;
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "div" &&
                        xmlReader.GetAttribute("class") == "cardtextbox")
                    {
                        string text = WorkOnTextBox(new AwareXmlTextReader(xmlReader));
                        if (!string.IsNullOrWhiteSpace(text))
                        {
                            value += "\r\n" + text;
                        }
                    }
                }
                if (string.IsNullOrEmpty(value))
                {
                    throw new ParserException("No Text element found in Element");
                }

                return(new Dictionary <string, string> {
                    { CardParserBase.TextKey, value.HtmlTrim() }
                });
            }
            return(new Dictionary <string, string>());
        }
Exemple #2
0
        public IDictionary <string, string> WorkOnElement(IAwareXmlTextReader xmlReader)
        {
            if (xmlReader.Name == "div" && xmlReader.GetAttribute("class") == "value")
            {
                string value = null;
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Text)
                    {
                        if (!string.IsNullOrEmpty(value))
                        {
                            throw new ParserException("Multiple Text element in Element");
                        }

                        value = xmlReader.Value.HtmlTrim();
                    }
                }
                if (string.IsNullOrEmpty(value))
                {
                    throw new ParserException("No Text element found in Element for Key: " + _key);
                }

                return(new Dictionary <string, string> {
                    { _key, value }
                });
            }
            return(new Dictionary <string, string>());
        }
Exemple #3
0
        public IDictionary <string, string> WorkOnElement(IAwareXmlTextReader xmlReader)
        {
            if (xmlReader.Name == "div" && xmlReader.GetAttribute("class") == "value")
            {
                string value = null;
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "img")
                    {
                        string symbol = SymbolParser.Parse(xmlReader);
                        if (string.IsNullOrEmpty(value))
                        {
                            value = symbol;
                        }
                        else
                        {
                            value += " " + symbol;
                        }
                    }
                }
                if (string.IsNullOrEmpty(value))
                {
                    throw new ParserException("No Text element found in Element");
                }

                return(new Dictionary <string, string> {
                    { CardParserBase.ManaCostKey, value }
                });
            }
            return(new Dictionary <string, string>());
        }
Exemple #4
0
        public bool Read()
        {
            if (_level <= 0)
            {
                return(false);
            }

            bool ret = _parent != null?_parent.Read() : _reader.Read();

            if (ret)
            {
                if (NodeType == XmlNodeType.Element)
                {
                    if (!IsEmptyElement)
                    {
                        _level++;
                    }
                }

                if (NodeType == XmlNodeType.EndElement)
                {
                    _level--;
                }

                if (_level == 0 && _sourceElementName != Name)
                {
                    throw new ParserException("Closing Element is not matching opening one");
                }
            }

            return(ret);
        }
Exemple #5
0
        private IDictionary <string, string> ParseElement(IAwareXmlTextReader xmlReader, ICardInfoParserWorker worker)
        {
            IDictionary <string, string> parsedInfo = new Dictionary <string, string>();
            bool readOk = worker.WorkOnCurrentAtStart || xmlReader.Read();

            while (readOk)
            {
                if (xmlReader.NodeType == XmlNodeType.Element)
                {
                    IDictionary <string, string> workOnElement = worker.WorkOnElement(new AwareXmlTextReader(xmlReader));
                    parsedInfo.AddRange(workOnElement);
                }
                readOk = xmlReader.Read();
            }

            return(parsedInfo);
        }
Exemple #6
0
        private CardRuleInfo WorkOnRow(IAwareXmlTextReader xmlReader)
        {
            DateTime date = new DateTime();
            string   rule = null;

            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "td")
                {
                    string tdIdValue = xmlReader.GetAttribute("id");
                    if (!string.IsNullOrEmpty(tdIdValue))
                    {
                        tdIdValue = tdIdValue.ToLowerInvariant();

                        string text = WorkOnTextBox(new AwareXmlTextReader(xmlReader));
                        if (tdIdValue.EndsWith("rulingdate"))
                        {
                            DateTime.TryParseExact(text, "M/d/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
                        }
                        else if (tdIdValue.EndsWith("rulingtext"))
                        {
                            rule = text;
                        }
                    }
                }
            }

            if (rule == null || date == new DateTime())
            {
                throw new ParserException("Can't retrieve all data needed for rule");
            }

            if (string.IsNullOrWhiteSpace(rule))
            {
                //The rule text is retrieve but empty, ignore the rule
                return(null);
            }

            return(new CardRuleInfo {
                Date = date, Text = rule
            });
        }
Exemple #7
0
        public IDictionary <string, string> WorkOnElement(IAwareXmlTextReader xmlReader)
        {
            string value = string.Empty;

            if (xmlReader.Name == "div")
            {
                string id = xmlReader.GetAttribute("id");
                if (IsWorkingInfo(id))
                {
                    while (xmlReader.Read())
                    {
                        if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "a")
                        {
                            string text = xmlReader.GetAttribute("id");
                            if (!string.IsNullOrWhiteSpace(text))
                            {
                                if (!string.IsNullOrWhiteSpace(value))
                                {
                                    value += Separator;
                                }

                                value += text;
                            }
                        }
                    }
                }

                if (string.IsNullOrEmpty(value))
                {
                    throw new ParserException("No A element found in Element");
                }

                return(new Dictionary <string, string> {
                    { CardParserBase.VariationsKey, value }
                });
            }
            return(new Dictionary <string, string>());
        }
Exemple #8
0
        private string WorkOnTextBox(IAwareXmlTextReader xmlReader)
        {
            string value = string.Empty;

            while (xmlReader.Read())
            {
                string text = null;
                if (xmlReader.NodeType == XmlNodeType.Text)
                {
                    text = xmlReader.Value.HtmlTrim();
                }
                else if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == "img")
                {
                    text = SymbolParser.Parse(xmlReader);
                }

                if (!string.IsNullOrWhiteSpace(text))
                {
                    value += " " + text;
                }
            }

            return(value.HtmlTrim());
        }