/// <summary>
        /// 收到post信息,首先对分支进行切换,然后git pull拉取本分支的最新代码,最后再进行项目的编译工作
        /// </summary>
        /// <param name="projectInfo">项目信息</param>
        /// <param name="pushBranch">操作的分支</param>
        /// <param name="CIConfigPath">项目config路径</param>
        /// <returns></returns>
        public ProjectInfo buildProject(ProjectInfo projectInfo,string pushBranch,string CIConfigPath)
        {
            //进行分支切换操作
            bool switchBranch = _gitController.git_checkout("git checkout " + pushBranch, projectInfo.WorkDirectory);
            //若是分支切换成功,进行项目编译
            if (switchBranch)
            {

                //获取gitlab信息
                GitInfo gitlabInfo = _configController.GitInfoQuery("config/GitLabInfo", CIConfigPath);

                Boolean gitPullResult = _gitController.Libgit2_GitPull(projectInfo.WorkDirectory, gitlabInfo.Username, gitlabInfo.Password, gitlabInfo.Emailaddress);
                if (gitPullResult)
                {
                    string buildResult; //存储编译是否成功
                    string error; //存储编译的日志文件
                    string log; //存储编译的所有信息
                    string time;
                    ConfigInfo configInfo = _configController.ConfigQuery("config/preferences",
             CIConfigPath);
                    projectInfo.BuildTime = DateTime.Now.ToString();
                    projectInfo.StartTime = DateTime.Now.ToString();
                    if (projectInfo.Nameproperty == "LuckyCI") { projectInfo.WorkDirectory += "\\Project"; }
                    log = _projectController.Build(projectInfo.BuildCommand, projectInfo.WorkDirectory,
               out buildResult, out error, out time);
                    projectInfo.Duration = time;
                    projectInfo.EndTime = DateTime.Now.ToString();
                    projectInfo.Log = (configInfo.StandarOutput == "true")
                        ? ("\n" + log + "\n" + error)
                        : ("\n" + error);
                    projectInfo.Result = buildResult;
                }
            }
            return projectInfo;
        }
        /// <summary>
        /// 调用git pull操作,相等于svn更新操作
        /// </summary>
        /// <param name="projectInfo"></param>
        /// <returns></returns>
        public Boolean GitPullProject(ProjectInfo projectInfo)
        {
            string updateResult = "";
            updateLog = _gitlabController.GitPull(projectInfo.WorkDirectory, out updateResult);

            if (updateLog == "Already up-to-date.")
            {
                return true;
            }
            else
                return false;
        }
Exemple #3
0
 /// <summary>
 /// 执行编辑邮件相关信息的操作
 /// </summary>
 /// <param name="projectInfo">传入projectInfo的实例对象</param>
 /// <returns>返回编辑后的MailInfo实例对象</returns>
 public MailInfo EditBody(ProjectInfo projectInfo,string mailPath)
 {
     string path = string.Empty;
     System.IO.StreamReader sr = new System.IO.StreamReader(mailPath);
     string body = string.Empty;
     body = sr.ReadToEnd();
     MailInfo mailInfo = new MailInfo();
     string header = "";
     try
     {
         header = projectInfo.Result == "successful"
             ? Encoding.UTF8.GetString(new byte[] {0xF0, 0x9F, 0x98, 0x83})
             : Encoding.UTF8.GetString(new byte[] {0xF0, 0x9F, 0x91, 0xBF});
         header += projectInfo.Nameproperty + " revision" + projectInfo.Revision + " build " + projectInfo.Result;
         body = body.Replace("$PROJECTNAME$", projectInfo.Nameproperty);
         body = body.Replace("$LOG$", projectInfo.Log);
         body = body.Replace("$VERSION$", projectInfo.Revision);
         body = body.Replace("$AUTHER$", projectInfo.Author);
         body = body.Replace("$DATE$", projectInfo.Changetime);
         body = body.Replace("$RESULT$", "Build " + projectInfo.Result);
         body = body.Replace("$DURATION$", projectInfo.Duration);
         body = projectInfo.Log == ""
             ? body.Replace("$LOGLABEL$", "")
             : body.Replace("$LOGLABEL$", "Build Log");
         mailInfo.Subject = header;
         mailInfo.Body = body;
         mailInfo.Mailto = projectInfo.MailTo;
         mailInfo.Host = projectInfo.MailHost;
         if (projectInfo.UserName.Contains("#author#"))
         {
             mailInfo.Mailfrom = projectInfo.Author.Remove(0, 3) + Regex.Match(projectInfo.UserName, "(?:@)(.+)").Value;
         }
         else
         {
             mailInfo.Mailfrom = projectInfo.UserName.Replace("#","");
             mailInfo.Mailpassword = projectInfo.Password;
         }
         return mailInfo;
     }
     catch (Exception exception)
     {
         return mailInfo;
     }
 }
