Esempio n. 1
0
        public void RecipeTagsAddMethod_ShouldIncreseLengthPropertyCorrectly()
        {
            var tags1 = new RecipeTags();
            Assert.AreEqual(tags1.Length, 0);

            tags1.Add(RecipeTag.Breakfast);
            tags1.Add(RecipeTag.Dessert);

            Assert.AreEqual(2, tags1.Length);
        }
Esempio n. 2
0
        public void RecipeTagsAddMethod_ShouldAddACorrectElementToTheCollection()
        {
            var tags1 = new RecipeTags();

            tags1.Add(RecipeTag.Breakfast);
            tags1.Add(RecipeTag.Dessert);

            Assert.AreEqual(tags1[0], RecipeTag.Breakfast);
            Assert.AreEqual(tags1[1], RecipeTag.Dessert);
        }
Esempio n. 3
0
        public void RecipeTagsAddMethod_ShouldAddACorrectElementToTheCollection()
        {
            var tags1 = new RecipeTags();

            tags1.Add(RecipeTag.Breakfast);
            tags1.Add(RecipeTag.Dessert);

            Assert.AreEqual(tags1[0], RecipeTag.Breakfast);
            Assert.AreEqual(tags1[1], RecipeTag.Dessert);
        }
Esempio n. 4
0
        public void RecipeTagsAddMethod_ShouldIncreseLengthPropertyCorrectly()
        {
            var tags1 = new RecipeTags();

            Assert.AreEqual(tags1.Length, 0);

            tags1.Add(RecipeTag.Breakfast);
            tags1.Add(RecipeTag.Dessert);

            Assert.AreEqual(2, tags1.Length);
        }
Esempio n. 5
0
            public void Dispose()
            {
                var timer = new Stopwatch();

                timer.Start();

                ratingGraph = null;

                //Free up memory/increase index accessing speed by converting List<> objects to arrays
                foreach (var r in snapshot.recipeMap.Values)
                {
                    r.Ingredients = r.Ingredients.ToArray();
                }

                foreach (var i in snapshot.ingredientMap.Values)
                {
                    var temp     = new List <RecipeNode[]>();
                    var usedTags = new RecipeTags();

                    for (var c = 0; c < Enum.GetNames(typeof(RecipeTag)).Length; c++)
                    {
                        RecipeNode[] nodes = null;
                        if (i.RecipesByTag[c] != null)
                        {
                            nodes = i.RecipesByTag[c].ToArray();
                            usedTags.Add((RecipeTag)c);
                        }

                        temp.Add(nodes);
                    }

                    i.RecipesByTag  = temp.ToArray();
                    i.AvailableTags = usedTags;
                }

                GC.Collect(); //Force garbage collection now, since there might be several hundred megs of unreachable allocations

                timer.Stop();
                ModelingSession.Log.InfoFormat("Cleaning up Indexer took {0}ms.", timer.ElapsedMilliseconds);
            }
Esempio n. 6
0
            public void Dispose()
            {
                var timer = new Stopwatch();
                timer.Start();

                ratingGraph = null;

                //Free up memory/increase index accessing speed by converting List<> objects to arrays
                foreach (var r in snapshot.recipeMap.Values)
                {
                    r.Ingredients = r.Ingredients.ToArray();
                }

                foreach (var i in snapshot.ingredientMap.Values)
                {
                    var temp = new List<RecipeNode[]>();
                    var usedTags = new RecipeTags();

                    for (var c = 0; c < Enum.GetNames(typeof(RecipeTag)).Length; c++)
                    {
                        RecipeNode[] nodes = null;
                        if (i.RecipesByTag[c] != null)
                        {
                            nodes = i.RecipesByTag[c].ToArray();
                            usedTags.Add((RecipeTag)c);
                        }

                        temp.Add(nodes);
                    }

                    i.RecipesByTag = temp.ToArray();
                    i.AvailableTags = usedTags;
                }

                GC.Collect(); //Force garbage collection now, since there might be several hundred megs of unreachable allocations

                timer.Stop();
                ModelingSession.Log.InfoFormat("Cleaning up Indexer took {0}ms.", timer.ElapsedMilliseconds);
            }
