Example #1
0
        public static CheckMessage GetMessage(string html, out double percent)
        {
            CheckMessage message = new CheckMessage();
            Match        match   = Regex.Match(html, @"<p>用户:<code>(.+)</code>");

            message.Username = match.Groups[1].Value.Trim();
            match            = Regex.Match(html, @"等级:.+<code>(.+)</code>");
            message.Level    = match.Groups[1].Value.Trim();
            match            = Regex.Match(html, @"总流量:<code>(.+)</code>");
            message.All      = match.Groups[1].Value.Trim();
            match            = Regex.Match(html, @"已用流量:<code>(.+)</code>");
            message.Used     = match.Groups[1].Value.Trim();
            match            = Regex.Match(html, @"剩余流量:<code>(.+)</code>");
            message.Surplus  = match.Groups[1].Value.Trim();
            double all = 1;

            double.TryParse(Regex.Match(message.All, @"[0-9]+").Value, out all);
            double used = 0;

            double.TryParse(Regex.Match(message.Used, @"[0-9]+").Value, out used);
            if (message.All.EndsWith("MB"))
            {
                all = all * 1024 * 1024;
            }
            else if (message.All.EndsWith("GB"))
            {
                all = all * 1024 * 1024 * 1024;
            }
            else if (message.All.EndsWith("TB"))
            {
                all = all * 1024 * 1024 * 1024 * 1024;
            }
            if (message.Used.EndsWith("MB"))
            {
                used = used * 1024 * 1024;
            }
            else if (message.Used.EndsWith("GB"))
            {
                used = used * 1024 * 1024;
            }
            else if (message.Used.EndsWith("TB"))
            {
                used = used * 1024 * 1024 * 1024 * 1024;
            }
            percent = used / all;
            return(message);
        }
Example #2
0
        private void Refresh(Action errorHandle)
        {
            int    flag = 0;
            string html = "failed";

            while (html == "failed")
            {
                html = RequsetHelper.GetHtml(Cookie.email, Cookie.key, Cookie.uid, Cookie.expire_in);
                if (flag > 5)
                {
                    MessageBox.Show("连接超时");
                    return;
                }
            }
            if (!html.Contains("总流量"))
            {
                errorHandle();
                return;
            }
            message          = TextHelper.GetMessage(html, out double percent);
            notifyIcon1.Icon = ImageHelper.MakeIcon(percent);
            notifyIcon1.Text = String.Format("用户名:{0}\r\n用户等级:{1}\r\n总流量:{2}\r\n已用流量:{3}\r\n剩余流量:{4}", message.Username, message.Level, message.All, message.Used, message.Surplus);
            this.Visible     = false;
        }