Exemplo n.º 1
0
        public async Task <List <RozkladLesson>[]> GetTimetable()
        {
            try
            {
                await InitRequest();
            }
            catch (Exception e)
            {
            }
            //Group selection
            Timetable.AddNew("ctl00$MainContent$ctl00$txtboxGroup", Group);
            message = new HttpRequestMessage();
            SetHeaders();
            message.Headers.AddIfNotExists("Referer", "http://rozklad.kpi.ua/Schedules/ScheduleGroupSelection.aspx");
            message.Method     = HttpMethod.Post;
            message.RequestUri = new Uri("http://rozklad.kpi.ua/Schedules/ScheduleGroupSelection.aspx");
            Timetable.AddIfNotExists("ctl00$MainContent$ctl00$btnShowSchedule", "Розклад занять");
            message.Content = new FormUrlEncodedContent(Timetable);
            var response = await client.SendAsync(message).Result.Content.ReadAsStringAsync();

            var document = new HtmlDocument();

            document.LoadHtml(response);
            var result = new List <RozkladLesson> [2];

            result[0] = ParseTable(document.DocumentNode.SelectSingleNode($@"//table[@id='{FirstWeek}']"), true);
            result[1] = ParseTable(document.DocumentNode.SelectSingleNode($@"//table[@id='{SecondWeek}']"), false);
            foreach (var item in result[0])
            {
                if (!Teachers.Exists(t => t.Name == item.Teacher.Name))
                {
                    Teachers.Add(item.Teacher);
                }
                if (!Subjects.Exists(t => t.Title == item.Subject.Title))
                {
                    Subjects.Add(item.Subject);
                }
            }
            foreach (var item in result[1])
            {
                if (!Teachers.Exists(t => t.Name == item.Teacher.Name))
                {
                    Teachers.Add(item.Teacher);
                }
                if (!Subjects.Exists(t => t.Title == item.Subject.Title))
                {
                    Subjects.Add(item.Subject);
                }
            }
            RozkladTimeTable = result;
            return(result);
        }