Esempio n. 7
0
        public static RecipeTags ToRecipeTags(RecipeMetadata metadata)
        {
            var tags = new RecipeTags();

            if (metadata.DietGlutenFree)
            {
                tags.Add(RecipeTag.GlutenFree);
            }

            if (metadata.DietNoAnimals)
            {
                tags.Add(RecipeTag.NoAnimals);
            }

            if (metadata.DietNomeat)
            {
                tags.Add(RecipeTag.NoMeat);
            }

            if (metadata.DietNoPork)
            {
                tags.Add(RecipeTag.NoPork);
            }

            if (metadata.DietNoRedMeat)
            {
                tags.Add(RecipeTag.NoRedMeat);
            }

            if (metadata.MealBreakfast)
            {
                tags.Add(RecipeTag.Breakfast);
            }

            if (metadata.MealDessert)
            {
                tags.Add(RecipeTag.Dessert);
            }

            if (metadata.MealDinner)
            {
                tags.Add(RecipeTag.Dinner);
            }

            if (metadata.MealLunch)
            {
                tags.Add(RecipeTag.Lunch);
            }

            if (metadata.NutritionLowCalorie)
            {
                tags.Add(RecipeTag.LowCalorie);
            }

            if (metadata.NutritionLowCarb)
            {
                tags.Add(RecipeTag.LowCarb);
            }

            if (metadata.NutritionLowFat)
            {
                tags.Add(RecipeTag.LowFat);
            }

            if (metadata.NutritionLowSodium)
            {
                tags.Add(RecipeTag.LowSodium);
            }

            if (metadata.NutritionLowSugar)
            {
                tags.Add(RecipeTag.LowSugar);
            }

            if (metadata.SkillCommon)
            {
                tags.Add(RecipeTag.CommonIngredients);
            }

            if (metadata.SkillEasy)
            {
                tags.Add(RecipeTag.EasyToMake);
            }

            if (metadata.SkillQuick)
            {
                tags.Add(RecipeTag.Quick);
            }

            return(tags);
        }
Esempio n. 8
0
        public static RecipeTags ToRecipeTags(RecipeMetadata metadata)
        {
            var tags = new RecipeTags();

              if (metadata.DietGlutenFree)
              {
              tags.Add(RecipeTag.GlutenFree);
              }

              if (metadata.DietNoAnimals)
              {
              tags.Add(RecipeTag.NoAnimals);
              }

              if (metadata.DietNomeat)
              {
              tags.Add(RecipeTag.NoMeat);
              }

              if (metadata.DietNoPork)
              {
              tags.Add(RecipeTag.NoPork);
              }

              if (metadata.DietNoRedMeat)
              {
              tags.Add(RecipeTag.NoRedMeat);
              }

              if (metadata.MealBreakfast)
              {
              tags.Add(RecipeTag.Breakfast);
              }

              if (metadata.MealDessert)
              {
              tags.Add(RecipeTag.Dessert);
              }

              if (metadata.MealDinner)
              {
              tags.Add(RecipeTag.Dinner);
              }

              if (metadata.MealLunch)
              {
              tags.Add(RecipeTag.Lunch);
              }

              if (metadata.NutritionLowCalorie)
              {
              tags.Add(RecipeTag.LowCalorie);
              }

              if (metadata.NutritionLowCarb)
              {
              tags.Add(RecipeTag.LowCarb);
              }

              if (metadata.NutritionLowFat)
              {
              tags.Add(RecipeTag.LowFat);
              }

              if (metadata.NutritionLowSodium)
              {
              tags.Add(RecipeTag.LowSodium);
              }

              if (metadata.NutritionLowSugar)
              {
              tags.Add(RecipeTag.LowSugar);
              }

              if (metadata.SkillCommon)
              {
              tags.Add(RecipeTag.CommonIngredients);
              }

              if (metadata.SkillEasy)
              {
              tags.Add(RecipeTag.EasyToMake);
              }

              if (metadata.SkillQuick)
              {
              tags.Add(RecipeTag.Quick);
              }

              return tags;
        }
