void KeywordProInclude(List <string> pro, List <RecipeObj> results)
        {
            bool added = false;

            if (pro.Count > 0)
            {
                foreach (string recipeName in Model.recipes.Keys)
                {
                    RecipeObj r = Model.recipes[recipeName];
                    foreach (string word in pro)
                    {//need to match all pro to pass recipe to results
                        if (WordInRecipe(r, word) && !results.Contains(r) && !added)
                        {
                            results.Add(r);
                            Trace.WriteLine(string.Format("adding recipe {0} because it contains {1} and results.contains() is {2}", r.name, word, results.Contains(r)));
                            added = true;
                        }
                        added = false;
                    }
                }
            }
            else
            {
                foreach (string name in Model.recipes.Keys)
                {
                    results.Add(Model.recipes[name]);
                }
            }
        }
        // TODO: filter the results via favorited.
        public void FavoriteRecipes()
        {
            string imagePath = Constants.Paths_Images.getImagesRecipesBasePath();

            paneLabel.Content = "Your Favorites";
            recipeList.Children.Clear();
            noRecipe("", false);
            Trace.WriteLine(string.Format("root = {0} and Recipes = {1}", Constants.GetRootFolder(), imagePath));
            if (Model.user.favorites.Count > 0)
            {
                foreach (string recipe in Model.user.favorites)
                {
                    if (Model.recipes.ContainsKey(recipe))
                    {
                        RecipeObj recipeObj = Model.recipes[recipe];
                        recipeList.Children.Add(new ViewRecipeListElement(recipeObj.name, imagePath + recipeObj.image_thumb, recipeObj.difficulty, recipeObj.ethnicity, recipeObj.steps.Count()));
                    }
                }
            }
            else
            {
                noRecipe("You Have No Favorites", true);
            }

            paneLabel.Content = "Your Favorites";
        }
