Пример #1
0
        static void SreachLectureDemo()
        {
            Console.WriteLine("Starting up the database...");
            //the list that the engine should look to
            var lectureList = ApuBot.LecturesList();

            while (true)
            {
                Console.WriteLine("There are " + lectureList.Count + " lectures in the database");
                Console.WriteLine("Type a search term (type exit to terminate): ");
                string query = Console.ReadLine().ToLower();

                if (query.Contains("exit"))
                {
                    Console.WriteLine("Exiting...");
                    break;
                }

                Console.WriteLine("Searching...");

                //search the given database with the given query
                var searchResults = SearchEngine.SearchLecture(query, lectureList);

                //show the search results
                if (SearchEngine.ResultCount > 0)
                {
                    foreach (var res in searchResults)
                    {
                        string outputRow = res.Term + ApuBot.delimiter
                                           + res.SubjectNameEN + ApuBot.delimiter
                                           + res.Classroom + ApuBot.delimiter
                                           + res.InstructorEN + ApuBot.delimiter
                                           + res.Grade + ApuBot.delimiter;

                        foreach (var n in res.TimetableCells)
                        {
                            outputRow += n.DayOfWeek + "-" + n.Period
                                         + $"[{n.Column} - {n.Row}]" + ApuBot.delimiter;
                        }

                        Console.WriteLine(outputRow);
                    }
                    Console.WriteLine("Took " + SearchEngine.LastSearchTime + " ms");
                    Console.WriteLine("Found " + SearchEngine.ResultCount + " items");
                    Console.WriteLine("============================");
                }
                else
                {
                    Console.WriteLine("No results found");
                    Console.WriteLine("============================");
                }
            }
        }
Пример #2
0
        static async Task GetDatabaseContentAsync()
        {
            var listFromDb = await Database.GetAllLecturesAsync();

            //check if the database is empty or not
            if (listFromDb.Count <= 0)
            {
                Console.WriteLine("The database is empty, will get new lectures");
                var newLectures = ApuBot.LecturesList();

                await Database.SaveAllLecturesAsync(newLectures);

                Console.WriteLine("Finished saving all the lectures!");
            }
            else
            {
                Console.WriteLine($"Found {listFromDb.Count} items from an existing database, listing all of them...");
                var currentLectures = await Database.GetAllLecturesAsync();

                foreach (var i in currentLectures)
                {
                    string row = i.Term + ApuBot.delimiter
                                 + i.SubjectNameEN + ApuBot.delimiter
                                 + i.Semester + ApuBot.delimiter
                                 + i.Curriculum + ApuBot.delimiter
                                 + i.BuildingFloor + ApuBot.delimiter
                                 + i.Classroom + ApuBot.delimiter
                                 + i.InstructorEN + ApuBot.delimiter
                                 + i.Grade + ApuBot.delimiter;


                    if (i.TimetableCells != null)
                    {
                        foreach (var n in i.TimetableCells)
                        {
                            row += n.DayOfWeek + "-" + n.Period
                                   + $"[{n.Column} - {n.Row}]" + ApuBot.delimiter;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No timetable cell");
                    }

                    Console.WriteLine(row);
                }
                var lectureListJson = Database.SerializeToJson(listFromDb);

                Console.WriteLine(lectureListJson);
            }
        }
Пример #3
0
        /// <summary>
        /// This demo will show how the bot gets the lectures, puts them into a list, and prints them
        /// </summary>
        static void GetLecturesDemo()
        {
            //initiate the CSV file which works like a database
            var csv = new StringBuilder();

            var lectureList = ApuBot.LecturesList();

            foreach (var i in lectureList)
            {
                //lectureList.Add(i);

                string row = i.Term + ApuBot.delimiter
                             + i.SubjectNameEN + ApuBot.delimiter
                             + i.Semester + ApuBot.delimiter
                             + i.Curriculum + ApuBot.delimiter
                             + i.BuildingFloor + ApuBot.delimiter
                             + i.Classroom + ApuBot.delimiter
                             + i.InstructorEN + ApuBot.delimiter
                             + i.Grade + ApuBot.delimiter;

                foreach (var n in i.TimetableCells)
                {
                    row += n.DayOfWeek + "-" + n.Period
                           + $"[{n.Column} - {n.Row}]" + ApuBot.delimiter;
                }

                Console.WriteLine(row);

                csv.AppendLine(row);
            }

            //file path for the output
            string filePath = @"output-lectures.csv";

            //output the csv file
            File.WriteAllText(filePath, csv.ToString());

            Console.WriteLine("There are " + lectureList.Count + " items in the list");
        }