コード例 #1
0
        public static void ImportRecipes(string headerPath, string materialPath)
        {
            string header;

            using (var sr = new StreamReader(headerPath))
                header = sr.ReadToEnd();


            string materials;

            using (var sr = new StreamReader(materialPath))
                materials = sr.ReadToEnd();


            using (var itemrepo = new ItemRepository())
            {
                var parser = new RecipeParser(itemrepo, new RecipeParserSettings(), header, string.Empty, materials);

                using (var reciperepo = new RecipeRepository())
                {
                    reciperepo.Begin();
                    foreach (var recipe in parser.Recipes)
                    {
                        var  existing = reciperepo.GetByPrimaryResult(recipe.Result);
                        bool skip     = false;
                        foreach (var e in existing)
                        {
                            var match = true;
                            foreach (var kvp in recipe.Materials)
                            {
                                if (!e.Materials.ContainsKey(kvp.Key) || e.Materials[kvp.Key] != kvp.Value)
                                {
                                    match = false;
                                }
                            }
                            if (match)
                            {
                                skip = true;
                            }
                        }

                        if (skip)
                        {
                            Console.WriteLine($"Skipping duplicate recipe for {recipe.Result.Name}");
                            continue;
                        }

                        reciperepo.Save(recipe);
                    }
                    reciperepo.End();
                }
            }
        }