public WeeklyMenu NewMenu(UserProfile userProfile)
        {
            WeeklyMenu result = new WeeklyMenu(this);
            Random     rnd    = new Random();

            foreach (DailyMenu dm in result)
            {
                int num = rnd.Next(1, 4);
                for (int i = 0; i < num; i++)
                {
                    List <Serving> servings = new List <Serving>();
                    int            num2     = rnd.Next(1, 3);
                    for (int j = 0; j < num2; j++)
                    {
                        servings.Add(new Serving(KitchenManager.Dishes.RandomElement(), new Random().Next(120)));
                    }
                    NonEmptyList <Serving> nonempty = new NonEmptyList <Serving>(servings[0]);
                    for (int j = 1; j < servings.Count; j++)
                    {
                        nonempty.Add(servings[j]);
                    }
                    dm.Meals.Add(new Meal("pasto " + i, new DateTime(2000, 1, 1, rnd.Next(24), rnd.Next(60), 0), nonempty));
                }
            }
            return(result);
        }
        private void LoadDishesFromXml(string filename)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(filename);
            XmlNodeList dishesNodes = xml.SelectNodes("/dishes/dish");

            foreach (XmlElement dishNode in dishesNodes)
            {
                string name          = dishNode.Attributes["name"].Value;
                double carbohydrates = XmlConvert.ToDouble(dishNode.Attributes["carbohydrates"].Value);
                double calories      = XmlConvert.ToDouble(dishNode.Attributes["calories"].Value);
                double proteins      = XmlConvert.ToDouble(dishNode.Attributes["proteins"].Value);
                double fats          = XmlConvert.ToDouble(dishNode.Attributes["fats"].Value);

                XmlNodeList       ingredientNodes = dishNode.SelectNodes("/ingredient");
                List <Ingredient> ingredients     = new List <Ingredient>();
                foreach (XmlElement ingredientNode in ingredientNodes)
                {
                    Ingredient ingredient = ingredientNode.InnerText;
                    ingredients.Add(name);
                }
                NonEmptyList <Ingredient> nonEmpty = new NonEmptyList <Ingredient>(ingredients[0]);
                for (int i = 1; i < ingredients.Count; i++)
                {
                    nonEmpty.Add(ingredients[i]);
                }

                _dishes.Add(new Dish(name, calories, proteins, fats, carbohydrates, nonEmpty));
            }
        }
        private void LoadProfilesFromXml(string filename)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(filename);
            XmlNodeList usersNodes = xml.SelectNodes("/users/user");

            foreach (XmlElement userNode in usersNodes)
            {
                UserProfile     up = new UserProfile();
                PersonalDetails pd = new PersonalDetails();
                foreach (XmlElement detail in userNode.SelectNodes("/personaldetails/*"))
                {
                    var propertyInfo = pd.GetType().GetProperty(detail.LocalName);
                    if (propertyInfo != null)
                    {
                        propertyInfo.SetValue(pd, System.Convert.ChangeType(detail.InnerText, propertyInfo.PropertyType));
                    }
                }
                up.Details = pd;

                up.Goal = (Goal)System.Enum.Parse(typeof(Goal), userNode.SelectSingleNode("/goal").InnerText, true);

                List <Ingredient> preferences = new List <Ingredient>();
                foreach (XmlElement ingredientNode in userNode.SelectNodes("/preferences/ingredient"))
                {
                    preferences.Add(ingredientNode.InnerText);
                }
                up.Preferences = preferences;

                WeeklyMenu wm = new WeeklyMenu(userNode.SelectSingleNode("/menu").Attributes["dietCalculator"].InnerText);
                foreach (XmlElement dayNode in userNode.SelectNodes("/menu/day"))
                {
                    preferences.Add(dayNode.InnerText);
                    DailyMenu dm = wm[(System.DayOfWeek)System.Enum.Parse(typeof(System.DayOfWeek), dayNode.Attributes["day"].InnerText, true)];
                    foreach (XmlElement mealNode in dayNode.SelectNodes("/meal"))
                    {
                        string         name     = mealNode.Attributes["name"].InnerText;
                        string         hour     = mealNode.Attributes["hour"].InnerText;
                        string         minute   = mealNode.Attributes["minute"].InnerText;
                        DateTime       time     = new DateTime(2000, 1, 1, int.Parse(hour), int.Parse(minute), 0);
                        List <Serving> servings = new List <Serving>();

                        foreach (XmlElement servingNode in mealNode.SelectNodes("/serving"))
                        {
                            Dish dish = null;
                            // una ricerca migliore??
                            foreach (Dish d in _dishes)
                            {
                                if (d.Name == servingNode.Attributes["quantity"].InnerText)
                                {
                                    dish = d;
                                    break;
                                }
                            }
                            int quantity = int.Parse(servingNode.Attributes["quantity"].InnerText);
                            servings.Add(new Serving(dish, quantity));
                        }

                        NonEmptyList <Serving> nonEmpty = new NonEmptyList <Serving>(servings[0]);
                        for (int i = 1; i < servings.Count; i++)
                        {
                            nonEmpty.Add(servings[i]);
                        }
                        dm.Meals.Add(new Meal(name, time, nonEmpty));
                    }
                }
                up.Diet = wm;

                _profiles.Add(up);
            }
        }
        private MockPersistence()
        {
            _version = StandardVersion.GetInstance();

            _ingredients = new HashSet <Ingredient>();
            _ingredients.Add("nasello");
            _ingredients.Add("maiale");
            _ingredients.Add("pasta");
            _ingredients.Add("cipolla");
            _ingredients.Add("pomodorini");
            _ingredients.Add("ragù di carne");
            _ingredients.Add("pollo");
            _ingredients.Add("tacchino");
            _ingredients.Add("vitello");
            _ingredients.Add("maionese");
            _ingredients.Add("tonno");
            _ingredients.Add("capperi");
            _ingredients.Add("mozzarella");
            _ingredients.Add("salsiccia");
            _ingredients.Add("patate");
            _ingredients.Add("seppia");
            _ingredients.Add("calamaro");
            _ingredients.Add("gambero");
            _ingredients.Add("pane");
            _ingredients.Add("insalata");
            _ingredients.Add("pomodoro");
            _ingredients.Add("scamorza");
            _ingredients.Add("formaggio");
            _ingredients.Add("grana");
            _ingredients.Add("Cipolla");
            _ingredients.Add("Origano");
            _ingredients.Add("Paprica");
            _ingredients.Add("Prezzemolo");
            _ingredients.Add("Pastinaca");
            _ingredients.Add("Piselli");
            _ingredients.Add("Peperoni");
            _ingredients.Add("pimento");
            _ingredients.Add("fagioli");
            _ingredients.Add("pianta");
            _ingredients.Add("Patata");
            _ingredients.Add("Zucca");
            _ingredients.Add("radicchio");
            _ingredients.Add("Ravanello");
            _ingredients.Add("peperoncino");
            _ingredients.Add("rabarbaro");
            _ingredients.Add("Tuberi");
            _ingredients.Add("rosmarino");
            _ingredients.Add("rapa");
            _ingredients.Add("saggio");
            _ingredients.Add("Scalogno");
            _ingredients.Add("piselli");
            _ingredients.Add("soia");
            _ingredients.Add("zucca");
            _ingredients.Add("Spinaci");
            _ingredients.Add("Cipollotto");
            _ingredients.Add("Schiacciare");
            _ingredients.Add("zucche");
            _ingredients.Add("svedese");
            _ingredients.Add("Patata dolce");
            _ingredients.Add("Mais");
            _ingredients.Add("pepe");
            _ingredients.Add("Timo");
            _ingredients.Add("Pomodoro");
            _ingredients.Add("tuberi");
            _ingredients.Add("Rapa");
            _ingredients.Add("Rapa");
            _ingredients.Add("Wasabi");
            _ingredients.Add("Castagna");
            _ingredients.Add("Crescione");
            _ingredients.Add("ravanello bianco");
            _ingredients.Add("patata dolce");
            _ingredients.Add("Zucchine");


            _dishes = new HashSet <Dish>();
            NonEmptyList <Ingredient> ingredients = new NonEmptyList <Ingredient>("pasta");

            ingredients.Add("ragù di carne");
            _dishes.Add(new Dish("Pasta al ragù alla bolognese", 406, 15.43, 3.23, 76.61, ingredients));
            ingredients = new NonEmptyList <Ingredient>("nasello");
            ingredients.Add("cipolla");
            ingredients.Add("pomodorini");
            _dishes.Add(new Dish("Nasello alla cipolla con pomodorini", 234, 17.31, 1.52, 23.35, ingredients));
            ingredients = new NonEmptyList <Ingredient>("carne di maiale");
            _dishes.Add(new Dish("Braciola di maiale", 217, 24.28, 12.67, 0, ingredients));
            ingredients = new NonEmptyList <Ingredient>("gambero");
            ingredients.Add("pane");
            _dishes.Add(new Dish("Spiedini di gamberi", 217, 24.28, 12.67, 0, ingredients));
            ingredients = new NonEmptyList <Ingredient>("seppia");
            ingredients.Add("pane");
            _dishes.Add(new Dish("Spiedini di seppie", 217, 24.28, 12.67, 0, ingredients));
            ingredients = new NonEmptyList <Ingredient>("salsiccia");
            ingredients.Add("patate");
            _dishes.Add(new Dish("Salsiccia al forno con patate", 436, 24.28, 12.67, 0, ingredients));

            _profiles = new List <UserProfile>();
            PersonalDetails   details     = new PersonalDetails("Pippa", "Labamba", new DateTime(1994, 08, 25), 58, 161, Sex.FEMALE, 30, Load.HEAVY, 15, Load.NORMAL);
            List <Ingredient> preferences = new List <Ingredient>();

            preferences.Add("pasta");
            preferences.Add("maiale");
            preferences.Add("pane");
            _profiles.Add(new UserProfile(preferences, DietCalculators.Goal.WEIGHT_LOSS, null, details));

            details     = new PersonalDetails("Giro", "Ditalia", new DateTime(1994, 10, 11), 120, 178, Sex.MALE, 40, Load.LIGHT, 1, Load.LIGHT);
            preferences = new List <Ingredient>();
            preferences.Add("pasta");
            preferences.Add("maiale");
            preferences.Add("pane");
            _profiles.Add(new UserProfile(preferences, DietCalculators.Goal.WEIGHT_LOSS, null, details));
        }