示例#1
0
        private static async void GetCrawling()
        {
            DataInfo.Add("SchoolNotice", new Dictionary <string, string>());
            DataInfo.Add("SchoolNewsletter", new Dictionary <string, string>());

            while (true)
            {
                try
                {
                    Logger.LogInformation("<Server> 학교 홈페이지 크롤링: 학교 공지사항을 가져옵니다.");
                    var tmpSchoolNotice = GetSchoolNotice();

                    Logger.LogInformation("<Server> 가정통신문 크롤링: 학교 공지사항을 가져옵니다.");
                    var tmpSchoolNewsletter = GetSchoolNewsletter();

                    if (tmpSchoolNotice != null)
                    {
                        // 학교 공지사항 데이터 값의 변화가 있는지 확인
                        if (SchoolNotice != null)
                        {
                            if (!JsonCompare(tmpSchoolNotice, SchoolNotice))
                            {
                                SchoolNotice = tmpSchoolNotice;

                                DataInfo["SchoolNotice"].Remove("LastUpdate");
                                DataInfo["SchoolNotice"].Add("LastUpdate", DateTime.Now.ToString());

                                DataInfo["SchoolNotice"].Remove("Size");
                                DataInfo["SchoolNotice"].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpSchoolNotice)).ToString());
                            }
                        }
                        else
                        {
                            SchoolNotice = tmpSchoolNotice;

                            DataInfo["SchoolNotice"].Add("LastUpdate", DateTime.Now.ToString());
                            DataInfo["SchoolNotice"].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpSchoolNotice)).ToString());
                        }
                    }
                    else
                    {
                        continue;
                    }

                    if (tmpSchoolNewsletter != null)
                    {
                        // 가정통신문 데이터 값의 변화가 있는지 확인
                        if (SchoolNewsletter != null)
                        {
                            if (!JsonCompare(tmpSchoolNewsletter, SchoolNewsletter))
                            {
                                SchoolNewsletter = tmpSchoolNewsletter;

                                DataInfo["SchoolNewsletter"].Remove("LastUpdate");
                                DataInfo["SchoolNewsletter"].Add("LastUpdate", DateTime.Now.ToString());

                                DataInfo["SchoolNewsletter"].Remove("Size");
                                DataInfo["SchoolNewsletter"].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpSchoolNewsletter)).ToString());
                            }
                        }
                        else
                        {
                            SchoolNewsletter = tmpSchoolNewsletter;

                            DataInfo["SchoolNewsletter"].Add("LastUpdate", DateTime.Now.ToString());
                            DataInfo["SchoolNewsletter"].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpSchoolNewsletter)).ToString());
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError("<Server> 학교 홈페이지 크롤링: 오류 (" + e.Message + ")");
                    continue;
                }

                await Task.Delay(1800000); // 1000 = 1초, 기본: 30분 (1800000)
            }
        }
示例#2
0
        private static async void GetData()
        {
            DataInfo.Add("LunchMenu", new Dictionary <string, string>());
            DataInfo.Add("SchoolSchedule", new Dictionary <string, string>());

            while (true)
            {
                try
                {
                    Logger.LogInformation("<Server> 데이터 가져오기: 시간표를 가져옵니다.");
                    var tmpTimetable = GetTimetable(); // 시간표 가져오기

                    Logger.LogInformation("<Server> 데이터 가져오기: 급식 메뉴를 가져옵니다.");
                    var tmpLunchMenu = GetLunchMenu(); // 급식 메뉴 가져오기

                    Logger.LogInformation("<Server> 데이터 가져오기: 학사 일정을 가져옵니다.");
                    var tmpSchoolSchedule = GetSchoolSchedule(); // 학사 일정 가져오기

                    if (tmpTimetable != null)
                    {
                        // 시간표 데이터 값의 변화가 있는지 확인
                        if (Timetable != null)
                        {
                            if (!JsonCompare(tmpTimetable, Timetable))
                            {
                                Timetable = tmpTimetable;

                                foreach (var className in tmpTimetable.Keys)
                                {
                                    DataInfo["Timetable-" + className].Remove("LastUpdate");
                                    DataInfo["Timetable-" + className].Add("LastUpdate", DateTime.Now.ToString());

                                    DataInfo["Timetable-" + className].Remove("Size");
                                    DataInfo["Timetable-" + className].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpTimetable[className])).ToString());
                                }
                            }
                        }
                        else
                        {
                            Timetable = tmpTimetable;

                            foreach (var className in tmpTimetable.Keys)
                            {
                                DataInfo.Add("Timetable-" + className, new Dictionary <string, string>());

                                DataInfo["Timetable-" + className].Add("LastUpdate", DateTime.Now.ToString());
                                DataInfo["Timetable-" + className].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpTimetable[className])).ToString());
                            }
                        }
                    }

                    if (tmpLunchMenu != null)
                    {
                        // 급식 메뉴 데이터 값의 변화가 있는지 확인
                        if (LunchMenu != null)
                        {
                            if (!JsonCompare(tmpLunchMenu, LunchMenu))
                            {
                                LunchMenu = tmpLunchMenu;

                                DataInfo["LunchMenu"].Remove("LastUpdate");
                                DataInfo["LunchMenu"].Add("LastUpdate", DateTime.Now.ToString());

                                DataInfo["LunchMenu"].Remove("Size");
                                DataInfo["LunchMenu"].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpLunchMenu)).ToString());
                            }
                        }
                        else
                        {
                            LunchMenu = tmpLunchMenu;

                            DataInfo["LunchMenu"].Add("LastUpdate", DateTime.Now.ToString());
                            DataInfo["LunchMenu"].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpLunchMenu)).ToString());
                        }
                    }

                    if (tmpSchoolSchedule != null)
                    {
                        // 학사 일정 데이터 값의 변화가 있는지 확인
                        if (SchoolSchedule != null)
                        {
                            if (!JsonCompare(tmpSchoolSchedule, SchoolSchedule))
                            {
                                SchoolSchedule = tmpSchoolSchedule;

                                DataInfo["SchoolSchedule"].Remove("LastUpdate");
                                DataInfo["SchoolSchedule"].Add("LastUpdate", DateTime.Now.ToString());

                                DataInfo["SchoolSchedule"].Remove("Size");
                                DataInfo["SchoolSchedule"].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpSchoolSchedule)).ToString());
                            }
                        }
                        else
                        {
                            SchoolSchedule = tmpSchoolSchedule;

                            DataInfo["SchoolSchedule"].Add("LastUpdate", DateTime.Now.ToString());
                            DataInfo["SchoolSchedule"].Add("Size", ByteSize.FromBytes(GetJsonByteLength(tmpSchoolSchedule)).ToString());
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError("<Server> 데이터 가져오기: 오류 (" + e.Message + ")");
                    continue;
                }

                await Task.Delay(1800000); // 1000 = 1초, 기본: 30분 (1800000)
            }
        }