コード例 #1
0
        protected override string ToLine(IImportExportCardCount cardCount)
        {
            //Ignore AltArt
            if (cardCount == null || (cardCount.FoilNumber == 0 && cardCount.Number == 0))
            {
                return(null);
            }

            ICard    card    = MagicDatabase.GetCard(cardCount.IdGatherer);
            IEdition edition = MagicDatabase.GetEdition(cardCount.IdGatherer);

            if (card == null || edition == null)
            {
                throw new ImportExportException("Can't find card with IdGatherer={0}", cardCount.IdGatherer);
            }

            string ret = string.Empty;

            if (cardCount.Number > 0)
            {
                ret += string.Format("{0}#{1}#{2}#False\n", card, edition.AlternativeCode(Format), cardCount.Number);
            }

            if (cardCount.FoilNumber > 0)
            {
                ret += string.Format("{0}#{1}#{2}#True\n", card, edition.AlternativeCode(Format), cardCount.FoilNumber);
            }

            return(ret);
        }
コード例 #2
0
        protected override IImportExportCardCount ParseLine(string line)
        {
            Match m = _regLine.Match(line);

            if (!m.Success)
            {
                return(new ErrorImportExportCardInfo(line, "Can't parse line"));
            }

            int count     = 0;
            int foilCount = 0;

            if (!int.TryParse(m.Groups["Count"].Value, out int tmpcount) || tmpcount <= 0)
            {
                return(new ErrorImportExportCardInfo(line, "Invalid value for count"));
            }

            if (m.Groups["Foil"].Value.ToUpper() == "TRUE")
            {
                foilCount = tmpcount;
            }
            else
            {
                count = tmpcount;
            }


            ICard card = MagicDatabase.GetCard(m.Groups["Name"].Value, null);

            if (card == null)
            {
                return(new ErrorImportExportCardInfo(line, string.Format("Can't find card named {0}", m.Groups["Name"].Value)));
            }

            IEdition edition = MagicDatabase.GetEditionFromCode(m.Groups["Edition"].Value);

            if (edition == null)
            {
                return(new ErrorImportExportCardInfo(line, string.Format("Can't find edition named {0}", m.Groups["Edition"].Value)));
            }

            int idGatherer = MagicDatabase.GetIdGatherer(card, edition);

            if (idGatherer == 0)
            {
                return(new ErrorImportExportCardInfo(line, string.Format("Can't find gatherer id for card {0} edition {1}", card, edition)));
            }

            CardCount cardCount = new CardCount
            {
                { CardCountKeys.Standard, count },
                { CardCountKeys.Foil, foilCount }
            };

            return(new ImportExportCardInfo(idGatherer, cardCount, 0));
        }
コード例 #3
0
ファイル: MpsdFormatter.cs プロジェクト: FleurLotus/MPSD
        protected override IImportExportCardCount ParseLine(string line)
        {
            Match m = _regLine.Match(line);

            if (!m.Success)
            {
                return(new ErrorImportExportCardInfo(line, "Can't parse line"));
            }
            if (!int.TryParse(m.Groups["IdGatherer"].Value, out int idGatherer) || MagicDatabase.GetCard(idGatherer) == null)
            {
                return(new ErrorImportExportCardInfo(line, "Invalid IdGatherer"));
            }
            if (!int.TryParse(m.Groups["Count"].Value, out int count) || count < 0)
            {
                return(new ErrorImportExportCardInfo(line, "Invalid Count"));
            }
            if (!int.TryParse(m.Groups["FoilCount"].Value, out int foilCount) || foilCount < 0)
            {
                return(new ErrorImportExportCardInfo(line, "Invalid FoilCount"));
            }
            int    altArtCount  = 0;
            string sAltArtCount = m.Groups["AltArtCount"].Value;

            if (!string.IsNullOrWhiteSpace(sAltArtCount))
            {
                if (!int.TryParse(m.Groups["AltArtCount"].Value, out altArtCount) || altArtCount < 0)
                {
                    return(new ErrorImportExportCardInfo(line, "Invalid AltArtCount"));
                }
            }
            int    foilAltArtCount  = 0;
            string sFoilAltArtCount = m.Groups["FoilAltArtCount"].Value;

            if (!string.IsNullOrWhiteSpace(sFoilAltArtCount))
            {
                if (!int.TryParse(m.Groups["FoilAltArtCount"].Value, out foilAltArtCount) || foilAltArtCount < 0)
                {
                    return(new ErrorImportExportCardInfo(line, "Invalid FoilAltArtCount"));
                }
            }
            if (!int.TryParse(m.Groups["Language"].Value, out int idLanguage) || MagicDatabase.GetLanguages(idGatherer).All(l => l.Id != idLanguage))
            {
                return(new ErrorImportExportCardInfo(line, "Invalid idLanguage"));
            }

            CardCount cardCount = new CardCount
            {
                { CardCountKeys.Standard, count },
                { CardCountKeys.Foil, foilCount },
                { CardCountKeys.AltArt, altArtCount },
                { CardCountKeys.FoilAltArt, foilAltArtCount }
            };

            return(new ImportExportCardInfo(idGatherer, cardCount, idLanguage));
        }