Exemple #4
0
 /// <summary>
 /// 执行编译项目的操作
 /// </summary>
 /// <param name="projectInfo">当前编译的项目</param>
 /// <returns></returns>
 private ProjectInfo BuildProject(ProjectInfo projectInfo,string xmlPath)
 {
     string buildResult; //存储编译是否成功
     string error;          //存储编译的日志文件
     string log;              //存储编译的所有信息
     string time;
     ConfigInfo configInfo = _configController.ConfigQuery("config/preferences",
         xmlPath);
     projectInfo.BuildTime = DateTime.Now.ToString();
     log = _projectController.Build(projectInfo.Buildcommand, projectInfo.Workdirectory,
         out buildResult, out error,out time);
     //projectInfo.Duration = Regex.Match(log, "(?<=Total time:).*?(?=secs)").Value == ""
     //    ? ""
     //    : (Regex.Match(log, "(?<=Total time:).*?(?=secs)").Value + " secs");
     projectInfo.Duration = time;
     projectInfo.Revision = _latestRevision;
     projectInfo.Log = (configInfo.StandarOutput == "true")
         ? ("\n" + buildResult + "\n" + log + "\n" + error)
         : ("\n" + buildResult + "\n" + projectInfo.Duration + "\n" + error);
     projectInfo.Result = buildResult;
     return projectInfo;
 }
