Esempio n. 1
0
        private static void SaveObjectToFile(LunchMenu lunchMenu, string filepath)
        {
            var outputFilepath = filepath.Remove(filepath.LastIndexOf('.')) + ".json";

            var json = JsonConvert.SerializeObject(lunchMenu);

            File.WriteAllText(outputFilepath, json);
        }
Esempio n. 2
0
        private static LunchMenu DeserializePDF(XmlNodeList xmlNodeList)
        {
            var lunchMenu = new LunchMenu();

            for (int i = 0; i < xmlNodeList.Count; i += 6)
            {
                var newDay = new Day()
                {
                    DayName = xmlNodeList[i].FirstChild.InnerXml
                };

                for (int j = 1; j < 6; j++)
                {
                    var cellValues = xmlNodeList[i + j].ChildNodes
                                     .Cast <XmlNode>()
                                     .Select(x => x.InnerXml)
                                     .ToArray();

                    var foodStation = new FoodStation()
                    {
                        StationName = cellValues[0],
                        FoodName    = cellValues[1]
                    };


                    // In the case that there are two options (ex. Bowl vs Cup), take the first
                    if (cellValues[2].Split(' ').Count() >= 2)
                    {
                        cellValues[2] = cellValues[2].Split(' ')[0];
                    }

                    // In case the station is CLOSED, don't set the price
                    if (!string.IsNullOrEmpty(cellValues[2]))
                    {
                        foodStation.Price = Double.Parse(cellValues[2].Substring(1));
                    }

                    newDay.FoodStations.Add(foodStation);
                }

                lunchMenu.Add(newDay);
            }

            return(lunchMenu);
        }