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)
|