//计时器:发送一周邮件报告,每周一早上八点半进行发送 private void _sendWeeklyReportTimer_Tick(object sender, EventArgs e) { DayOfWeek today = DateTime.Now.DayOfWeek; bool orMonday = (today.ToString() == "Monday"); bool timeNow = (DateTime.Now.ToShortTimeString() == "8:30"); if (orMonday == false) { _notSendReport = true; } if (orMonday && timeNow && _notSendReport) { //发送一周总结报告邮件 SendMailSlack sendReportMail = new SendMailSlack(null, "../../../common/WeeklyReport.html", null, null); bool sendSuccess = sendReportMail.SendWeeklyReport(); _notSendReport = false; //进行数据清空 //进行成员数据清空 Dictionary <string, string> clearMemberZero = new Dictionary <string, string>(); clearMemberZero.Add("Week", "0"); clearMemberZero.Add("Success", "0"); clearMemberZero.Add("Failure", "0"); _projectController.ClearTimesAfterSendReport("config/Member", "../../../common/res/InfoStatics.xml", clearMemberZero, "memberTimes"); //进行总提交次数清空 Dictionary <string, string> clearWeekTotalZero = new Dictionary <string, string>(); clearWeekTotalZero.Add("CommitTimes", "0"); clearWeekTotalZero.Add("BuildTimes", "0"); clearWeekTotalZero.Add("BuildSuccessTimes", "0"); clearWeekTotalZero.Add("BuildFailedTimes", "0"); _projectController.ClearTimesAfterSendReport("config/WeekTotal", "../../../common/res/InfoStatics.xml", clearWeekTotalZero, "totalTimes"); //projects进行清空 _projectController.ClearTimesAfterSendReport("config/Projects", "../../../common/res/InfoStatics.xml", null, null); } }
/// <summary> /// 执行发送邮件的操作 /// </summary> /// <param name="projectInfo">projectInfoGetLocal的信息</param> /// <param name="ifSlack">是否向slack发信息</param> /// <param name="ifMail">是否发送邮件</param> private void SendSlackMail(ProjectInfo projectInfo, string mailPath, string xmlPath) { SendMailSlack sendMailSlack = new SendMailSlack(projectInfo, mailPath, updateLog, xmlPath); Thread sendMail = new Thread(sendMailSlack.SendMail); Thread sendSlack = new Thread(sendMailSlack.SendSlack); // Thread sendLogMessage = new Thread(sendMailSlack.SendLogMessage); sendMail.Start(); sendSlack.Start(); // sendLogMessage.Start(); }
//计时器:发送一周邮件报告,每周一早上八点半进行发送 private void _sendWeeklyReportTimer_Tick(object sender, EventArgs e) { DayOfWeek today = DateTime.Now.DayOfWeek; bool orMonday = (today.ToString() == "Monday"); bool timeNow = (DateTime.Now.ToShortTimeString() == "8:30"); if (orMonday == false) { _notSendReport = true; } if (orMonday && timeNow && _notSendReport) { //发送一周总结报告邮件 SendMailSlack sendReportMail = new SendMailSlack(null, "../../../common/WeeklyReport.html", null, null); bool sendSuccess = sendReportMail.SendWeeklyReport(); _notSendReport = false; //进行数据清空 //进行成员数据清空 Dictionary<string, string> clearMemberZero = new Dictionary<string, string>(); clearMemberZero.Add("Week", "0"); clearMemberZero.Add("Success", "0"); clearMemberZero.Add("Failure", "0"); _projectController.ClearTimesAfterSendReport("config/Member", "../../../common/res/InfoStatics.xml", clearMemberZero, "memberTimes"); //进行总提交次数清空 Dictionary<string, string> clearWeekTotalZero = new Dictionary<string, string>(); clearWeekTotalZero.Add("CommitTimes", "0"); clearWeekTotalZero.Add("BuildTimes", "0"); clearWeekTotalZero.Add("BuildSuccessTimes", "0"); clearWeekTotalZero.Add("BuildFailedTimes", "0"); _projectController.ClearTimesAfterSendReport("config/WeekTotal", "../../../common/res/InfoStatics.xml", clearWeekTotalZero, "totalTimes"); //projects进行清空 _projectController.ClearTimesAfterSendReport("config/Projects", "../../../common/res/InfoStatics.xml", null, null); } }
/// <summary> /// 设置计时器触发的执行事件 /// </summary> private void timer_Tick(object sender, EventArgs e) { //如果运行的是windows服务则刷新当前运行项目状态 ConfigInfo serviceInfo = _configController.ConfigQuery("config/preferences", "../../../common/res/CIConfig.xml"); //获取所有的项目数量 List<ProjectInfo> projectInfoCount = _projectController.ProjectQuery("/config/Projects", true, "../../../common/res/CIConfig.xml"); string mailPath = "../../../common/SendMail.html"; string xmlPath = "../../../common/res/CIConfig.xml"; if (serviceInfo.ServiceSwitch == "service") { InitPage(); } else { _timer.Stop(); List<ProjectInfo> projectInfos = _projectController.ProjectQuery("/config/Projects", true, "../../../common/res/CIConfig.xml"); Task buildTask = new Task(() => { foreach (var projectInfo in projectInfos) { if (projectInfo.Statusproperty == "true") { Dispatcher.BeginInvoke(new Action(() => { ProjectName.Text = projectInfo.Nameproperty; ImgSource.Source = new BitmapImage(new Uri("../images/dot_yellow.png", UriKind.Relative)); })); //保存修改前的版本以便回滚 ProjectInfo lastestInfo = _projectController.ProjectQuery("config/lastest", false, "../../../common/res/LastestInfo.xml").First(); //将当前运行项目及运行状态存储 Dictionary<string, string> startValue = new Dictionary<string, string>(); startValue.Add("projectName", projectInfo.Nameproperty); startValue.Add("result", "running"); _projectController.ModifyProject(startValue, null, "../../../common/res/LastestInfo.xml", "lastest"); //更新项目,若版本号未变则无需编译否则编译 Boolean updateResult = UpdateProject(projectInfo); //如果无需编译,则结果会滚到改变前的版本 // 测试用的语句 if (updateResult) //test code // if(false) { Dispatcher.BeginInvoke(new Action(() => { Dictionary<string, string> revertLastInfo = new Dictionary<string, string>(); revertLastInfo.Add("projectName", lastestInfo.Nameproperty); revertLastInfo.Add("result", lastestInfo.Result); _projectController.ModifyProject(revertLastInfo, null, "../../../common/res/LastestInfo.xml", "lastest"); InitPage(); })); } else { //发送更新信息 ProjectInfo projectInfoGetLocal = _svnController.GetLocalInfo(projectInfo); projectInfoGetLocal.Revision = _latestRevision; Dictionary<string, string> setValue = new Dictionary<string, string>(); setValue.Add("Name", projectInfoGetLocal.Author.Split('\\')[1]); _projectController.CommitStat("update", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); //检查infoStatics文件夹中有没有提交的项目,若是有则进行相对应的节点数值加1处理,若是没有,则进行创建,并进行初始化 List<ProjectInfo> checkProjectInfos = _projectController.ProjectQuery("/config/Projects", true,"../../../common/res/InfoStatics.xml"); //进行创建 bool whetherCreateAtInfoStatics = true; foreach (ProjectInfo proName in checkProjectInfos) { if (proName.Nameproperty == projectInfo.Nameproperty) { whetherCreateAtInfoStatics = false; break; } } if (checkProjectInfos.Count == 0 || whetherCreateAtInfoStatics) { var childNodes = new Dictionary<string, string>(); var property = new Dictionary<string, string>(); childNodes.Add("Commit","1"); childNodes.Add("Build","0"); childNodes.Add("Success","0"); childNodes.Add("Failed","0"); property.Add("Name",projectInfo.Nameproperty); _projectController.AddProject(childNodes,property, "../../../common/res/InfoStatics.xml"); } //进行加1处理 else { Dictionary<string, string> projectName = new Dictionary<string, string>(); projectName.Add("Name",projectInfo.Nameproperty); _projectController.CommitStat("projectsCommit", projectName, "config/Projects", "../../../common/res/InfoStatics.xml"); } if (updateLog.Contains("Node remains in conflict")) { SendMailSlack sendMailSlack = new SendMailSlack(projectInfoGetLocal, null, updateLog, xmlPath); Thread sendLogMessage = new Thread(sendMailSlack.SendConflictsMessage); sendLogMessage.Start(); } else { SendMailSlack sendMailSlack = new SendMailSlack(projectInfoGetLocal, null, updateLog, xmlPath); Thread sendLogMessage = new Thread(sendMailSlack.SendLogMessage); sendLogMessage.Start(); //编译项目 ProjectInfo buildFinishedInfo = BuildProject(projectInfoGetLocal); //存储编译信息 SaveInfo(buildFinishedInfo); if (buildFinishedInfo.Result == "successful") { _projectController.CommitStat("success", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); //对于所编译的项目加1操作 Dictionary<string, string> projectName = new Dictionary<string, string>(); projectName.Add("Name", projectInfo.Nameproperty); _projectController.CommitStat("projectSuccess", projectName, "config/Projects", "../../../common/res/InfoStatics.xml"); } else if (buildFinishedInfo.Result == "failed") { _projectController.CommitStat("failure", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); Dictionary<string, string> projectName = new Dictionary<string, string>(); projectName.Add("Name", projectInfo.Nameproperty); _projectController.CommitStat("projectFailed", projectName, "config/Projects", "../../../common/res/InfoStatics.xml"); } Dispatcher.BeginInvoke(new Action(() => { InitPage(); })); //先从本地svn完善项目信息后自动发送邮件 // ProjectInfo projectInfoGetLocal = _svnController.GetLocalInfo(buildFinishedInfo); SendSlackMail(buildFinishedInfo, mailPath, xmlPath); } } } } }); buildTask.Start(); Task nextBuild = buildTask.ContinueWith((t => { XmlNodeList xmlNodeLost = _configController.FindConfigInfo("/config/preferences/UpdateInterval", "../../../common/res/CIConfig.xml"); int updateInterval = int.Parse(xmlNodeLost[0].InnerText); Thread.Sleep(updateInterval*60*1000); _timer.Start(); //遍历编译完成,重新启动计时器 })); } }
/// <summary> /// 设置计时器触发的执行事件 /// </summary> private void timer_Tick(object sender, EventArgs e) { //如果运行的是windows服务则刷新当前运行项目状态 ConfigInfo serviceInfo = _configController.ConfigQuery("config/preferences", "../../../common/res/CIConfig.xml"); //获取所有的项目数量 List <ProjectInfo> projectInfoCount = _projectController.ProjectQuery("/config/Projects", true, "../../../common/res/CIConfig.xml"); string mailPath = "../../../common/SendMail.html"; string xmlPath = "../../../common/res/CIConfig.xml"; if (serviceInfo.ServiceSwitch == "service") { InitPage(); } else { _timer.Stop(); List <ProjectInfo> projectInfos = _projectController.ProjectQuery("/config/Projects", true, "../../../common/res/CIConfig.xml"); Task buildTask = new Task(() => { foreach (var projectInfo in projectInfos) { if (projectInfo.Statusproperty == "true") { Dispatcher.BeginInvoke(new Action(() => { ProjectName.Text = projectInfo.Nameproperty; ImgSource.Source = new BitmapImage(new Uri("../images/dot_yellow.png", UriKind.Relative)); })); //保存修改前的版本以便回滚 ProjectInfo lastestInfo = _projectController.ProjectQuery("config/lastest", false, "../../../common/res/LastestInfo.xml").First(); //将当前运行项目及运行状态存储 Dictionary <string, string> startValue = new Dictionary <string, string>(); startValue.Add("projectName", projectInfo.Nameproperty); startValue.Add("result", "running"); _projectController.ModifyProject(startValue, null, "../../../common/res/LastestInfo.xml", "lastest"); //更新项目,若版本号未变则无需编译否则编译 Boolean updateResult = UpdateProject(projectInfo); //如果无需编译,则结果会滚到改变前的版本 // 测试用的语句 if (updateResult) //test code // if(false) { Dispatcher.BeginInvoke(new Action(() => { Dictionary <string, string> revertLastInfo = new Dictionary <string, string>(); revertLastInfo.Add("projectName", lastestInfo.Nameproperty); revertLastInfo.Add("result", lastestInfo.Result); _projectController.ModifyProject(revertLastInfo, null, "../../../common/res/LastestInfo.xml", "lastest"); InitPage(); })); } else { //发送更新信息 ProjectInfo projectInfoGetLocal = _svnController.GetLocalInfo(projectInfo); projectInfoGetLocal.Revision = _latestRevision; Dictionary <string, string> setValue = new Dictionary <string, string>(); setValue.Add("Name", projectInfoGetLocal.Author.Split('\\')[1]); _projectController.CommitStat("update", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); //检查infoStatics文件夹中有没有提交的项目,若是有则进行相对应的节点数值加1处理,若是没有,则进行创建,并进行初始化 List <ProjectInfo> checkProjectInfos = _projectController.ProjectQuery("/config/Projects", true, "../../../common/res/InfoStatics.xml"); //进行创建 bool whetherCreateAtInfoStatics = true; foreach (ProjectInfo proName in checkProjectInfos) { if (proName.Nameproperty == projectInfo.Nameproperty) { whetherCreateAtInfoStatics = false; break; } } if (checkProjectInfos.Count == 0 || whetherCreateAtInfoStatics) { var childNodes = new Dictionary <string, string>(); var property = new Dictionary <string, string>(); childNodes.Add("Commit", "1"); childNodes.Add("Build", "0"); childNodes.Add("Success", "0"); childNodes.Add("Failed", "0"); property.Add("Name", projectInfo.Nameproperty); _projectController.AddProject(childNodes, property, "../../../common/res/InfoStatics.xml"); } //进行加1处理 else { Dictionary <string, string> projectName = new Dictionary <string, string>(); projectName.Add("Name", projectInfo.Nameproperty); _projectController.CommitStat("projectsCommit", projectName, "config/Projects", "../../../common/res/InfoStatics.xml"); } if (updateLog.Contains("Node remains in conflict")) { SendMailSlack sendMailSlack = new SendMailSlack(projectInfoGetLocal, null, updateLog, xmlPath); Thread sendLogMessage = new Thread(sendMailSlack.SendConflictsMessage); sendLogMessage.Start(); } else { SendMailSlack sendMailSlack = new SendMailSlack(projectInfoGetLocal, null, updateLog, xmlPath); Thread sendLogMessage = new Thread(sendMailSlack.SendLogMessage); sendLogMessage.Start(); //编译项目 ProjectInfo buildFinishedInfo = BuildProject(projectInfoGetLocal); //存储编译信息 SaveInfo(buildFinishedInfo); if (buildFinishedInfo.Result == "successful") { _projectController.CommitStat("success", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); //对于所编译的项目加1操作 Dictionary <string, string> projectName = new Dictionary <string, string>(); projectName.Add("Name", projectInfo.Nameproperty); _projectController.CommitStat("projectSuccess", projectName, "config/Projects", "../../../common/res/InfoStatics.xml"); } else if (buildFinishedInfo.Result == "failed") { _projectController.CommitStat("failure", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); Dictionary <string, string> projectName = new Dictionary <string, string>(); projectName.Add("Name", projectInfo.Nameproperty); _projectController.CommitStat("projectFailed", projectName, "config/Projects", "../../../common/res/InfoStatics.xml"); } Dispatcher.BeginInvoke(new Action(() => { InitPage(); })); //先从本地svn完善项目信息后自动发送邮件 // ProjectInfo projectInfoGetLocal = _svnController.GetLocalInfo(buildFinishedInfo); SendSlackMail(buildFinishedInfo, mailPath, xmlPath); } } } } }); buildTask.Start(); Task nextBuild = buildTask.ContinueWith((t => { XmlNodeList xmlNodeLost = _configController.FindConfigInfo("/config/preferences/UpdateInterval", "../../../common/res/CIConfig.xml"); int updateInterval = int.Parse(xmlNodeLost[0].InnerText); Thread.Sleep(updateInterval * 60 * 1000); _timer.Start(); //遍历编译完成,重新启动计时器 })); } }