Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReceipePrintPage"/> class.
        /// </summary>
        /// <param name="receipe">The receipe.</param>
        public ReceipePrintPage(Receipe receipe)
        {
            this.InitializeComponent();

            this.pageTitle.Text = receipe.Title;

            Paragraph paragraph = new Paragraph();

            paragraph.Inlines.Add(new Run {
                Text = receipe.ToDoInstructions
            });
            paragraph.Inlines.Add(new LineBreak());
            this.instructionsBlock.Blocks.Add(paragraph);

            paragraph = new Paragraph();

            foreach (Ingredient ingredient in receipe.ingredients)
            {
                String ingredientText = String.Format("- {0} {1} {2}", ingredient.quantity, ingredient.unity, ingredient.name);
                paragraph.Inlines.Add(new Run {
                    Text = ingredientText
                });
                paragraph.Inlines.Add(new LineBreak());
            }

            this.ingredientsBlock.Blocks.Add(paragraph);
        }
Esempio n. 2
0
        public bool cleanHtmlEntities(string html, Receipe rec)
        {
            int          posIngredients = html.IndexOf("<p class=\"m_content_recette_ingredients\">");
            HtmlDocument doc            = new HtmlDocument();

            doc.LoadHtml(html);

            var body       = doc.DocumentNode.Element("html").Element("body");
            var div        = body.Elements("div");
            var isNotEmpty = false;

            rec.ToDoInstructions = "";
            var divs = doc.DocumentNode.Descendants("div");

            foreach (var curDiv0 in divs)
            {
                if (curDiv0.GetAttributeValue("class", "") == "m_content_recette_todo")
                {
                    curDiv0.Attributes.RemoveAll();
                    curDiv0.Attributes.Add("style", "font-family:Segoe UI;font-weight: 350;font-size:17px;");

                    String htmlToDo = curDiv0.OuterHtml;

                    var linksToHide = curDiv0.Elements("a");
                    foreach (var currentLink in linksToHide)
                    {
                        htmlToDo = htmlToDo.Replace(currentLink.OuterHtml, currentLink.InnerText);
                    }
                    var divEl2 = curDiv0.Elements("div");
                    foreach (var currDiv2 in divEl2)
                    {
                        var paraph = currDiv2.Elements("p");
                        foreach (var currentParaph in paraph)
                        {
                            var linksToHide2 = currentParaph.Elements("a");
                            foreach (var currentLink2 in linksToHide2)
                            {
                                htmlToDo = htmlToDo.Replace(currentLink2.OuterHtml, currentLink2.InnerText);
                            }
                        }
                    }
                    rec.ToDoInstructions = htmlToDo;
                    isNotEmpty           = true;
                }
            }
            var pPart = doc.DocumentNode.Descendants("p");

            foreach (var currentPart in pPart)
            {
                if (currentPart.GetAttributeValue("class", "") == "m_content_recette_ingredients")
                {
                    this.ingredientPart = currentPart;
                    isNotEmpty          = true;
                }
            }

            return(isNotEmpty);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a group to the shopping list, containing all the ingredients of a receipe.
        /// </summary>
        /// <param name="receipe">The receipe.</param>
        public void CreateShoppingList(Receipe receipe)
        {
            if (!this.ShoppingList.ContainsKey(receipe.Title))
            {
                this.ShoppingList.Add(receipe.Title, new ShoppingListGroup(receipe.Title));

                foreach (Ingredient ing in receipe.ingredients)
                {
                    this.AddIngredientToShoppingList(ing, receipe.Title);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Checks the ingredients.
        /// </summary>
        /// <param name="receipe">The receipe.</param>
        /// <param name="keyWord">The key word.</param>
        /// <returns></returns>
        public bool checkIngredients(Receipe receipe, string keyWord)
        {
            bool containsKey = false;

            foreach (var ingredient in receipe.ingredients)
            {
                if (ingredient.name.ToUpper().IndexOf(keyWord.ToUpper()) >= 0 || ingredient.unity.ToUpper().IndexOf(keyWord.ToUpper()) >= 0)
                {
                    containsKey = true;
                }
            }
            return(containsKey);
        }
Esempio n. 5
0
 /// <summary>
 /// Adds the receipe.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 /// <param name="model">The model.</param>
 public void addReceipe(Receipe receipe, AppModel model)
 {
     if (checkType(receipe))
     {
         if (checkDifficulty(receipe))
         {
             if (checkOptions(receipe))
             {
                 model.AddReceipe(receipe);
             }
         }
     }
 }
Esempio n. 6
0
        public async Task <bool> extractReceipeFromMarmiton(Receipe receipe)
        {
            bool isDone = false;

            this.URL = "http://dev.yougoweb.fr/misn/api2.php?id=" + receipe.Id;
            HttpClient http = new System.Net.Http.HttpClient();

            HttpResponseMessage response = await http.GetAsync(this.URL);

            receipe.HtmlReceipe = await response.Content.ReadAsStringAsync();

            isDone = true;
            return(isDone);
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReceipeTimeOfDay"/> class.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        public ReceipeTimeOfDay(JsonObject jsonObject)
        {
            JsonObject receipeToDJson = JsonObject.Parse(jsonObject.Stringify());

            this.Time.TimeOfDay = receipeToDJson.GetNamedString("TimeOfDay");
            JsonArray receipesJson = receipeToDJson.GetNamedArray("Receipes");

            this.Receipes = new Dictionary <string, Receipe>();

            foreach (var receipeJson in receipesJson)
            {
                Receipe re = new Receipe(receipeJson.Stringify());
                this.Receipes[re.Title] = re;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Adds a receipe to the planning.
        /// </summary>
        /// <param name="receipe">The receipe.</param>
        /// <param name="timeOfDay">The time of day.</param>
        /// <param name="date">The date.</param>
        public void AddReceipeList(Receipe receipe, string timeOfDay, string date)
        {
            ReceipeDate receipeDate = null;

            if (ReceipeList.ContainsKey(date))
            {
                receipeDate = ReceipeList[date];
            }
            else
            {
                receipeDate = new ReceipeDate(date);
                ReceipeList.Add(date, receipeDate);
            }

            receipeDate.ReceipeTimeOfDay[timeOfDay].AddReceipe(receipe);
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <param name="keyWord">The key word.</param>
        /// <param name="nbItemsPerPage">The nb items per page.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <bool> GetData(String keyWord, int nbItemsPerPage, int startIndex, AppModel model)
        {
            HttpClient http  = new System.Net.Http.HttpClient();
            bool       error = false;

            model.ClearReceipes();
            try
            {
                foreach (var jsonItem in model.LocalReceipes)
                {
                    Receipe localToAdd = new Receipe(jsonItem.Stringify());
                    if (checkInstructions(localToAdd, keyWord) || checkTitle(localToAdd, keyWord))
                    {
                        addReceipe(localToAdd, model);
                    }
                }
            }catch (Exception ex) {
            }

            try
            {
                HttpResponseMessage response = await http.GetAsync(String.Format(this.URL, keyWord, nbItemsPerPage, startIndex));

                string jsonString = await response.Content.ReadAsStringAsync();

                JsonObject jsonObject = JsonObject.Parse(jsonString);
                JsonArray  jsonArray  = getItemsArrayFromJSONObject(jsonObject);



                foreach (var item in jsonArray)
                {
                    Receipe receipe = getReceipeFromJSONItem(item.GetObject());
                    addReceipe(receipe, model);
                }
            }
            catch (Exception ex)
            {
                error = true;
            }

            return(error);
        }
Esempio n. 10
0
        /// <summary>
        /// Removes a receipe from the planning.
        /// </summary>
        /// <param name="receipe">The receipe.</param>
        /// <param name="timeOfDay">The time of day.</param>
        /// <param name="date">The date.</param>
        public void RemoveReceipeList(Receipe receipe, string timeOfDay, string date)
        {
            if (this.ReceipeList.Count != 0 && this.ReceipeList[date] != null && this.ReceipeList[date].ReceipeTimeOfDay[timeOfDay] != null)
            {
                this.ReceipeList[date].ReceipeTimeOfDay[timeOfDay].RemoveReceipe(receipe);
                bool deletedReceipeDate = true;
                foreach (ReceipeTimeOfDay receipeTimeOfDay in this.ReceipeList[date].ReceipeTimeOfDay.Values)
                {
                    if (receipeTimeOfDay.Receipes.Count != 0)
                    {
                        deletedReceipeDate = false;
                    }
                }

                if (deletedReceipeDate)
                {
                    this.ReceipeList.Remove(date);
                }
                this.RefreshViews(new RemovedReceipeListEvent(this, receipe, new Time(date, timeOfDay)));
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Adds a receipe to the list of search results..
        /// </summary>
        /// <param name="receipe">The receipe.</param>
        public void AddReceipe(Receipe receipe)
        {
            this.Receipes.Add(receipe);

            this.RefreshViews(new AddedReceipeEvent(this, receipe));
        }
Esempio n. 12
0
 /// <summary>
 /// Selects a receipe.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 public void SelectReceipe(Receipe receipe)
 {
     this.SelectedReceipe = receipe;
     this.RefreshViews(new SelectedReceipeEvent(this, receipe));
 }
Esempio n. 13
0
 /// <summary>
 /// Checks the title.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 /// <param name="keyWord">The key word.</param>
 /// <returns></returns>
 public bool checkTitle(Receipe receipe, string keyWord)
 {
     return(receipe.Title.ToUpper().IndexOf(keyWord.ToUpper()) >= 0);
 }
Esempio n. 14
0
 /// <summary>
 /// Removes a favorite receipe.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 public void RemoveFavoriteReceipe(Receipe receipe)
 {
     this.FavouriteReceipes.Remove(receipe.Title);
 }
Esempio n. 15
0
        /// <summary>
        /// Gets the data by ingredients.
        /// </summary>
        /// <param name="keyWords">The key words.</param>
        /// <param name="nbItemsPerPage">The nb items per page.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <bool> GetDataByIngredients(String[] keyWords, int nbItemsPerPage, int startIndex, AppModel model)
        {
            bool error = false;

            model.ClearReceipes();
            try
            {
                //we add all receipes created by the user
                foreach (var jsonItem in model.LocalReceipes)
                {
                    Receipe localToAdd = new Receipe(jsonItem.Stringify());
                    addReceipe(localToAdd, model);
                }
            }
            catch (Exception ex)
            {
            }
            try
            {
                List <Receipe>[] results = new List <Receipe> [keyWords.Length];
                for (int i = 0; i < keyWords.Length; i++)
                {
                    results[i]  = new List <Receipe>();
                    keyWords[i] = keyWords[i].ToUpper();
                }
                //we add all basic research associated to each keyword to the model
                foreach (var keyWord in keyWords)
                {
                    await this.GetData(keyWord, nbItemsPerPage, startIndex, model);
                }

                int bestResults = 1;// confidence level

                foreach (var receipe in model.Receipes)
                {
                    //we check the research parameters to go faster
                    if (checkType(receipe))
                    {
                        if (checkDifficulty(receipe))
                        {
                            if (checkOptions(receipe))
                            {
                                //used to compute the confidence level
                                int count = 0;

                                //case of receipes from marmiton
                                if (receipe.Id != -1)
                                {
                                    //retrieves ingredients
                                    ReceipeRetriever rr = new ReceipeRetriever();
                                    var task            = rr.extractReceipeFromMarmiton(receipe);


                                    if ((await task) == true)
                                    {
                                        var task2 = rr.cleanHtmlEntities(receipe.HtmlReceipe, receipe);
                                        rr.handleIngredients(rr.ingredientPart, receipe);
                                    }
                                }

                                //we compute the confidence level
                                foreach (var keyWord in keyWords)
                                {
                                    //each key word in the receipe informations add 1 confidence level
                                    if (checkIngredients(receipe, keyWord) || checkInstructions(receipe, keyWord) || checkTitle(receipe, keyWord))
                                    {
                                        count++;
                                    }
                                }
                                results[count].Add(receipe);
                                if (count > bestResults)
                                {
                                    bestResults = count;
                                }
                            }
                        }
                    }
                }

                model.ClearReceipes();


                //only best results are displayed
                foreach (var receipe in results[bestResults])
                {
                    model.AddReceipe(receipe);
                }
            }
            catch (Exception ex)
            {
                error = true;
            }

            return(error);
        }
Esempio n. 16
0
 /// <summary>
 /// Removes a receipe from the list of search results..
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 public void RemoveReceipe(Receipe receipe)
 {
     this.Receipes.Remove(receipe);
     this.RefreshViews(new RemovedReceipeEvent(this, receipe));
 }
Esempio n. 17
0
 /// <summary>
 /// Checks the difficulty.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 /// <returns></returns>
 public bool checkDifficulty(Receipe receipe)
 {
     return((AdvancedDifficulty == 0) || receipe.Difficulty.Value >= 4 || receipe.Difficulty.Value < 1 || (AdvancedDifficulty == receipe.Difficulty.Value));
 }
Esempio n. 18
0
        /// <summary>
        /// Gets the receipe from json item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        private Receipe getReceipeFromJSONItem(JsonObject item)
        {
            Receipe receipe = new Receipe();

            foreach (var property in item)
            {
                if (property.Value.Stringify() != "null")
                {
                    switch (property.Key)
                    {
                    case "author":
                        receipe.Author = property.Value.GetString();
                        break;

                    case "cost":
                        receipe.Cost = new Cost((int)property.Value.GetNumber());
                        break;

                    case "difficulty":
                        receipe.Difficulty = new Difficulty((int)property.Value.GetNumber());
                        break;

                    case "dishType":
                        JsonObject dishType = property.Value.GetObject();
                        foreach (var dishTypeProperty in dishType)
                        {
                            if (dishTypeProperty.Key == "label")
                            {
                                receipe.DishType = DishType.GetInstance(dishTypeProperty.Value.GetString());
                            }
                        }
                        break;

                    case "id":
                        receipe.Id = (int)property.Value.GetNumber();
                        break;

                    case "isVegetarian":
                        receipe.Vegetarian = property.Value.GetBoolean();
                        break;

                    case "published":
                        receipe.PublicationDate = getDateTimeFromString(property.Value.GetString());
                        break;

                    case "rating":
                        receipe.Rating = new Rating((int)property.Value.GetNumber());
                        break;

                    case "title":
                        receipe.Title = property.Value.GetString();
                        break;

                    case "withAlcohol":
                        receipe.WithAlcohol = property.Value.GetBoolean();
                        break;

                    case "pictures":
                        var    picturesArray = property.Value.GetArray();
                        string found         = "";
                        if (picturesArray != null)
                        {
                            var pictureObject = picturesArray[1];
                            foreach (var picture in pictureObject.GetObject())
                            {
                                if (picture.Key == "url")
                                {
                                    found = picture.Value.GetString();
                                }
                            }
                        }
                        receipe.Image = found;
                        break;
                    }
                }
            }

            return(receipe);
        }
Esempio n. 19
0
 /// <summary>
 /// Adds the receipe.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 public void AddReceipe(Receipe receipe)
 {
     this.Receipes[receipe.Title] = receipe;
 }
Esempio n. 20
0
 /// <summary>
 /// Checks the options.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 /// <returns></returns>
 public bool checkOptions(Receipe receipe)
 {
     return(((receipe.Vegetarian == AdvancedVegetarian) || (AdvancedVegetarian == false)) && ((receipe.WithAlcohol == AdvancedAlcool) || (AdvancedAlcool == true)));
 }
Esempio n. 21
0
 /// <summary>
 /// Checks the instructions.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 /// <param name="keyWord">The key word.</param>
 /// <returns></returns>
 public bool checkInstructions(Receipe receipe, string keyWord)
 {
     return((receipe.ToDoInstructions != null) && (receipe.ToDoInstructions.ToUpper().IndexOf(keyWord.ToUpper()) >= 0));
 }
Esempio n. 22
0
 public void handleContentReceipe(HtmlNode node, Receipe rec)
 {
 }
Esempio n. 23
0
 /// <summary>
 /// Adds a favorite receipe.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 public void AddFavoriteReceipe(Receipe receipe)
 {
     this.FavouriteReceipes[receipe.Title] = receipe;
 }
Esempio n. 24
0
 /// <summary>
 /// Removes the receipe.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 public void RemoveReceipe(Receipe receipe)
 {
     this.Receipes.Remove(receipe.Title);
 }
Esempio n. 25
0
 /// <summary>
 /// Checks the type.
 /// </summary>
 /// <param name="receipe">The receipe.</param>
 /// <returns></returns>
 public bool checkType(Receipe receipe)
 {
     return((AdvancedSearch == null || AdvancedSearch.Count == 0) || AdvancedSearch.Contains(receipe.DishType.Name));
 }
Esempio n. 26
0
        public void handleIngredients(HtmlNode node, Receipe rec)
        {
            String text = node.InnerText;
            String html = node.InnerHtml;

            int counterOfIng = 0;
            var spans        = node.Descendants("span");

            foreach (var span in spans)
            {
                html = html.Replace(span.OuterHtml, "");
            }
            html = html.Replace("\n", "");
            var linksIng = node.Descendants("a");

            foreach (var currLinkIng in linksIng)
            {
                html = html.Replace(currLinkIng.OuterHtml, currLinkIng.InnerText);
            }

            string[] stringSeparators = new string[] { "<br>" };

            string[] listOfIng = html.Split(stringSeparators, StringSplitOptions.None);
            rec.ingredients = new List <Ingredient>();

            foreach (var indexIng in listOfIng)
            {
                if (indexIng != "" && indexIng.Length > 0 && indexIng != " " && indexIng != null && indexIng.IndexOf('-') != -1)
                {
                    int counterOfWord = 0;
                    var updatedIng    = indexIng;
                    if (indexIng.IndexOf('-') != -1)
                    {
                        int firstIndexIng = indexIng.IndexOf('-');
                        updatedIng = indexIng.Substring(firstIndexIng);
                    }


                    string[] listofArgs = updatedIng.Split(' ');

                    Ingredient currentIng = new Ingredient();
                    currentIng.name     = "";
                    currentIng.unity    = "";
                    currentIng.quantity = "";
                    Boolean hasUnity            = false;
                    Boolean hasQty              = false;
                    Boolean needMoreDetailUnity = false;
                    int     indiceUnity         = 0;
                    int     indiceQty           = 0;

                    foreach (var currentArg in listofArgs)
                    {
                        Boolean hasDigit = false;
                        foreach (char letter in currentArg)
                        {
                            if (Char.IsDigit((letter)))
                            {
                                hasDigit = true;
                            }
                        }

                        var arg = currentArg;
                        if (counterOfWord == 0)
                        {
                            arg = arg.Replace("-", "");
                        }
                        if (counterOfWord == 1 && hasDigit)
                        {
                            currentIng.quantity = arg;
                            indiceQty           = counterOfWord;
                            hasQty = true;
                        }
                        else if ((arg.ToUpper() == "kg".ToUpper() || arg.ToUpper() == "tasse".ToUpper() || arg.ToUpper() == "bol".ToUpper() || arg.ToUpper() == "cuillère".ToUpper() || arg.ToUpper() == "cuillères".ToUpper() || arg.ToUpper() == "G" || arg.ToUpper() == "L" || arg.ToUpper() == "CL") && counterOfWord == indiceQty + 1)
                        {
                            if (hasQty)
                            {
                                currentIng.unity += (string)arg;
                                hasUnity          = true;
                                indiceUnity       = counterOfWord;
                            }
                            if (arg.ToUpper() == "cuillère".ToUpper() || arg.ToUpper() == "cuillères".ToUpper())
                            {
                                needMoreDetailUnity = true;
                            }
                        }
                        else if (needMoreDetailUnity)
                        {
                            if (hasQty && arg.ToUpper() == "à".ToUpper())
                            {
                                currentIng.unity   += " " + (string)arg + " ";
                                hasUnity            = true;
                                indiceUnity         = counterOfWord;
                                needMoreDetailUnity = true;
                            }
                            if (arg.ToUpper() == "soupe".ToUpper() || arg.ToUpper() == "café".ToUpper())
                            {
                                currentIng.unity   += (string)arg;
                                hasUnity            = true;
                                indiceUnity         = counterOfWord;
                                needMoreDetailUnity = false;
                            }
                        }
                        else
                        {
                            if (hasUnity)
                            {
                                if (indiceUnity == counterOfWord - 1)
                                {
                                    arg = arg.Replace("de", "");
                                    arg = arg.Replace("d'", "");
                                    arg = arg.Replace(" ", "");
                                }
                            }
                            if (arg != "" && arg != " ")
                            {
                                //arg = arg.Replace(",", " et ");
                                currentIng.name += arg + " ";
                            }
                        }
                        counterOfWord++;
                    }
                    if (currentIng.name.Length > 0 && counterOfWord >= 0 && currentIng.name != "")
                    {
                        string newstring = currentIng.name[0].ToString().ToUpper() + currentIng.name.Substring(1).ToLower();
                        currentIng.name = newstring;
                        rec.ingredients.Add(currentIng);
                    }
                }
                counterOfIng++;
            }
        }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemovedReceipeListEvent"/> class.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="receipe">The receipe.</param>
 /// <param name="time">The time.</param>
 public RemovedReceipeListEvent(AbstractModel model, Receipe receipe, Time time)
     : base(model, receipe)
 {
     this.Time = time;
 }