Exemple #5
0
        /// <summary>
        /// 执行编辑邮件相关信息的操作
        /// </summary>
        /// <param name="projectInfo">传入projectInfo的实例对象</param>
        /// <returns>返回编辑后的MailInfo实例对象</returns>
        public MailInfo EditBody(ProjectInfo projectInfo, Dictionary<string, Dictionary<string, string>> allStat, string mailPath)
        {
            string path = string.Empty;
            System.IO.StreamReader sr = new System.IO.StreamReader(mailPath);
            string body = string.Empty;
            body = sr.ReadToEnd();
            MailInfo mailInfo = new MailInfo();
            try
            {
                Dictionary<string, string> selectStat = allStat[projectInfo.Author.Split('\\')[1]];
                int[] allUpdate = new int[allStat.Count];
                int i = 0;
                int selectWeek = 0, selectSuccess = 0, selectFailure = 0;
                foreach (var key in allStat.Keys)
                {
                    allUpdate[i] = Int32.Parse(allStat[key]["Week"]);
                    if (key == projectInfo.Author.Split('\\')[1])
                    {
                        selectWeek = Int32.Parse(allStat[key]["Week"]);
                        selectSuccess = Int32.Parse(allStat[key]["Success"]);
                        selectFailure = Int32.Parse(allStat[key]["Failure"]);
                    }
                    i++;
                }
                //计算个人本周编译次数,成功失败次数,以及其所占有的比率
                double successRate = (double)selectSuccess / selectWeek;
                double failureRate = (double)selectFailure / selectWeek;

                Array.Sort(allUpdate);
                Array.Reverse(allUpdate);
                var emoji = projectInfo.Result == "successful"
                    ? Encoding.UTF8.GetString(new byte[] {0xF0, 0x9F, 0x98, 0x83})
                    : Encoding.UTF8.GetString(new byte[] {0xF0, 0x9F, 0x91, 0xBF});
                var header = emoji + projectInfo.Nameproperty + " revision" + projectInfo.Revision + " build " +
                             projectInfo.Result + ". This week " + projectInfo.Author.Split('\\')[1] + " build " +
                             selectWeek.ToString() + " times, " +selectSuccess.ToString()+" passed, "+selectFailure.ToString()+" failed.";

                body = body.Replace("$PROJECTNAME$", projectInfo.Nameproperty);
                body = body.Replace("$LOG$", projectInfo.Log);
                body = body.Replace("$VERSION$", projectInfo.Revision);
                body = body.Replace("$AUTHOR$", projectInfo.Author);
                body = body.Replace("$DATE$", projectInfo.Changetime);
                body = body.Replace("$RESULT$", "build " + projectInfo.Result);
                body = body.Replace("$DURATION$", projectInfo.Duration);
                body = body.Replace("$SERVER_VERSION$", "Send by LuckyCI v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                body = projectInfo.Log == "\n"
                    ? body.Replace("$LOGLABEL$", "")
                    : body.Replace("$LOGLABEL$", "Build Log");
                mailInfo.Subject = header;
                mailInfo.Body = body;
                mailInfo.Mailto = projectInfo.MailTo;
                mailInfo.Host = projectInfo.MailHost;
                if (projectInfo.UserName.Contains("#author#"))
                {
                    mailInfo.Mailfrom = projectInfo.Author.Remove(0, 3) + Regex.Match(projectInfo.UserName, "(?:@)(.+)").Value;
                }
                else
                {
                    mailInfo.Mailfrom = projectInfo.UserName.Replace("#","");
                    mailInfo.Mailpassword = projectInfo.Password;
                }
                return mailInfo;
            }
            catch (Exception ex)
            {
                return mailInfo;
            }
        }
Exemple #6
0
 /// <summary>
 /// 手动编译
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnBuild_Click(object sender, RoutedEventArgs e)
 {
     ProjectController projectController = new ProjectController();
     if (respoPath.Text == "" || projectName.Text == "" || Workspace.Text == "" ||
         Host.Text == "" || Mailto.Text == "" || Buildcomand.Text == "")
     {
         MessageBox.Show("请先填写完整的信息!");
     }
     else
     {
         ProjectInfo projectInfo = new ProjectInfo();
         projectInfo.WorkDirectory = Workspace.Text;
         projectInfo.RepositoryPath = respoPath.Text;
         projectInfo.MailTo = Mailto.Text;
         projectInfo.BuildCommand = Buildcomand.Text;
         string buildResult = "";
         string time = "";
         Task buildTask = new Task(() =>
         {
             projectInfo.BuildTime = DateTime.Now.ToString();
             log = projectController.Build(projectInfo.BuildCommand, projectInfo.WorkDirectory, out buildResult,
                 out err,out time);
             Dictionary<string, string> setValue = new Dictionary<string, string>();
             setValue.Add("Name", _svnController.GetLocalInfo(projectInfo).Author.Split('\\')[1]);
             if (buildResult == "successful")
             {
                 _projectController.CommitStat("success", setValue, "config/Member", "../../../common/res/InfoStatics.xml");
             }
             else if (buildResult == "failed")
             {
                 _projectController.CommitStat("failure", setValue, "config/Member", "../../../common/res/InfoStatics.xml");
             }
             Dispatcher.BeginInvoke(new Action(() =>
             {
                 duration = time;
                 logs.Text = "编译信息" + log + "\n" + this.logs.Text + "\n";
                 lastRe.Text = buildResult;
                 //检验是否存储信息(最近一次编译信息,以及后台存储信息)
                 Dictionary<string, string> lastProject = new Dictionary<string, string>();
                 //修改存储最近完成项目信息的xml文件
                 lastProject.Add("projectName", projectName.Text);
                 lastProject.Add("buildTime", projectInfo.BuildTime);
                 lastProject.Add("duration", projectInfo.Duration);
                 lastProject.Add("result", buildResult);
                 projectController.ModifyProject(lastProject, null,
                     "../../../common/res/LastestInfo.xml", "lastest");
             }));
         });
         buildTask.Start();
     }
 }
        /// <summary>
        /// 保存编译信息到mongodb数据库中
        /// </summary>
        /// <param name="projectInfo">项目信息</param>
        /// <returns>成功或者失败</returns>
        public bool saveLogToDataBase(ProjectInfo projectInfo,string dbPath,string logPath)
        {
            MongoFieldNames mongoCILog = new MongoFieldNames();
            WeeklyReportData weeklyReportData = new WeeklyReportData();

            double changeSecs = 0;
            string[] timeSpent = projectInfo.Duration.Split(' ');
            if (timeSpent.Length==4) {
                 changeSecs = double.Parse(timeSpent[0])*60 + double.Parse(timeSpent[2]);
            }
            if (timeSpent.Length==2) {
                 changeSecs = double.Parse(timeSpent[0]);
            }

            try {

                //string connstr = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+dbPath;
                //OleDbConnection tempconn = new OleDbConnection(connstr);
                //tempconn.Open();
                ////存储基本信息到CILog表中
                //string sql = "insert into CILog(ProjectName,CommitVersion,Submitter,CIResult,CITimeSpent,CIStartTime,CIEndTime,CILogTime,Branch)values('" + projectInfo.Nameproperty + "','" + projectInfo.GitVersion + "','" + projectInfo.Author + "'," + (projectInfo.Result=="successful"?"True":"False") + ",'" +changeSecs +"','"+projectInfo.StartTime+"','"+projectInfo.EndTime+"','"+DateTime.Now.ToString() +"','"+projectInfo.Branch+ "')";
                //OleDbCommand comm = new OleDbCommand(sql, tempconn);
                ////存储临时信息到weeklyreport中
                //string spl_weeklyreport= "insert into WeeklyReportData(Submitter,ProjectName,BuildResult)values('" + projectInfo.Author + "','" + projectInfo.Nameproperty + "'," + (projectInfo.Result == "successful" ? "True" : "False") + ")";
                //OleDbCommand comm_weeklyreport = new OleDbCommand(spl_weeklyreport, tempconn);
                //comm.ExecuteNonQuery();
                //comm_weeklyreport.ExecuteNonQuery();
                //tempconn.Close();
                var connectionString = "mongodb://localhost:27017";
                MongoClient client = new MongoClient(connectionString);
                var database = client.GetDatabase("CILog");
                //var collection = database.GetCollection<User>("persion");
                var collection = database.GetCollection<MongoFieldNames>("CILog");
                //对要存到mongo数据库CIlog中的实现定义好的字段进行赋值
                mongoCILog.ProjectName = projectInfo.Nameproperty;
                mongoCILog.CommitVersion = projectInfo.GitVersion;
                mongoCILog.Submitter = projectInfo.Author;
                mongoCILog.CIResult = (projectInfo.Result == "successful" ? "true" : "false");
                mongoCILog.CITimeSpent = changeSecs.ToString();
                mongoCILog.CIStartTime =projectInfo.StartTime.ToString();
                mongoCILog.CIEndTime =projectInfo.EndTime.ToString();
                mongoCILog.CILogTime =DateTime.Now.ToString();
                mongoCILog.Branch =projectInfo.Branch;
                collection.InsertOne(mongoCILog);
                //存储临时信息到weeklyreport中
                var collectionWeekly = database.GetCollection<WeeklyReportData>("WeeklyReportData");
                //对要存到mongo数据库weeklyReport中的实现定义好的字段进行赋值
                weeklyReportData.Submitter = projectInfo.Author;
                weeklyReportData.ProjectName = projectInfo.Nameproperty;
                weeklyReportData.BuildResult = (projectInfo.Result == "successful" ? "true" : "false");
                collectionWeekly.InsertOne(weeklyReportData);

                FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs); // 创建写入流
                string outputLog = "projectName:" + projectInfo.Nameproperty + ",CommitVersion:" + projectInfo.GitVersion + ",Submitter:" + projectInfo.Author + ",CIResult:" + projectInfo.Result + ",CITimeSpent:" + projectInfo.Duration + ",CILogTime:" + DateTime.Now.ToString() + "Log:" + projectInfo.Log+"\n";
                sw.WriteLine(outputLog); // 写入Hello World
                sw.Close(); //关闭文件

                return true;
            } catch (Exception ex)
            { return false; }
        }
 /// <summary>
 /// 执行更新的操作
 /// </summary>
 /// <param name="projectInfo">所要更新的项目的相关信息</param>
 /// <param name="startValue">当前运行项目保存的信息</param>
 /// <returns>是否要更新</returns>
 private Boolean UpdateProject(ProjectInfo projectInfo)
 {
     string updateResult = ""; //执行更新操作的结果
     updateLog = _svnController.Update(projectInfo.WorkDirectory, out updateResult, "../../../common/res/CIConfig.xml");
     //判断版本号
     _latestRevision = Regex.Match(updateLog, @"revision\s[0-9]+").Value.Replace("revision", "");
     updateLog = updateLog.Replace("<br/>", "\n");
     string[] updateLogSplit = updateLog.Split('\n');
     List<ProjectInfo> infos = new List<ProjectInfo>();
     infos = _projectController.ReadLog("/config/Projects",
         "../../../common/res/BuildResultLogs.xml");
     foreach (var info in infos)
     {
         if (info.Nameproperty.Equals(projectInfo.Nameproperty))
         {
             if (info.Revision.Equals(_latestRevision)||updateLogSplit.Length<=3)
             {
                 return true;
             }
             break;
         }
     }
     return false;
 }
 /// <summary>
 /// 存储编译的信息
 /// </summary>
 /// <param name="projectInfo">当前编译的项目</param>
 private void SaveInfo(ProjectInfo projectInfo)
 {
     Dictionary<string, string> lastProject = new Dictionary<string, string>();
     Dictionary<string, string> property = new Dictionary<string, string>();
     property.Add("Name", projectInfo.Nameproperty);
     //累加Log,存储在新的Log节点并执行添加属性的操作
     _projectController.SaveLog(projectInfo, property,
         "../../../common/res/BuildResultLogs.xml", "Projects");
     //修改存储最近完成项目信息的xml文件
     lastProject.Add("projectName", projectInfo.Nameproperty);
     lastProject.Add("buildTime", projectInfo.BuildTime);
     lastProject.Add("duration", projectInfo.Duration);
     lastProject.Add("result", projectInfo.Result);
     _projectController.ModifyProject(lastProject,null,
         "../../../common/res/LastestInfo.xml","lastest");
 }
