Пример #1
0
        /* ReadTxtFile parses data fron the .txt file stored in the Assets directory
         * and creates Dining Location objects and created Food objects within each Dining Location Object
         */
        public async void ReadTxtFile()
        {
            Dining_Location Current_DL = null;
            string          L;

            using (Stream stream = await FileSystem.OpenAppPackageFileAsync("TTU_Meal_Objs.txt"))
            {
                using (StreamReader sr = new StreamReader(stream))
                {
                    while ((L = sr.ReadLine()) != null)
                    {
                        //Console.WriteLine(L);
                        //Check if there is a new DiningLocation
                        if (L.Contains("->"))
                        {
                            string          Title = L.Substring(2);
                            Dining_Location DL    = new Dining_Location(Title);
                            if (Current_DL != null)
                            {
                                Current_DL.getSortedFood();
                                TTU_Meal_Data.Add(Current_DL);
                            }
                            Current_DL = DL;
                        }
                        else if (!L.Equals(""))
                        {
                            Food F = new Food(L);
                            Current_DL.Add_Food(F);
                        }
                    }
                }
            }
        }
Пример #2
0
        private Dining_Location Create_Obj(string PDFN)
        {
            string RawD = ExtractTextFromPdf(PDFN);

            //Console.WriteLine(RawD);
            string[] Lines = Regex.Split(RawD, "\r\n|\r|\n");

            //Create Header
            string Header = FormatHeader(PDFN);
            //Console.WriteLine(Header);

            Dining_Location DL = new Dining_Location(Header);

            //Get Data and send it to the Food Object
            List <string> Formatted_Sheet = Format_Sheet(Lines);
            string        CurrentLabel    = "Offered Food";

            foreach (string L in Formatted_Sheet)
            {
                //Test to see if L is correctly formatted for food item
                string newS = L.Replace("<", "");
                newS = newS.Replace(">", "");
                newS = Regex.Replace(newS, "[\\d*]", "@");
                //Console.WriteLine(newS + "\n");
                string[] AllP = newS.Split(" @");
                if (L.Contains("| LABEL"))
                {
                    CurrentLabel = L.Replace("| LABEL", "").Replace("Serving Size", "").Replace("180 2 24 1 4  Wheat, Milk, Soy", "")
                                   .Replace("Serving Size Calories Fat (g) Carbs (g) Fiber Protein (g) Vegan Vegetarian Gluten Free Allergen/Contains", "")
                                   .Replace("<", "").Replace("Nuts Pecans/Walnuts", "").Replace("", "").Replace("Wheat, Milk, Soy", "").Replace("?", "");
                    CurrentLabel = Regex.Replace(CurrentLabel, "[\\d*]", "");
                }
                else if (AllP.Length == 7)
                {
                    //Add to the list of food in the Dining Location
                    Food NewF = new Food(Header, CurrentLabel, L);
                    DL.Add_Food(NewF);
                }

                //Console.WriteLine(L + "\n");
            }

            return(DL);
        }