Esempio n. 1
0
        public static void PatchPotentialVersionCardData(IEnumerable <MagicCardDefinition> cards)
        {
            var result = new StringBuilder();

            ////var swamps = StaticMagicData.CardDefinitions.Where(c => c.NameEN.IndexOf("swamp", StringComparison.InvariantCultureIgnoreCase) >= 0 && c.SetCode == "RTR")
            ////    .ToList();

            var grouped = cards
                          .GroupBy(c => StaticMagicData.MakeNameSetCode(c.SetCode, c.NameMkm, ""))
                          .Where(g => g.Count() > 1)
                          .ToList();

            foreach (var group in grouped)
            {
                int version = 1;
                foreach (var item in group.OrderBy(c => c.NameMkm).ThenBy(c => c.CardId))
                {
                    item.NameMkm = item.NameMkm + " (Version " + version + ")";
                    ////result.AppendFormat("{0}, {1} (Version {4}) {2}", item.CardId, item.NameMkm, item.SetCode, item.NumberInSet, version);
                    ////result.AppendLine();

                    version++;
                }
            }
        }
Esempio n. 2
0
        public IEnumerable <MagicBinderCardViewModel> ReadFileContent(string content)
        {
            var result = new List <MagicBinderCardViewModel>();

            var groupedCards = StaticMagicData.CardDefinitions.GroupBy(d => d.SetCode).ToList();

            MagicSetDefinition  set        = null;
            MagicCardDefinition definition = null;
            string lastSetCodeName;

            using (var inputCsv = new CsvReader(new StringReader(content)))
            {
                while (inputCsv.Read())
                {
                    var card = new MagicBinderCard()
                    {
                        Quantity      = inputCsv.GetField <int>("Count"),
                        QuantityTrade = inputCsv.GetField <int>("Tradelist Count"),
                        Grade         = inputCsv.GetField <string>("Condition").ToMagicGrade(),
                        IsFoil        = inputCsv.GetField <string>("Foil") == "foil",
                        Language      = inputCsv.GetField <string>("Language").ToMagicLanguage()
                    };

                    var cardNumber = inputCsv.GetField <string>("Card Number");
                    var cardName   = inputCsv.GetField <string>("Name");
                    var setName    = inputCsv.GetField <string>("Edition");
                    if (set == null || !set.Name.Equals(setName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!StaticMagicData.SetDefinitionsBySetName.TryGetValue(setName, out set))
                        {
                            // TODO: Handle error

                            _notificationCenter.FireNotification(LogLevel.Error, string.Format("Cannot find set for card {0} ({1})", cardName, setName));
                            continue;
                        }
                    }

                    var setCodeName = StaticMagicData.MakeNameSetCode(set.Code, cardName, cardNumber);
                    lastSetCodeName = setCodeName;

                    if (!StaticMagicData.CardDefinitionsByNameSetCode.TryGetValue(setCodeName, out definition))
                    {
                        _notificationCenter.FireNotification(LogLevel.Error, string.Format("Cannot find card {0} ({1})", cardName, setName));
                        continue;
                    }

                    result.Add(new MagicBinderCardViewModel(definition, card));
                }
            }

            return(result);
        }