Exemple #10
0
        /// <summary>
        /// 获取logs的信息
        /// </summary>
        /// <param name="nodePath">获取节点的路径</param>
        /// <param name="xmlBuildPath">读取的xml文件的路径</param>
        /// <returns></returns>
        public List<ProjectInfo> ReadLog(string nodePath,string xmlBuildPath)
        {
            List<ProjectInfo> logs = new List<ProjectInfo>();
            XmlNodeList nodeList = dao.XmlQuery(nodePath,xmlBuildPath);
            foreach (XmlNode node in nodeList)
            {
                ProjectInfo projectInfo = new ProjectInfo();
                XmlNodeList xmlNodeList = node.SelectNodes("Log");
                int count = xmlNodeList.Count;
                if (count != 0)
                {
                    projectInfo.Log = xmlNodeList[count - 1].InnerText;
                    projectInfo.Nameproperty = node.Attributes["Name"].Value;
                    projectInfo.Revision = xmlNodeList[count - 1].Attributes["Revision"].Value;
                    projectInfo.Result = xmlNodeList[count - 1].Attributes["Result"].Value;
                    logs.Add(projectInfo);
                }
                else
                {
                    projectInfo.Nameproperty = node.Attributes["Name"].Value;
                    logs.Add(projectInfo);
                }

            }
            return logs;
        }
Exemple #11
0
 /// <summary>
 /// 执行获取本地项目svn信息的操作
 /// </summary>
 /// <param name="projectInfo">传入想要获取信息的projectInfo实例对象</param>
 /// <returns>获取完信息的projectInfo的实例对象</returns>
 public ProjectInfo GetLocalInfo(ProjectInfo projectInfo)
 {
     using (SvnClient svnClient = new SvnClient())
     {
         try
         {
             SvnInfoEventArgs clientInfo;
             SvnPathTarget local = new SvnPathTarget(projectInfo.Workdirectory);
             svnClient.GetInfo(local, out clientInfo);
             //string revision =
             //    Regex.Match(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision),
             //        @"\d+").Value;
             string author = clientInfo.LastChangeAuthor;
             string changeTime = clientInfo.LastChangeTime.ToLocalTime().ToString();
             projectInfo.Author = author;
             //projectInfo.Revision = revision;
             //projectInfo.Changetime = changeTime;
             return projectInfo;
         }
         catch (Exception exception)
         {
             return projectInfo;
         }
     }
 }
