public RecipeCreator(IKpcContext context)
        {
            this.context = context;
            this.recipe = new Recipe();

            this.recipe.DateEntered = DateTime.Now;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuUpdater"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="menu">The menu.</param>
 public MenuUpdater(IKpcContext context, Menu menu)
 {
     this.context = context;
     this.menu = menu;
     this.addQueue = new List<Recipe>();
     this.removeQueue = new List<Recipe>();
     this.moveQueue = new List<MenuMover>();
 }
        public ShoppingListUpdater(IKpcContext context, ShoppingList list)
        {
            this.context = context;
            this.list = list;

            this.addQueue = new List<ShoppingListAdder>();
            this.updateQueue = new List<ShoppingListItemUpdater>();
            this.removeQueue = new List<ShoppingListItem>();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuAction"/> class.
 /// </summary>
 /// <param name="context">The context on which the actions have to be applied.</param>
 public MenuAction(IKpcContext context)
 {
     this.context = context;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelerAction"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public ModelerAction(IKpcContext context)
 {
     this.context = context;
 }
 public ShoppingListAction(IKpcContext context)
 {
     this.context = context;
 }
 public ShoppingListLoader(IKpcContext context, ShoppingList list)
 {
     this.context = context;
     this.listsToLoad = new List<ShoppingList>() { list };
 }
 public RecipeLoader(IKpcContext context, Recipe recipe)
 {
     this.context = context;
     this.recipesToLoad = new List<Recipe>() { recipe };
 }
 public IngredientAdder(IKpcContext context, Recipe recipe, string section)
     : this(context, recipe)
 {
     this.section = section;
 }
 public IngredientAdder(IKpcContext context, Recipe recipe)
 {
     this.context = context;
     this.recipe = recipe;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuLoader"/> class.
 /// </summary>
 /// <param name="context">The context from where the menu has to be loaded.</param>
 /// <param name="menu">The specific menu that has to be loaded.</param>
 public MenuLoader(IKpcContext context, Menu menu)
 {
     this.context = context;
     this.menusToLoad = new List<Menu>() { menu };
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuLoader"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public MenuLoader(IKpcContext context)
 {
     this.context = context;
     this.loadAll = true;
 }
 public RecipeEnqueuer(IKpcContext context)
 {
     this.context = context;
     this.recipesQueue = new List<Recipe>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuDeleter"/> class.
 /// </summary>
 /// <param name="context">The context that has to be cheked for the specified menu and if it is found to be deleted.</param>
 /// <param name="menu">The menu that has to be deleted. </param>
 public MenuDeleter(IKpcContext context, Menu menu)
 {
     this.context = context;
     this.menusToDelete = new List<Menu>() { menu };
 }
 public void Initialize(IKpcContext context)
 {
     if (this.sessionFactory == null)
     {
         this.sessionFactory = this.InitializeSessionFactory();
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuCreator"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 public MenuCreator(IKpcContext context)
 {
     this.context = context;
     this.recipes = new List<Recipe>();
     this.title = "New Menu";
 }
 public ShoppingListDeleter(IKpcContext context, ShoppingList list)
 {
     this.context = context;
     this.deleteQueue = new List<ShoppingList>() { list };
 }
 public QueueLoader(IKpcContext context)
 {
     this.context = context;
 }
 public ModelerProxy(IKpcContext context)
 {
     this.context = context;
 }
 public ShoppingListLoader(IKpcContext context)
 {
     this.context = context;
     this.loadAll = true;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelingSessionAction"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="profile">The profile.</param>
 public ModelingSessionAction(IKpcContext context, IUserProfile profile)
 {
     this.session = context.CreateModelingSession(profile);
 }
 public QueueAction(IKpcContext context)
 {
     this.context = context;
 }
 public RecipeFinder(IKpcContext context, RecipeQuery query)
 {
     this.context = context;
     this.query = query;
 }
 public void Setup()
 {
     Trace.Write("Creating DB Snapshot from XML file... ");
     this.context = new MockContext();
     this.context.Initialize();
     Trace.WriteLine("Done!");
 }
            public void Index(IKpcContext context)
            {
                var timer = new Stopwatch();
                timer.Start();

                this.ratingGraph = new RatingGraph();
                var loader = context.ModelerLoader;

                foreach (var dataItem in loader.LoadRatingGraph())
                {
                    var rating = dataItem.Rating;
                    var userId = dataItem.UserId;
                    var recipeId = dataItem.RecipeId;

                    if (rating < 4)
                    {
                        continue; // TODO: Might not be needed, DB should only query for 4 or 5 star ratings
                    }

                    this.ratingGraph.AddRating(rating, userId, recipeId);
                }

                ModelingSession.Log.InfoFormat("Building Rating Graph took {0}ms.", timer.ElapsedMilliseconds);
                timer.Reset();
                timer.Start();

                // Create empty recipe nodes without links
                this.snapshot.recipeMap = (from recipeGraph in loader.LoadRecipeGraph()
                                      select new RecipeNode
                                      {
                                          RecipeId = recipeGraph.Id,
                                          Rating = recipeGraph.Rating,
                                          Tags = recipeGraph.Tags,
                                          Hidden = recipeGraph.Hidden,
                                          Ingredients = new List<IngredientUsage>()
                                      }).ToDictionary(k => k.RecipeId);

                ModelingSession.Log.InfoFormat("Building empty RecipeNodes took {0}ms.", timer.ElapsedMilliseconds);
                timer.Reset();
                timer.Start();

                // Build tag index
                foreach (var recipe in this.snapshot.recipeMap.Values)
                {
                    if (recipe.Hidden)
                    {
                        continue; // RecipeList does not include Hidden recipes so they don't get picked at random
                    }

                    foreach (var tag in recipe.Tags)
                    {
                        var nodes = this.snapshot.recipeList[tag.Value] as List<RecipeNode>;
                        if (nodes == null)
                        {
                            this.snapshot.recipeList[tag.Value] = nodes = new List<RecipeNode>();
                        }

                        nodes.Add(recipe);
                    }
                }

                for (var i = 0; i < this.snapshot.recipeList.Length; i++)
                {
                    var list = this.snapshot.recipeList[i] as List<RecipeNode>;
                    if (list != null)
                    {
                        this.snapshot.recipeList[i] = list.ToArray();
                    }
                    else
                    {
                        // No recipes in DB use this tag
                        this.snapshot.recipeList[i] = new RecipeNode[0];
                    }
                }

                ModelingSession.Log.InfoFormat("Indexing recipes by tag took {0}ms.", timer.ElapsedMilliseconds);
                timer.Reset();
                timer.Start();

                // Loop through ingredient usages and fill in vertices on graph
                // For each item: Create IngredientUsage and add to recipe, create IngredientNode (if necessary) and add recipe to IngredientNode
                foreach (var ingredientGraph in loader.LoadIngredientGraph())
                {
                    var recipeId = ingredientGraph.RecipeId;
                    var ingredientId = ingredientGraph.IngredientId;
                    var quantity = ingredientGraph.Quantity;
                    var unit = ingredientGraph.Unit;
                    var convertedType = Unit.GetConvertedType(unit);

                    List<RecipeNode>[] nodes;
                    IngredientNode ingredientNode;
                    var node = this.snapshot.recipeMap[recipeId];

                    if (!this.snapshot.ingredientMap.TryGetValue(ingredientId, out ingredientNode))
                    {
                        // New ingredient, create node for it
                        nodes = new List<RecipeNode>[RecipeTag.NumberOfTags];
                        this.snapshot.ingredientMap.Add(
                            ingredientId,
                            ingredientNode = new IngredientNode { IngredientId = ingredientId, RecipesByTag = nodes, ConvType = convertedType });
                    }
                    else
                    {
                        nodes = ingredientNode.RecipesByTag as List<RecipeNode>[];
                    }

                    // For each tag the recipe has, we need to create a link through ingNode.RecipesByTag to the recipe
                    if (!node.Hidden)
                    {
                        // Don't index Hidden recipes
                        foreach (var tag in node.Tags)
                        {
                            if (nodes[tag.Value] == null)
                            {
                                nodes[tag.Value] = new List<RecipeNode>();
                            }

                            nodes[tag.Value].Add(node); // Add ingredient link to RecipeNode
                        }
                    }

                    var usages = node.Ingredients as List<IngredientUsage>; // Add ingredient usage to recipe
                    usages.Add(new IngredientUsage { Amount = quantity, Ingredient = ingredientNode, Unit = unit });
                }

                ModelingSession.Log.InfoFormat("Creating IngredientUsage vertices took {0}ms.", timer.ElapsedMilliseconds);
                timer.Reset();
                timer.Start();

                // Create suggestion links for each recipe
                foreach (var recipe in this.snapshot.recipeMap.Values)
                {
                    recipe.Suggestions = (from s in this.ratingGraph.GetSimilarRecipes(recipe.RecipeId) select this.snapshot.recipeMap[s]).ToArray();
                }

                ModelingSession.Log.InfoFormat("Building suggestions for each recipe took {0}ms.", timer.ElapsedMilliseconds);
                timer.Reset();
            }