Esempio n. 3
0
 public ViewRecipeListElement(RecipeObj r)
 {
     InitializeComponent();
     RecipeName = r.name;
     ImgPath    = r.image;
     Difficulty = r.difficulty;
     Ethnicity  = r.ethnicity;
     Steps      = r.totalSteps;
 }
        public void ConfigRecipe()
        {
            RecipeObj recipe = Model.recipe;

            Trace.WriteLine(string.Format("config Recipe called with current step= {0}", recipe.currentStep));
            RecipeEndLabel.Text = String.Format("Recipe Complete : {0}\n{1}", recipe.name, recipe.steps[recipe.totalSteps - 1][1]);
            string path = Constants.Paths_Images.getImagesRecipesBasePath() + recipe.steps[recipe.totalSteps - 1][0];

            RecipeEndImage.Source = Constants.PathToSource(path);
            Uid = recipe.Uids[recipe.totalSteps];
        }
        public void ConfigRecipe()
        {
            RecipeObj recipe = Model.recipe;

            progress.Value   = 0;
            progress.Maximum = recipe.totalSteps;
            string path = Constants.Paths_Images.getImagesRecipesBasePath() + recipe.steps[0][0];

            RecipeStepImage.Source = Constants.PathToSource(path);
            RecipeStepTitle.Text   = recipe.steps[0][1];
            RecipeStepText.Text    = recipe.steps[0][2];
        }
        public void RefreshStep()
        {
            RecipeObj recipe  = Model.recipe;
            double    stepNum = recipe.currentStep;

            string[] step = recipe.steps[(int)stepNum];
            Trace.WriteLine(string.Format("configure recipeStep {0} for stepName {1} and stepText {2}", Model.recipe.currentStep, step[1], step[2]));
            RecipeStepTitle.Text = step[1];
            Trace.Write(string.Format("refresh Uid from {0}", Uid));
            Trace.WriteLine(string.Format("to {0}", Uid));
            Uid = Model.recipe.Uids[Model.recipe.currentStep];
            MainWindow._viewRecipe.SwapGuid(this);
            string path = Constants.Paths_Images.getImagesRecipesBasePath() + step[0];

            RecipeStepImage.Source = Constants.PathToSource(path);
            RecipeStepText.Text    = step[2];
            progress.Value         = stepNum + 1;
        }
        Boolean WordInRecipe(RecipeObj r, string word)
        {
            //get fully upercase variants of all relevant text fields
            string        NAME   = r.name.ToUpper();
            string        ETH    = r.ethnicity.ToUpper();
            string        DIFF   = r.difficulty.ToUpper();
            List <string> INGRED = new List <string>();

            foreach (string[] i in r.ingredients)
            {
                INGRED.Add(i[1].ToUpper());
            }
            string WORD = word.ToUpper();

            //test keyword matching now;
            if (NAME.Contains(WORD))
            {
                Trace.WriteLine(string.Format("recipe {0} contains {1} in name", r.name, WORD));
                return(true);
            }
            if (ETH.Contains(WORD))
            {
                Trace.WriteLine(string.Format("recipe {0} contains {1} in ethnicity", r.name, WORD));
                return(true);
            }
            if (DIFF.Contains(WORD))
            {
                Trace.WriteLine(string.Format("recipe {0} contains {1} in difficulty", r.name, WORD));
                return(true);
            }
            foreach (string I in INGRED)
            {
                Trace.WriteLine(string.Format("testing ingredient {0} or .contains() {1}", I, WORD));
                if (I.Contains(WORD))
                {
                    Trace.WriteLine(string.Format("recipe {0} contains {1} in ingredients", r.name, WORD));
                    return(true);
                }
            }
            return(false);
        }
 public void PopularRecipes()
 {
     Trace.WriteLine("entry of PopularRecipes() in viewHomeTemplate");
     recipeList.Children.Clear();
     noRecipe("", false);
     Trace.WriteLine(string.Format("Recipes = {0}", Constants.Paths_Images.getImagesRecipesBasePath()));
     if (Model.recipes.ToArray().Length > 0)
     {
         foreach (string recipe in Model.recipes.Keys)
         {
             RecipeObj recipeObj = Model.recipes[recipe];
             Trace.WriteLine(String.Format("assigning {0} image {1} at {2}", recipeObj.name, recipeObj.image_thumb, Constants.Paths_Images.getImagesRecipesBasePath() + recipeObj.image_thumb));
             recipeList.Children.Add(new ViewRecipeListElement(recipeObj.name, Constants.Paths_Images.getImagesRecipesBasePath() + recipeObj.image_thumb, recipeObj.difficulty, recipeObj.ethnicity, recipeObj.steps.Count()));
         }
     }
     else
     {
         noRecipe("No Recipes Available", true);
     }
     paneLabel.Content = "Dishes of the Day";
     Trace.WriteLine(String.Format("size of recipeList = {0}", this.ActualHeight));
     Trace.WriteLine("    exit from PopularRecipes() in viewHomeTemplate");
 }
Esempio n. 9
0
        public void GetRecipesFromFile()
        {
//            String path = Constants.root + Constants.Paths_Data.Recipes;
            String[] directories = Directory.GetDirectories(Constants.Paths_Data.GetDatabaseRecipeFolderPath());
            string   recipeFile  = "\\recipe";

            Trace.WriteLine("loading recipes from file");
            foreach (string dir in directories)
            {
                Trace.Write(String.Format("loading {0} which splits to ", dir));
                foreach (string piece in dir.Split('\\'))
                {
                    Trace.Write(piece + ", ");
                }
                Trace.WriteLine(String.Format("  with {0} elements", dir.Split('\\').Length));
                Trace.WriteLine(String.Format("    Last element is element {0}", dir.Split('\\').Length - 1));
                string recipeName = dir.Split('\\')[dir.Split('\\').Length - 1];
                Trace.Write(String.Format("found {0}, loading file {1}", recipeName, dir + recipeFile));
                StreamReader file = new StreamReader(Constants.Paths_Data.GetDatabaseRecipeFilePath(recipeName));
                RecipeObj    r    = new RecipeObj(file);
                recipes.Add(r.name, r);
            }
        }