Exemplo n.º 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>());
        }
        public ICardInfoParserWorker CreateParserWorker(IAwareXmlTextReader xmlReader)
        {
            string classValue = xmlReader.GetAttribute("class");

            if (classValue == null || classValue.ToLowerInvariant() == "planeimage" || classValue.ToLowerInvariant() == "fadedcard")
            {
                return(ImageWorker.IsWorkingInfo(xmlReader.GetAttribute("id")) ? new ImageWorker() : null);
            }

            switch (classValue.ToLowerInvariant())
            {
            case "communityratings":
                return(new SkipWorker());

            case "row":
            case "row manarow":
                return(new RowWorker(xmlReader));

            case "variations":
                return(new VariationsWorker());

            default:
                return(null);
            }
        }
Exemplo n.º 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.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>());
        }
Exemplo n.º 4
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>());
        }
        public ICardInfoParserWorker CreateParserRowSubWorker(IAwareXmlTextReader xmlReader)
        {
            string classValue = xmlReader.GetAttribute("id");

            if (classValue == null)
            {
                return(null);
            }

            string lowerClassValue = classValue.ToLowerInvariant();

            if (!lowerClassValue.StartsWith("ctl00_ctl00_ctl00_maincontent_subcontent_subcontent"))
            {
                return(null);
            }

            string infoType = lowerClassValue.Substring(lowerClassValue.LastIndexOf('_') + 1);

            //ctl00_ctl00_ctl00_maincontent_subcontent_subcontent_* for normalcard
            //ctl00_ctl00_ctl00_maincontent_subcontent_subcontent_ctl03_* for part A off multi part card
            //ctl00_ctl00_ctl00_maincontent_subcontent_subcontent_ctl04_* for part B off multi part card

            switch (infoType)
            {
            case "namerow":
                return(new SimpleValueRowWorker(CardParserBase.NameKey));

            case "manarow":
                return(new ManaRowWorker());

            case "cmcrow":
                return(new SimpleValueRowWorker(CardParserBase.CmcKey));

            case "ptrow":
                return(new SimpleValueRowWorker(CardParserBase.PTKey));

            case "typerow":
                return(new SimpleValueRowWorker(CardParserBase.TypeKey));

            case "rarityrow":
                return(new SimpleValueRowWorker(CardParserBase.RarityKey));

            case "textrow":
                return(new TextRowWorker());

            //Not used
            case "setrow":
            case "numberrow":
            case "artistrow":
            case "flavorRow":
                return(null);

            default:
                return(null);
            }
        }
Exemplo n.º 6
0
        public IDictionary <string, string> WorkOnElement(IAwareXmlTextReader xmlReader)
        {
            if (xmlReader.Name == "img")
            {
                string id = xmlReader.GetAttribute("id");
                if (IsWorkingInfo(id))
                {
                    string source = xmlReader.GetAttribute("src");
                    if (string.IsNullOrWhiteSpace(source))
                    {
                        throw new ParserException("Can't find image path");
                    }

                    return(new Dictionary <string, string> {
                        { CardParserBase.ImageKey, source }
                    });
                }
            }
            return(new Dictionary <string, string>());
        }
Exemplo n.º 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>());
        }
Exemplo n.º 8
0
        internal static string Parse(IAwareXmlTextReader reader)
        {
            if (reader.NodeType == XmlNodeType.Element && reader.Name == "img")
            {
                string src = reader.GetAttribute("src");
                Match  m   = _symbolRegex.Match(src);
                if (m.Success)
                {
                    return(Prefix + m.Groups["symbol"].Value);
                }
            }

            throw new ParserException("Can't retrieve symbol");
        }
Exemplo n.º 9
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
            });
        }
Exemplo n.º 10
0
 public string GetAttribute(string key)
 {
     return(_parent != null?_parent.GetAttribute(key) : _reader.GetAttribute(key));
 }