/// <summary> /// 更新文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, RoutedEventArgs e) { SvnInfo svnInfo = new SvnInfo(); svnInfo.Workdirectory = Workspace.Text; ProjectInfo setInfo = new ProjectInfo(); if (respoPath.Text == "" || projectName.Text == "" || Workspace.Text == "" || Mailto.Text == "" || Host.Text == "" || Buildcomand.Text == "") { MessageBox.Show("请先填写完整的信息!"); } else { string updateResult; var updateLog = _svnController.Update(svnInfo.Workdirectory, out updateResult, "../../../common/res/CIConfig.xml"); logs.Text = "更新信息:" + updateLog + "\n" + this.logs.Text + "\n"; revision = Regex.Match(updateLog, @"revision\s[0-9]+").Value.Replace("revision", ""); Dictionary <string, string> setValue = new Dictionary <string, string>(); setInfo.WorkDirectory = svnInfo.Workdirectory; setInfo.RepositoryPath = respoPath.Text; setInfo = _svnController.GetLocalInfo(setInfo); setValue.Add("Name", setInfo.Author.Split('\\')[1]); _projectController.CommitStat("update", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); } }
/// <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(); //遍历编译完成,重新启动计时器 })); } }
private void fun() { string config = System.AppDomain.CurrentDomain.BaseDirectory; int p = config.LastIndexOf("\\"); string parent = config.Substring(0, p - 25); string xmlPath = parent + "\\common\\res\\CIconfig.xml"; string buildXmlPath = parent + "\\common\\res\\BuildResultLogs.xml"; string lastXmlPath = parent + "\\common\\res\\LastestInfo.xml"; infoStatXmlPath = parent + "\\common\\res\\InfoStatics.xml"; string mailPath = parent + "\\common\\SendMail.html"; string mailWeekReportPath = parent + "\\common\\WeeklyReport.html"; List <ProjectInfo> projectInfos = _projectController.ProjectQuery("/config/Projects", true, xmlPath); List <ProjectInfo> lastResults = _projectController.ReadLog("/config/Projects", buildXmlPath); // Thread.Sleep(40000); foreach (var projectInfo in projectInfos) { if (projectInfo.Statusproperty == "true") { //保存修改前的版本以便回滚 ProjectInfo lastestInfo = _projectController.ProjectQuery("config/lastest", false, lastXmlPath).First(); //将当前运行项目及运行状态存储 Dictionary <string, string> startValue = new Dictionary <string, string>(); startValue.Add("projectName", projectInfo.Nameproperty); startValue.Add("result", "running"); _projectController.ModifyProject(startValue, null, lastXmlPath, "lastest"); //更新项目,若版本号未变则无需编译否则编译 Boolean updateResult = UpdateProject(projectInfo, xmlPath, buildXmlPath); //如果无需编译,则结果会滚到改变前的版本 //测试语句 //if(false) if (updateResult) { Dictionary <string, string> revertLastInfo = new Dictionary <string, string>(); revertLastInfo.Add("projectName", lastestInfo.Nameproperty); revertLastInfo.Add("result", lastestInfo.Result); _projectController.ModifyProject(revertLastInfo, null, lastXmlPath, "lastest"); } 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", infoStatXmlPath); //检查infoStatics文件夹中有没有提交的项目,若是有则进行相对应的节点数值加1处理,若是没有,则进行创建,并进行初始化 List <ProjectInfo> checkProjectInfos = _projectController.ProjectQuery("/config/Projects", true, infoStatXmlPath); //进行创建 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, infoStatXmlPath); } //进行加1处理 else { Dictionary <string, string> projectName = new Dictionary <string, string>(); projectName.Add("Name", projectInfo.Nameproperty); _projectController.CommitStat("projectsCommit", projectName, "config/Projects", infoStatXmlPath); } //将更新记录记入统计 //Dictionary<string, string> setUpdateValue = new Dictionary<string, string>(); //setUpdateValue.Add("Name", projectInfoGetLocal.Author.Split('\\')[1]); //_projectController.CommitStat("update", setUpdateValue, "config/Member", infoStatXmlPath); SendMailSlack sendMailSlack = new SendMailSlack(projectInfoGetLocal, null, updateLog, xmlPath, infoStatXmlPath); Thread sendLogMessage = new Thread(sendMailSlack.SendLogMessage); sendLogMessage.Start(); //编译项目 ProjectInfo buildFinishedInfo = BuildProject(projectInfoGetLocal, xmlPath); //存储编译信息 SaveInfo(buildFinishedInfo, buildXmlPath, lastXmlPath); if (buildFinishedInfo.Result == "successful") { _projectController.CommitStat("success", setValue, "config/Member", infoStatXmlPath); Dictionary <string, string> projectName = new Dictionary <string, string>(); projectName.Add("Name", projectInfo.Nameproperty); _projectController.CommitStat("projectSuccess", projectName, "config/Projects", infoStatXmlPath); } else if (buildFinishedInfo.Result == "failed") { _projectController.CommitStat("failure", setValue, "config/Member", infoStatXmlPath); Dictionary <string, string> projectName = new Dictionary <string, string>(); projectName.Add("Name", projectInfo.Nameproperty); _projectController.CommitStat("projectFailed", projectName, "config/Projects", infoStatXmlPath); } //先从本地svn完善项目信息后自动发送邮件 // ProjectInfo projectInfoGetLocal = _svnController.GetLocalInfo(buildFinishedInfo); SendSlackMail(buildFinishedInfo, mailPath, xmlPath); } } } XmlNodeList xmlNodeLost = _configController.FindConfigInfo("/config/preferences/UpdateInterval", xmlPath); int updateInterval = int.Parse(xmlNodeLost[0].InnerText); Thread.Sleep(updateInterval * 60000); Thread t = new Thread(fun); t.Start(); }