Exemple #12
0
        //成功失败次数直接封装
        /// <summary>
        /// 最新编辑邮件模板
        /// </summary>
        /// <param name="projectInfo"></param>
        /// <param name="statisticsTimes"></param>
        /// <param name="mailPath"></param>
        /// <param name="shortName"></param>
        /// <returns></returns>
        public MailInfo NewEditBody(ProjectInfo projectInfo,string[] statisticsTimes, string mailPath, string shortName)
        {
            string path = string.Empty;
            System.IO.StreamReader sr = new System.IO.StreamReader(mailPath);
            string body = string.Empty;
            body = sr.ReadToEnd();
            MailInfo mailInfo = new MailInfo();
            try
            {

                //计算个人本周编译次数,成功失败次数,以及其所占有的比率
                double successRate = double.Parse(statisticsTimes[2]) / double.Parse(statisticsTimes[1]);
                double failureRate = double.Parse(statisticsTimes[3]) / double.Parse(statisticsTimes[1]);

                var emoji = projectInfo.Result == "successful"
                    ? Encoding.UTF8.GetString(new byte[] { 0xF0, 0x9F, 0x98, 0x83 })
                    : Encoding.UTF8.GetString(new byte[] { 0xF0, 0x9F, 0x91, 0xBF });
                var header = emoji + projectInfo.Nameproperty + " reversion " + ((projectInfo.ProjectType == "git") ? (projectInfo.GitVersion.Substring(0, 8)) : projectInfo.GitVersion) + " build " +
                             projectInfo.Result + ". This week " + projectInfo.Author + " build " +
                             statisticsTimes[1] + " times, " + statisticsTimes[2] + " passed, " + statisticsTimes[3] + " failed.";

                body = body.Replace("$PROJECTNAME$", projectInfo.Nameproperty);
                body = body.Replace("$LOG$", projectInfo.Log);
                body = body.Replace("$VERSION$", projectInfo.Revision);
                body = body.Replace("$AUTHOR$", projectInfo.Author);
                body = body.Replace("$DATE$", projectInfo.Changetime);
                body = body.Replace("$RESULT$", "build " + projectInfo.Result);
                body = body.Replace("$DURATION$", projectInfo.Duration);
                body = body.Replace("$SERVER_VERSION$", "Send by LuckyCI v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                body = projectInfo.Log == "\n"
                    ? body.Replace("$LOGLABEL$", "")
                    : body.Replace("$LOGLABEL$", "Build Log");
                mailInfo.Subject = header;
                mailInfo.Body = body;
                mailInfo.Mailto = projectInfo.MailTo;
                mailInfo.Host = projectInfo.MailHost;
                if (projectInfo.UserName.Contains("#author#"))
                {
                    mailInfo.Mailfrom = (shortName != "") ? (shortName + Regex.Match(projectInfo.UserName, "(?:@)(.+)").Value) : (projectInfo.Author + Regex.Match(projectInfo.UserName, "(?:@)(.+)").Value);
                }
                else
                {
                    mailInfo.Mailfrom = projectInfo.UserName.Replace("#", "");
                    mailInfo.Mailpassword = projectInfo.Password;
                }
                return mailInfo;
            }
            catch (Exception ex)
            {
                return mailInfo;
            }
        }
Exemple #13
0
 /// <summary>
 /// 执行更新的操作
 /// </summary>
 /// <param name="projectInfo">所要更新的项目的相关信息</param>
 /// <param name="startValue">当前运行项目保存的信息</param>
 /// <returns>是否要更新</returns>
 private Boolean UpdateProject(ProjectInfo projectInfo,string xmlPath,string buildXmlPath)
 {
     string updateLog = "";     //执行更新操作获取的日志信息
     string updateResult = ""; //执行更新操作的结果
     updateLog = _svnController.Update(projectInfo.Workdirectory, out updateResult,xmlPath);
     //判断版本号
     _latestRevision = Regex.Match(updateLog, @"revision\s[0-9]+").Value.Replace("revision", "");
     List<ProjectInfo> infos = new List<ProjectInfo>();
     infos = _projectController.ReadLog("/config/Projects",
         buildXmlPath);
     string[] updateLogSplit = updateLog.Split('\n');
     foreach (var info in infos)
     {
         if (info.Nameproperty.Equals(projectInfo.Nameproperty))
         {
             if (info.Revision.Equals(_latestRevision)||updateLogSplit.Length<=3)
             {
                 return true;
             }
             break;
         }
     }
     return false;
 }
Exemple #14
0
 /// <summary>
 /// 执行发送邮件的操作
 /// </summary>
 /// <param name="projectInfo">projectInfoGetLocal的信息</param>
 /// <param name="ifSlack">是否向slack发信息</param>
 /// <param name="ifMail">是否发送邮件</param>
 private void SendSlackMail(ProjectInfo projectInfo, string ifSlack, string ifMail,string mailPath)
 {
     if (projectInfo.IfMail == "true")
     {
         MailInfo mailInfo = _mailController.EditBody(projectInfo,
             mailPath);
         _mailController.SendMail(mailInfo);
     }
     try
     {
         if (ifSlack == "true")
         {
             WebClient webClient = new WebClient();
             string slackBody = projectInfo.SlackContent;
             slackBody = slackBody.Replace("projectName", projectInfo.Nameproperty);
             slackBody = slackBody.Replace("versionNum", projectInfo.Revision);
             string[] contentItem = slackBody.Split('#');
             string slackEmoji = projectInfo.Result == "successful"
                 ? contentItem[1].Split(':')[0]
                 : contentItem[1].Split(':')[1];
             contentItem[contentItem.Length - 2] = projectInfo.Result == "successful"
                 ? contentItem[contentItem.Length - 2].Split(':')[0]
                 : contentItem[contentItem.Length - 2].Split(':')[1];
             slackBody = "";
             for (int i = 2; i < contentItem.Length - 1; i++)
             {
                 slackBody += contentItem[i];
             }
             string userName = projectInfo.SlackUser == "#author#" ? projectInfo.Author.Remove(0, 3)
             : projectInfo.SlackUser;
             //将传输信息写入json
             var payLoad = new
             {
                 channel = projectInfo.SlackChannel,
                 text = ":" + slackEmoji + ":" + slackBody,
                 username = userName
             };
             string json = JsonConvert.SerializeObject(payLoad);
             string slackResult = webClient.UploadString(projectInfo.SlackUrl, json);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
 /// <summary>
 /// 编译完成之后,对本次项目信息进行存储
 /// </summary>
 /// <param name="projectInfo">项目信息</param>
 /// <param name="dbPath">数据库路径</param>
 /// <param name="logPath">日志路径</param>
 /// <returns></returns>
 public bool SaveInfoToDataBase(ProjectInfo projectInfo, string dbPath, string logPath)
 {
     return _projectController.saveLogToDataBase(projectInfo, dbPath, logPath);
 }
 /// <summary>
 /// 构造函数,在线程启动之前,进行赋值
 /// </summary>
 /// <param name="projectInfo">项目信息</param>
 /// <param name="ifSlack">是否发送slack</param>
 /// <param name="ifMail">是否发送邮件</param>
 public SendMailSlack(ProjectInfo projectInfo, string mailPath, string CIConfigParh, string mdbPath, ConfigInfo configInfo,string mailWeekReportPath)
 {
     if (configInfo != null) { this.configInfo = configInfo; }
     if (CIConfigParh != null)
     {
         _slackPeople = _configController.AcquireSlackPeople("/config/SlackPeople/People", CIConfigParh);
         _mailPeople = _configController.AcquireSlackPeople("/config/MailPeople/People", CIConfigParh);
     }
     this.projectInfo = projectInfo;
     this.mailPath = mailPath;
     this.mdbPath = mdbPath;
     this.mailWeekReportPath = mailWeekReportPath;
 }
Exemple #17
0
 /// <summary>
 ///  执行删除选中的工程节点
 /// </summary>
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     ProjectController projectController = new ProjectController();
     var xmlConfigPath = new[] { "../../../common/res/CIConfig.xml", "../../../common/res/BuildResultLogs.xml" };
     var result = projectController.DeleteProject("/config/Projects", projectName.Text, xmlConfigPath);
     MessageBox.Show("Delete " + result);
     if (result == "successful")
     {
         index = new int();
         modifyProject = null;
         respoPath.Text = "";
         projectName.Text = "";
         Workspace.Text = "";
         Mailto.Text = "";
         Buildcomand.Text = "";
         CheckMail.IsChecked = false;
         CheckSlack.IsChecked = false;
         Host.Text = "";
         Username.Text = "";
         Password.Text = "";
         SlackUrl.Text = "";
         SlackChannel.Text = "";
         buildRe.Text = "";
     }
 }
Exemple #18
0
        /// <summary>
        /// 执行获取所有符合要求的项目信息列表
        /// </summary>
        /// <param name="dataPath">查询的节点路径</param>
        /// <param name="b">true:项目信息;false:最近一次编译信息</param>
        /// <returns>返回查寻完毕的信息列表</returns>
        public List<ProjectInfo> ProjectQuery(string dataPath,bool b,string xmlPath)
        {
            List<ProjectInfo> projectInfos = new List<ProjectInfo>();
            XmlDao xmlDao = new XmlDao();
            if (b)
            {
                try
                {

                    XmlNodeList xmlNodeList = xmlDao.XmlQuery(dataPath,xmlPath);
                    foreach (XmlNode xmlNode in xmlNodeList)
                    {
                        ProjectInfo projectInfo = new ProjectInfo();
                        projectInfo.Statusproperty = xmlNode.Attributes["Status"].Value;
                        projectInfo.Nameproperty = xmlNode.Attributes["Name"].Value;
                        projectInfo.Buildcommand = xmlNode.SelectSingleNode("BuildCommand").InnerText;
                        projectInfo.Repositorypath = xmlNode.SelectSingleNode("RepositoryPath").InnerText;
                        projectInfo.Workdirectory = xmlNode.SelectSingleNode("WorkingDirectory").InnerText;
                        projectInfo.MailTo = xmlNode.SelectSingleNode("MailTo").InnerText;
                        projectInfo.IfMail = xmlNode.SelectSingleNode("IfMail").InnerText;
                        projectInfo.IfSlack = xmlNode.SelectSingleNode("IfSlack").InnerText;
                        projectInfo.SlackUrl = xmlNode.SelectSingleNode("SlackUrl").InnerText;
                        projectInfo.MailHost = xmlNode.SelectSingleNode("MailHost").InnerText;
                        projectInfo.UserName = xmlNode.SelectSingleNode("UserName").InnerText;
                        projectInfo.Password = xmlNode.SelectSingleNode("Password").InnerText;
                        projectInfo.SlackChannel = xmlNode.SelectSingleNode("SlackChannel").InnerText;
                        projectInfo.SlackUser = xmlNode.SelectSingleNode("SlackUser").InnerText;
                        projectInfo.SlackContent = xmlNode.SelectSingleNode("SlackContent").InnerText;
                        projectInfos.Add(projectInfo);
                    }
                    return projectInfos;
                }
                catch (Exception)
                {
                    return projectInfos;
                }
            }
            else
            {
                ProjectInfo projectInfo = new ProjectInfo();
                XmlNodeList xmlNodeList = xmlDao.XmlQuery(dataPath, xmlPath);
                projectInfo.Nameproperty = xmlNodeList[0].SelectSingleNode("projectName").InnerText;
                projectInfo.BuildTime = xmlNodeList[0].SelectSingleNode("buildTime").InnerText;
                projectInfo.Duration = xmlNodeList[0].SelectSingleNode("duration").InnerText;
                projectInfo.Result = xmlNodeList[0].SelectSingleNode("result").InnerText;
                projectInfo.Index = xmlNodeList[0].SelectSingleNode("index").InnerText;
                projectInfos.Add(projectInfo);
                return projectInfos;
            }
        }
Exemple #19
0
 /// <summary>
 /// 点击事件进行发送邮件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSendMail_Click(object sender, RoutedEventArgs e)
 {
     if (Username.Text == "#author#@domain.com")
     {
         MessageBox.Show("请修改默认发件人");
     }
     else
     {
         ConfigInfo configInfo = _configController.ConfigQuery("config/preferences", "../../../common/res/CIConfig.xml");
         _projectInfo.WorkDirectory = Workspace.Text;
         _projectInfo = _svnController.GetLocalInfo(_projectInfo);
         _projectInfo.Nameproperty = projectName.Text;
         _projectInfo.Log = (configInfo.StandarOutput == "true") ? ((log + err).Replace("\n", "<br/>")) : (err.Replace("\n", "<br/>"));
         _projectInfo.Result = lastRe.Text;
         _projectInfo.Duration = duration;
         _projectInfo.Revision = revision;
         _projectInfo.MailTo = Mailto.Text;
         _projectInfo.MailHost = Host.Text;
         _projectInfo.UserName = Username.Text;
         _projectInfo.Password = Password.Text;
         MailController mailController = new MailController();
         Dictionary<string, Dictionary<string, string>> allStatics =
             _projectController.GetStatData("config/Member", "../../../common/res/InfoStatics.xml");
         MailInfo mailInfo = mailController.EditBody(_projectInfo, allStatics, "../../../common/SendMail.html",null);
         sendRe.Text = mailController.SendMail(mailInfo);
     }
 }
Exemple #20
0
 /// <summary>
 /// 存储Log(按版本号增加Log节点
 /// </summary>
 /// <param name="value">需要修改的子节点的键值对</param>
 /// <param name="property">需要筛选的属性值的键值对</param>
 /// <param name="xmlPath">xml文件的路径</param>
 /// <param name="nodePath">节点的路径</param>
 /// <returns></returns>
 public string SaveLog(ProjectInfo projectInfo, Dictionary<string, string> property, string xmlPath,
     string nodePath)
 {
     XmlDao xmlDao = new XmlDao();
     var logInfo = new Dictionary<string,string>();
     var logProperty = new Dictionary<string,string>();
     logInfo.Add("Log",projectInfo.Log);
     logProperty.Add("Revision",projectInfo.Revision);
     logProperty.Add("Result",projectInfo.Result);
     logProperty.Add("Time",DateTime.Now.ToString());
     string result = "";
     XElement xElement = xmlDao.SelectOneXElement(property, xmlPath, nodePath);
     xmlDao.AddXNode(logInfo, xElement, xmlPath);
     xElement = xmlDao.SelectOneXElement(property, xmlPath, nodePath);
     result = xmlDao.XNodeAttributes(logProperty, xElement.Elements("Log").Last(), xmlPath);
     return result;
 }
Exemple #21
0
 /// <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");
     }
 }
Exemple #22
0
 /// <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();
 }
