Пример #1
0
        public static MidAlerts Parse(string data)
        {
            MidAlerts result = new MidAlerts();

            result.Alerts   = new List <MidAlert>();
            result.Semester = new Regex("<img src=./image/or_ball.gif>([^<]+)</h3>", RegexOptions.Multiline | RegexOptions.IgnoreCase).Match(data).Groups[1].Value.Trim();
            var regex   = new Regex("<tr><td align=Right>([^\n]*)\n<td align=Center>([^\n]*)\n<td align=Left>([^\n]*)\n<th align=Right>([^\n]*)\n<td align=Left>([^\n]*)\n<th>([^<]*)<th>([^<]*)<th>(\\d+) / (\\d+)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            var matches = regex.Matches(data);

            foreach (Match match in matches)
            {
                MidAlert alert = new MidAlert();
                alert.CourseNumber   = match.Groups[1].Value;
                alert.Type           = match.Groups[2].Value;
                alert.CourseName     = match.Groups[3].Value;
                alert.Credit         = float.Parse(match.Groups[4].Value);
                alert.Note           = match.Groups[5].Value;
                alert.Alerted        = !string.IsNullOrWhiteSpace(match.Groups[6].Value);
                alert.AlertSubmitted = string.IsNullOrWhiteSpace(match.Groups[7].Value);
                alert.Ratio          = new MidAlert.AlertRatio();
                alert.Ratio.Alerted  = int.Parse(match.Groups[8].Value);
                alert.Ratio.All      = int.Parse(match.Groups[9].Value);
                result.Alerts.Add(alert);
            }

            return(result);
        }
Пример #2
0
        public static async Task <MidAlerts> GetMidAlerts()
        {
            var url      = "https://aps-stu.ntut.edu.tw/StuQuery/QrySCWarn.jsp";
            var response = await Request(url, "GET");

            string responseString = await ConvertStreamToString(await response.Content.ReadAsStreamAsync(), true);

            response.Dispose();

            if (responseString.Contains("應用系統已中斷連線,請重新由入口網站主畫面左方的主選單,點選欲使用之系統!"))
            {
                throw new SessionExpiredException();
            }

            return(MidAlerts.Parse(responseString));
        }