/// <summary> Load all recipe results from the database </summary> public override void LoadData() { DataTable table = GetAllData(); foreach (DataRow row in table.Rows) { int tier = Tier.Parse(row); long recipeId = RecipeId.Parse(row); long resourceId = ResourceId.Parse(row); int amount = Amount.Parse(row); Recipe recipe = TableManager.Recipe.GetRecipe(recipeId); Resource resource = TableManager.Resource.GetResource(resourceId); recipe.AddResultResource(tier, resource, amount); } }
/// <summary> Parse data in the profession files </summary> static void ParseProfessionData() { foreach (string filePath in Directory.EnumerateFiles(ProfessionDataFolder)) { Console.WriteLine("Reading File: {0}", Path.GetFileName(filePath)); string professionName = Path.GetFileNameWithoutExtension(filePath); Profession profession = Profession.Factory.CreateProfession(professionName); using (StreamReader sr = new StreamReader(filePath)) { Recipe recipe = null; int grade = 0; while (!sr.EndOfStream) { string[] row = sr.ReadLine().Split(';'); RowType rowType = IdentifyRow(row); switch (rowType) { case RowType.TierDelimiter: { // Set Grade grade = row[0].Count(c => c == 'I'); break; } case RowType.RecipeInitial: { // Create Recipe string recipeName = row[2]; recipe = Recipe.Factory.CreateRecipe(recipeName, profession, grade); // Add Result Tier 1 string[] result = row[8].Split(','); foreach (string resourceAmountPair in result) { (Resource resource, int amount) = ParseResourceAmountPair(resourceAmountPair.Trim()); recipe?.AddResultResource(0, resource, amount); } break; } case RowType.RecipeConsumes: { // Add Consumed Resources string[] consumes = row[4].Split(','); foreach (string resourceAmountPair in consumes) { (Resource resource, int amount) = ParseResourceAmountPair(resourceAmountPair.Trim()); recipe?.AddConsumed(resource, amount); } // Add Result Tier 2 string[] result = row[8].Split(','); foreach (string resourceAmountPair in result) { (Resource resource, int amount) = ParseResourceAmountPair(resourceAmountPair.Trim()); recipe?.AddResultResource(1, resource, amount); } break; } case RowType.RecipeFinal: { // Add Result Tier 3 string[] result = row[8].Split(','); foreach (string resourceAmountPair in result) { (Resource resource, int amount) = ParseResourceAmountPair(resourceAmountPair.Trim()); recipe?.AddResultResource(2, resource, amount); } break; } } } } } }