Exemple #23
0
        /// <summary>
        /// 初始化事件,获取当前的uri路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InitPage(object sender, RoutedEventArgs e)
        {
            try
            {
                quesMark.ToolTip = "1.##之间的内容若包含:则:左边为成功的显示右边为失败" +
                                   "\n2.smile&smiling_imp为emoji对照英文可按需修改" +
                                   "\n3.可按需添加语句";
                ProjectController projectController = new ProjectController();
                List<ProjectInfo> list = projectController.ProjectQuery("/config/lastest", false, "../../../common/res/LastestInfo.xml");
                lastRe.Text = list[0].Result;
                index = int.Parse(list[0].Index);
                if (index != -1)
                {
                    List<ProjectInfo> projectInfos = projectController.ProjectQuery("/config/Projects", true,
                "../../../common/res/CIConfig.xml");
                    modifyProject = projectInfos[index];
                    if (modifyProject != null)
                    {
                        respoPath.Text = modifyProject.RepositoryPath;
                        projectName.Text = modifyProject.Nameproperty;
                        Workspace.Text = modifyProject.WorkDirectory;
                        Mailto.Text = modifyProject.MailTo;
                        Buildcomand.Text = modifyProject.BuildCommand;
                        CheckMail.IsChecked = Convert.ToBoolean(modifyProject.IfMail);
                        CheckSlack.IsChecked = Convert.ToBoolean(modifyProject.IfSlack);
                        Host.Text = modifyProject.MailHost;
                        Username.Text = modifyProject.UserName;
                        Password.Text = modifyProject.Password;
                        SlackUrl.Text = modifyProject.SlackUrl;
                        SlackChannel.Text = modifyProject.SlackChannel;
                        buildRe.Text = modifyProject.Result;
                        if (modifyProject.ProjectType=="git") { Git.IsChecked = true; }
                        if (modifyProject.ProjectType=="svn") { Svn.IsChecked = true; }
                    }
                    Dictionary<string, string> initIndex = new Dictionary<string, string>();
                    initIndex.Add("index", "-1");
                    projectController.ModifyProject(initIndex, null, "../../../common/res/LastestInfo.xml", "lastest");
                }

            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemple #24
0
 /// <summary>
 /// 构造函数,在线程启动之前,进行赋值
 /// </summary>
 /// <param name="projectInfo">项目信息</param>
 /// <param name="ifSlack">是否发送slack</param>
 /// <param name="ifMail">是否发送邮件</param>
 public SendMailSlack(ProjectInfo projectInfo, string mailPath, string updateLog, string xmlParh)
 {
     if (xmlParh != null)
     {
         _slackPeople = _configController.AcquireSlackPeople("/config/SlackPeople/People", xmlParh);
     }
     allStatics = _projectController.GetStatData("config/Member", "../../../common/res/InfoStatics.xml");
     allProjectStatics = _projectController.GetProjectData("config/Projects", "../../../common/res/InfoStatics.xml");
     weekTotalData = _projectController.GetTotal("config/WeekTotal", "../../../common/res/InfoStatics.xml");
     this.projectInfo = projectInfo;
     this.mailPath = mailPath;
     this.updateNewLog = updateLog;
 }
        /// <summary>
        /// 执行获取所有符合要求的项目信息列表
        /// </summary>
        /// <param name="dataPath">查询的节点路径</param>
        /// <param name="b">true:项目信息;false:最近一次编译信息</param>
        /// <returns>返回查寻完毕的信息列表</returns>
        public List<ProjectInfo> ProjectQuery(string dataPath,bool b,string xmlPath)
        {
            List<ProjectInfo> projectInfos = new List<ProjectInfo>();
            //检测infostatics中有没有包括提交的项目,分别赋值
            if (xmlPath.Contains("InfoStatics.xml")) {
                XmlNodeList xmlNodeList = dao.XmlQuery(dataPath, xmlPath);
                if (xmlNodeList.Count!=0) {
                    foreach (XmlNode xmlNode in xmlNodeList) {
                        ProjectInfo projectInfo = new ProjectInfo();
                        projectInfo.Nameproperty = xmlNode.Attributes["Name"].Value;
                        projectInfos.Add(projectInfo);
                    }
                }
                return projectInfos;
            }
            else
            {
                if (b)
                {
                    try
                    {

                        XmlNodeList xmlNodeList = dao.XmlQuery(dataPath, xmlPath);
                        foreach (XmlNode xmlNode in xmlNodeList)
                        {
                            ProjectInfo projectInfo = new ProjectInfo();
                            projectInfo.Statusproperty = xmlNode.Attributes["Status"].Value;
                            projectInfo.Nameproperty = xmlNode.Attributes["Name"].Value;
                            projectInfo.BuildCommand = xmlNode.SelectSingleNode("BuildCommand").InnerText;
                            projectInfo.RepositoryPath = xmlNode.SelectSingleNode("RepositoryPath").InnerText;
                            projectInfo.WorkDirectory = xmlNode.SelectSingleNode("WorkingDirectory").InnerText;
                            projectInfo.MailTo = xmlNode.SelectSingleNode("MailTo").InnerText;
                            projectInfo.IfMail = xmlNode.SelectSingleNode("IfMail").InnerText;
                            projectInfo.IfSlack = xmlNode.SelectSingleNode("IfSlack").InnerText;
                            projectInfo.SlackUrl = xmlNode.SelectSingleNode("SlackUrl").InnerText;
                            projectInfo.MailHost = xmlNode.SelectSingleNode("MailHost").InnerText;
                            projectInfo.UserName = xmlNode.SelectSingleNode("UserName").InnerText;
                            projectInfo.Password = xmlNode.SelectSingleNode("Password").InnerText;
                            projectInfo.SlackChannel = xmlNode.SelectSingleNode("SlackChannel").InnerText;
                            projectInfo.SlackUser = xmlNode.SelectSingleNode("SlackUser").InnerText;
                            projectInfo.SlackContent = xmlNode.SelectSingleNode("SlackContent").InnerText;
                            projectInfo.SelectResult = xmlNode.SelectSingleNode("SlackResult").InnerText;
                            projectInfo.SelectCommit = xmlNode.SelectSingleNode("SlackCommit").InnerText;
                            projectInfo.SelectUpdate = xmlNode.SelectSingleNode("SlackUpdate").InnerText;
                            projectInfo.GitVersion = xmlNode.SelectSingleNode("GitVersion").InnerText;
                            projectInfo.ProjectType = xmlNode.SelectSingleNode("ProjectType").InnerText;
                            projectInfos.Add(projectInfo);
                        }
                        return projectInfos;
                    }
                    catch (Exception)
                    {
                        return projectInfos;
                    }
                }
                else
                {
                    ProjectInfo projectInfo = new ProjectInfo();
                    XmlNodeList xmlNodeList = dao.XmlQuery(dataPath, xmlPath);
                    projectInfo.Nameproperty = xmlNodeList[0].SelectSingleNode("projectName").InnerText;
                    projectInfo.BuildTime = xmlNodeList[0].SelectSingleNode("buildTime").InnerText;
                    projectInfo.Duration = xmlNodeList[0].SelectSingleNode("duration").InnerText;
                    projectInfo.Result = xmlNodeList[0].SelectSingleNode("result").InnerText;
                    projectInfo.Index = xmlNodeList[0].SelectSingleNode("index").InnerText;
                    projectInfos.Add(projectInfo);
                    return projectInfos;
                }
            }
        }