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);
            }
        }
示例#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>());
        }
示例#3
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>());
        }
示例#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>());
        }
示例#5
0
        public IDictionary <string, string> WorkOnElement(IAwareXmlTextReader xmlReader)
        {
            if (_innerWorker == null)
            {
                return(new Dictionary <string, string>());
            }

            return(_innerWorker.WorkOnElement(new AwareXmlTextReader(xmlReader)));
        }
        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);
            }
        }
示例#7
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");
        }
示例#8
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);
        }
示例#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
            });
        }
示例#10
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>());
        }
示例#11
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>());
        }
示例#12
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());
        }
示例#13
0
 public IDictionary <string, string> WorkOnElement(IAwareXmlTextReader xmlReader)
 {
     //Do nothing only skip elements
     return(new Dictionary <string, string>());
 }
示例#14
0
 public RowWorker(IAwareXmlTextReader xmlReader)
 {
     _innerWorker = CardInfoParserWorkerFactory.Instance.CreateParserRowSubWorker(xmlReader);
 }
示例#15
0
 public AwareXmlTextReader(IAwareXmlTextReader parent)
 {
     _sourceElementName = parent.Name;
     _parent            = parent;
 }