Esempio n. 1
0
        private static RecipeDataGroup CreateRecipeGroup(JsonObject obj)
        {
            RecipeDataGroup group = new RecipeDataGroup();

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

                switch (key)
                {
                case "key":
                    group.UniqueId = val.GetString();
                    break;

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

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

                case "description":
                    group.Description = val.GetString();
                    break;

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

                case "groupImage":
                    group.SetGroupImage(val.GetString());
                    break;
                }
            }

            _recipeDataSource.AllGroups.Add(group);
            return(group);
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 3
0
 public RecipeDataItem(String uniqueId, String title, String shortTitle, String imagePath, int preptime, String directions, ObservableCollection <string> ingredients, RecipeDataGroup group)
     : base(uniqueId, title, shortTitle, imagePath)
 {
     this._preptime    = preptime;
     this._directions  = directions;
     this._ingredients = ingredients;
     this._group       = group;
 }