设为首页 加入收藏

TOP

写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我(三)
2017-10-13 10:39:34 】 浏览:9136
Tags:一个 Windows 服务 通过 模拟 网站 用户 登录 BUG 查询 有没有 提醒
tPtr hServer,
int SessionId, String pTitle, int TitleLength, String pMessage, int MessageLength, int Style, int Timeout, out int pResponse, bool bWait); public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero; private System.Timers.Timer timer; private static List<int> idList = new List<int>(); private string loginUrl = ConfigurationManager.AppSettings["loginUrl"]; private string listUrl = ConfigurationManager.AppSettings["bugListUrl"]; private string userLogin = ConfigurationManager.AppSettings["userName"]; private string userPassword = ConfigurationManager.AppSettings["userPassword"]; private Regex regTr = new Regex(@"<tr class=""listTableLine(?:(?!</tr>)[\s\S])*</tr>", RegexOptions.IgnoreCase); private Regex regTd = new Regex(@"<td align=""left"">((?:(?!</td>)[\s\S])*)</td>", RegexOptions.IgnoreCase); private int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["pageSize"]); private double interval = Convert.ToDouble(ConfigurationManager.AppSettings["interval"]); private string projectId = ConfigurationManager.AppSettings["projectId"]; public BugMonitorService() { InitializeComponent(); } public static void ShowMessageBox(string message, string title) { int resp = 0; WTSSendMessage( WTS_CURRENT_SERVER_HANDLE, WTSGetActiveConsoleSessionId(), title, title.Length, message, message.Length, 0, 0, out resp, false); } protected override void OnStart(string[] args) { LogUtil.path = Application.StartupPath + "\\log"; timer = new System.Timers.Timer(interval * 60 * 1000); timer.Elapsed += new System.Timers.ElapsedEventHandler(Action); timer.Start(); LogUtil.Log("服务启动成功"); } protected override void OnStop() { if (timer != null) { timer.Stop(); timer.Close(); timer.Dispose(); timer = null; } LogUtil.Log("服务停止成功"); Thread.Sleep(100); //等待一会,待日志写入文件 } public void Start() { OnStart(null); } public void Action(object sender, ElapsedEventArgs e) { try { Task.Factory.StartNew(() => { try { int bugCount = 0; string loginResult = HttpUtil.HttpPost(loginUrl, string.Format("uer={0}&userPassword={1}&submit=%E7%99%BB%E5%BD%95&userLogin={0}&uer=", userLogin, userPassword)); string result = HttpUtil.HttpPost(listUrl, string.Format("projectId={0}&perListDPF={1}&sortFieldDPF=bugCode&sortSequenceDPF=1&bugStatus=1", projectId, pageSize)); ProcessBug(result, ref bugCount); result = HttpUtil.HttpPost(listUrl, string.Format("projectId={0}&perListDPF={1}&sortFieldDPF=bugCode&sortSequenceDPF=1&bugStatus=3", projectId, pageSize)); ProcessBug(result, ref bugCount); if (bugCount > 0) { ShowMessageBox(string.Format("您有 {0} 个新BUG", bugCount), "提醒"); } else { LogUtil.Log("没有新BUG"); } } catch (Exception ex) { LogUtil.LogError(ex.Message + "\r\n" + ex.StackTrace); } }); } catch (Exception ex)
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇.Net Core 读取配置文件 下一篇关于StreamReader.ReadToEnd方法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目