Esempio n. 3
0
        private static void MainOld(string[] args)
        {
            var exeFolder = PathHelper.ExeFolder;
            MagicSetDefinition lastSet = null;

            var relativeToSource = @"..\..\..\MyMagicCollection.Shared";

            var exportFileName = Path.Combine(exeFolder, relativeToSource, "CSV", "MagicDatabase.csv");

            if (File.Exists(exportFileName))
            {
                File.Delete(exportFileName);
            }

            var exportSetFileName = Path.Combine(exeFolder, relativeToSource, "CSV", "MagicDatabaseSets.csv");

            if (File.Exists(exportSetFileName))
            {
                File.Delete(exportSetFileName);
            }

            int count      = 0;
            var inputFiles = Directory.EnumerateFiles(exeFolder, "set_*.csv", SearchOption.AllDirectories).ToList();

            var textWriter = new StreamWriter(exportFileName);

            var config = new CsvConfiguration()
            {
                Encoding        = Encoding.UTF8,
                HasHeaderRecord = true,
                CultureInfo     = CultureInfo.InvariantCulture,
            };

            // config.RegisterClassMap(new MagicCardDefinitionCsvMapper());

            var availableSets = new Dictionary <string, MagicSetDefinition>();

            var writer = new CsvWriter(textWriter, config);

            writer.WriteHeader <MagicCardDefinition>();

            var setWriter = new CsvWriter(new StreamWriter(exportSetFileName), config);

            setWriter.WriteField <string>("Code");
            setWriter.WriteField <string>("Name");
            setWriter.WriteField <string>("CodeMagicCardsInfo");
            setWriter.WriteField <string>("ReleaseDate");
            setWriter.WriteField <string>("Block");
            setWriter.WriteField <string>("IsPromoEdition");
            setWriter.NextRecord();

            var uniqueList = new Dictionary <string, string>();

            // Write Tokens:
            writer.WriteRecords(TokenDefinitions.TockenDefinition);

            foreach (var inputCsvName in inputFiles)
            {
                Console.WriteLine("Reading file " + new FileInfo(inputCsvName).Name);
                var inputCsv = new CsvReader(new StringReader(File.ReadAllText(inputCsvName)));
                inputCsv.Configuration.Delimiter = "||";

                while (inputCsv.Read())
                {
                    count += 1;

                    var setCode = PatchSetCode(inputCsv.GetField <string>("set_code"));

                    var card = new MagicCardDefinition();
                    card.NameDE = inputCsv.GetField <string>("name_DE");
                    card.NameEN = inputCsv.GetField <string>("name");

                    card.CardId                  = inputCsv.GetField <string>("id");
                    card.CardType                = inputCsv.GetField <string>("type");
                    card.MagicCardType           = GetCardType(card.CardType);
                    card.NumberInSet             = SafeGetInt(inputCsv, "number_int").ToString();
                    card.LegalityModern          = ComputeLegality(inputCsv.GetField <string>("legality_Modern"));
                    card.LegalityStandard        = ComputeLegality(inputCsv.GetField <string>("legality_Standard"));
                    card.LegalityLegacy          = ComputeLegality(inputCsv.GetField <string>("legality_Legacy"));
                    card.LegalityVintage         = ComputeLegality(inputCsv.GetField <string>("legality_Vintage"));
                    card.LegalityPauper          = ComputeLegality(inputCsv.GetField <string>("legality_Pauper"));
                    card.LegalityCommander       = ComputeLegality(inputCsv.GetField <string>("legality_Commander"));
                    card.LegalityFrenchCommander = ComputeLegality(inputCsv.GetField <string>("legality_French_Commander"));
                    card.Rarity                  = CardDatabaseHelper.ComputeRarity(inputCsv.GetField <string>("rarity"));
                    card.ManaCost                = inputCsv.GetField <string>("manacost");
                    card.ConvertedManaCost       = CardDatabaseHelper.ComputeConvertedManaCost(inputCsv.GetField <string>("converted_manacost"));

                    if (!IsSetIncluded(setCode))
                    {
                        continue;
                    }

                    // TODO: Add Patch for MKM Name (multiple versions, etc.)
                    string mkmName = null;
                    if (PatchCardDefinitions.PatchMkmCardDefinition.TryGetValue(card.CardId, out mkmName))
                    {
                        card.NameMkm = mkmName;
                    }
                    //else
                    //{
                    //	card.NameMkm = card.NameEN;
                    //}

                    card.RulesText = inputCsv.GetField <string>("ability");
                    // .Replace("£", Environment.NewLine);

                    card.RulesTextDE = inputCsv.GetField <string>("ability_DE");
                    // .Replace("£", Environment.NewLine);

                    var setName = CardDatabaseHelper.PatchSetName(inputCsv.GetField <string>("set"));
                    if (!string.IsNullOrWhiteSpace(setName) && !availableSets.ContainsKey(setCode))
                    {
                        MagicSetDefinition blockData;
                        if (SetDefinitions.BlockDefinition.TryGetValue(setCode, out blockData))
                        {
                            availableSets.Add(setCode, blockData);
                        }
                        else
                        {
                            var definition = new MagicSetDefinition
                            {
                                Name = setName,
                                Code = setCode,
                                CodeMagicCardsInfo = PatchSetCodeMagicCardsInfo(setCode),
                            };

                            availableSets.Add(setCode, definition);
                        }
                    }

                    if (availableSets.TryGetValue(setCode, out lastSet))
                    {
                        card.SetCode = lastSet.Code;
                    }
                    else
                    {
                        card.SetCode = setCode;
                    }

                    var unique = StaticMagicData.MakeNameSetCode(setCode, card.NameEN, card.NumberInSet);
                    if (uniqueList.ContainsKey(unique))
                    {
                        // Ignore variants of
                        continue;
                    }

                    uniqueList.Add(unique, unique);

                    writer.WriteRecord(card);

                    Console.WriteLine(count + " Reading " + card.NameEN + "(" + card.SetCode + ")...");
                }

                inputCsv.Dispose();
            }

            // Write Sets
            foreach (var set in availableSets.OrderBy(s => s.Key))
            {
                // setWriter.WriteRecord(set.Value);
                setWriter.WriteField <string>(set.Value.Code);
                setWriter.WriteField <string>(set.Value.Name);
                setWriter.WriteField <string>(set.Value.CodeMagicCardsInfo);
                setWriter.WriteField <string>(set.Value.ReleaseDate);
                setWriter.WriteField <string>(set.Value.Block);
                setWriter.WriteField <bool>(set.Value.IsPromoEdition);
                setWriter.NextRecord();
            }

            writer.Dispose();
            setWriter.Dispose();
        }