Esempio n. 9
0
        public IEnumerable<RecipeBinding> LoadRecipeGraph()
        {
            using (var session = this.GetStatelessSession())
            {
                RecipeMetadata metadata = null;
                var recipes = session.QueryOver<Models.Recipes>()
                   .JoinAlias(r => r.RecipeMetadata, () => metadata)
                   .Select(
                      p => p.RecipeId,
                      p => p.Rating,
                      p => metadata.DietGlutenFree,
                      p => metadata.DietNoAnimals,
                      p => metadata.DietNomeat,
                      p => metadata.DietNoPork,
                      p => metadata.DietNoRedMeat,
                      p => metadata.MealBreakfast,
                      p => metadata.MealDessert,
                      p => metadata.MealDinner,
                      p => metadata.MealLunch,
                      p => metadata.NutritionLowCalorie,
                      p => metadata.NutritionLowCarb,
                      p => metadata.NutritionLowFat,
                      p => metadata.NutritionLowSodium,
                      p => metadata.NutritionLowSugar,
                      p => metadata.SkillCommon,
                      p => metadata.SkillEasy,
                      p => metadata.SkillQuick)
                   .List<object[]>();

                List<RecipeBinding> recipeBindings = new List<RecipeBinding>();
                foreach (var recipe in recipes)
                {
                    RecipeTags tags = new RecipeTags();

                    if ((bool)recipe[2])
                    {
                        tags.Add(RecipeTag.GlutenFree);
                    }

                    if ((bool)recipe[3])
                    {
                        tags.Add(RecipeTag.NoAnimals);
                    }

                    if ((bool)recipe[4])
                    {
                        tags.Add(RecipeTag.NoMeat);
                    }

                    if ((bool)recipe[5])
                    {
                        tags.Add(RecipeTag.NoPork);
                    }

                    if ((bool)recipe[6])
                    {
                        tags.Add(RecipeTag.NoRedMeat);
                    }

                    if ((bool)recipe[7])
                    {
                        tags.Add(RecipeTag.Breakfast);
                    }

                    if ((bool)recipe[8])
                    {
                        tags.Add(RecipeTag.Dessert);
                    }

                    if ((bool)recipe[9])
                    {
                        tags.Add(RecipeTag.Dinner);
                    }

                    if ((bool)recipe[10])
                    {
                        tags.Add(RecipeTag.Lunch);
                    }

                    if ((bool)recipe[11])
                    {
                        tags.Add(RecipeTag.LowCalorie);
                    }

                    if ((bool)recipe[12])
                    {
                        tags.Add(RecipeTag.LowCarb);
                    }

                    if ((bool)recipe[13])
                    {
                        tags.Add(RecipeTag.LowFat);
                    }

                    if ((bool)recipe[14])
                    {
                        tags.Add(RecipeTag.LowSodium);
                    }

                    if ((bool)recipe[15])
                    {
                        tags.Add(RecipeTag.LowSugar);
                    }

                    if ((bool)recipe[16])
                    {
                        tags.Add(RecipeTag.CommonIngredients);
                    }

                    if ((bool)recipe[17])
                    {
                        tags.Add(RecipeTag.EasyToMake);
                    }

                    if ((bool)recipe[18])
                    {
                        tags.Add(RecipeTag.Quick);
                    }

                    RecipeBinding recipeBinding = new RecipeBinding()
                                                 {
                                                     Id = (Guid)recipe[0],
                                                     Rating = Convert.ToByte(recipe[1]),
                                                     Tags = tags
                                                 };
                    recipeBindings.Add(recipeBinding);
                }

                return recipeBindings;
            }
        }