Exemple #1
0
        private static void CreateRecipesAndRecipeGroups(JsonArray array)
        {
            foreach (var item in array)
            {
                var obj = item.GetObject();
                RecipeDataItem recipe = new RecipeDataItem();
                RecipeDataGroup group = null;

                foreach (var key in obj.Keys)
                {
                    IJsonValue val;
                    if (!obj.TryGetValue(key, out val))
                        continue;

                    switch (key)
                    {
                        case "key":
                            recipe.UniqueId = val.GetNumber().ToString();
                            break;
                        case "title":
                            recipe.Title = val.GetString();
                            break;
                        case "shortTitle":
                            recipe.ShortTitle = val.GetString();
                            break;
                        case "preptime":
                            recipe.PrepTime = (int)val.GetNumber();
                            break;
                        case "directions":
                            recipe.Directions = val.GetString();
                            break;
                        case "ingredients":
                            var ingredients = val.GetArray();
                            var list = (from i in ingredients select i.GetString()).ToList();
                            recipe.Ingredients = new ObservableCollection<string>(list);
                            break;
                        case "backgroundImage":
                            recipe.SetImage(val.GetString());
                            break;
                        case "tileImage":
                            recipe.SetTileImage(val.GetString());
                            break;
                        case "group":
                            var recipeGroup = val.GetObject();

                            IJsonValue groupKey;
                            if (!recipeGroup.TryGetValue("key", out groupKey))
                                continue;

                            group = _recipeDataSource.AllGroups.FirstOrDefault(c => c.UniqueId.Equals(groupKey.GetString()));

                            if (group == null)
                                group = CreateRecipeGroup(recipeGroup);

                            recipe.Group = group;
                            break;
                    }
                }

                if (group != null)
                    group.Items.Add(recipe);
            }
        }
Exemple #2
0
        private static void CreateRecipesAndRecipeGroups(JsonArray array)
        {
            foreach (var item in array)
            {
                var             obj    = item.GetObject();
                RecipeDataItem  recipe = new RecipeDataItem();
                RecipeDataGroup group  = null;

                foreach (var key in obj.Keys)
                {
                    IJsonValue val;
                    if (!obj.TryGetValue(key, out val))
                    {
                        continue;
                    }

                    switch (key)
                    {
                    case "key":
                        recipe.UniqueId = val.GetNumber().ToString();
                        break;

                    case "title":
                        recipe.Title = val.GetString();
                        break;

                    case "shortTitle":
                        recipe.ShortTitle = val.GetString();
                        break;

                    case "preptime":
                        recipe.PrepTime = (int)val.GetNumber();
                        break;

                    case "directions":
                        recipe.Directions = val.GetString();
                        break;

                    case "ingredients":
                        var ingredients = val.GetArray();
                        var list        = (from i in ingredients select i.GetString()).ToList();
                        recipe.Ingredients = new ObservableCollection <string>(list);
                        break;

                    case "backgroundImage":
                        recipe.SetImage(val.GetString());
                        break;

                    case "tileImage":
                        recipe.SetTileImage(val.GetString());
                        break;

                    case "group":
                        var recipeGroup = val.GetObject();

                        IJsonValue groupKey;
                        if (!recipeGroup.TryGetValue("key", out groupKey))
                        {
                            continue;
                        }

                        group = _recipeDataSource.AllGroups.FirstOrDefault(c => c.UniqueId.Equals(groupKey.GetString()));

                        if (group == null)
                        {
                            group = CreateRecipeGroup(recipeGroup);
                        }

                        recipe.Group = group;
                        break;
                    }
                }

                if (group != null)
                {
                    group.Items.Add(recipe);
                }
            }
        }