示例#1
0
 /// <summary>
 /// 执行恢复默认配置的操作
 /// </summary>
 /// <returns>返回configInfo的实例对象</returns>
 public ConfigInfo RestoreDefault()
 {
     ConfigInfo configInfo = new ConfigInfo();
     configInfo.Updateinterval = "30";
     configInfo.Svnpath = "C:\\Program Files\\TortoiseSVN\\bin\\svn.exe";
     configInfo.StandarOutput = "true";
     configInfo.ServiceSwitch = "window";
     return configInfo;
 }
示例#2
0
 /// <summary>
 /// 执行保存已修改数据的方法
 /// </summary>
 private void btnApply_Click(object sender, RoutedEventArgs e)
 {
     ConfigController configController = new ConfigController();
     ConfigInfo configInfo = new ConfigInfo();
     configInfo.StandarOutput = standaroutput.IsChecked == true ? "true" : "false";
     configInfo.Svnpath = Svnpath.Text;
     configInfo.Updateinterval = Updateinterval.Text;
     configInfo.ServiceSwitch = (windowprocess.IsChecked == true) ? "window" : "service";
     var result = configController.SaveConfig(configInfo, "../../../common/res/CIConfig.xml");
     MessageBox.Show(result);
 }
示例#3
0
 /// <summary>
 /// 查询配置信息
 /// </summary>
 /// <param name="dataPath">节点路径</param>
 /// <param name="xmlConfigPath">查询的xml文件路径</param>
 /// <returns></returns>
 public ConfigInfo ConfigQuery(string dataPath,string xmlConfigPath)
 {
     ConfigInfo configInfo = new ConfigInfo();
     XmlDao xmlDao = new XmlDao();
     try
     {
         XmlNodeList xmlNodeList = xmlDao.XmlQuery(dataPath, xmlConfigPath);
         configInfo.Svnpath = xmlNodeList[0].SelectSingleNode("SvnPath").InnerText;
         configInfo.Updateinterval = xmlNodeList[0].SelectSingleNode("UpdateInterval").InnerText;
         configInfo.StandarOutput = xmlNodeList[0].SelectSingleNode("StandarOutput").InnerText;
         configInfo.ServiceSwitch = xmlNodeList[0].SelectSingleNode("ServiceSwitch").InnerText;
         return configInfo;
     }
     catch (Exception)
     {
         return configInfo;
     }
 }
示例#4
0
 /// <summary>
 /// 执行保存已经修改的ConfigInfo
 /// </summary>
 /// <param name="configInfo">传入configInfo实例对象</param>
 /// <param name="xmlConfigPath">修改的xml文件</param>
 /// <returns></returns>
 public string SaveConfig(ConfigInfo configInfo,string xmlConfigPath)
 {
     string modifyPath = "preferences";
     string result = "";
     var value = new Dictionary<string, string>();
     value.Add("SvnPath",configInfo.Svnpath);
     value.Add("UpdateInterval",configInfo.Updateinterval);
     value.Add("StandarOutput",configInfo.StandarOutput);
     value.Add("ServiceSwitch", configInfo.ServiceSwitch);
     try
     {
         XmlDao xmlDao = new XmlDao();
         XElement xElement = xmlDao.SelectOneXElement(null, xmlConfigPath, modifyPath);
         result = xmlDao.ModifyXNode(value, xElement, xmlConfigPath);
         return result;
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
         result = "failed";
         return result;
     }
 }
示例#5
0
 /// <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;
 }
示例#6
0
 /// <summary>
 /// 执行恢复默认配置的操作
 /// </summary>
 /// <returns>返回configInfo的实例对象</returns>
 public ConfigInfo RestoreDefault()
 {
     ConfigInfo configInfo = new ConfigInfo();
     configInfo.Updateinterval = "30";
     configInfo.Svnpath = "C:\\Program Files\\TortoiseSVN\\bin\\svn.exe";
     configInfo.StandarOutput = "true";
     configInfo.ServiceSwitch = "window";
     configInfo.ReportFrom = "*****@*****.**";
     configInfo.Password = "******";
     configInfo.ReportTo = "*****@*****.**";
     configInfo.SmtpServer = "smtp.gmail.com";
     return configInfo;
 }
示例#7
0
        /// <summary>
        /// 从access数据库中取得数据,发送周报告
        /// </summary>
        /// <param name="mdbPath"></param>
        /// <param name="reportMailPath"></param>
        /// <param name="configInfo"></param>
        /// <returns></returns>
        public bool StatisticsFromMdb(string mdbPath,string reportMailPath,ConfigInfo configInfo)
        {
            //需要统计的数据

            //一周提交总次数
            int allTimes=0;
            int allSuccessfulTimes = 0;
            int allFiledTimes = 0;

            //暂存作者
            List<string> memberList = new List<string>();
            List<int> memberSuccessfulTimes = new List<int>();
            List<int> memberFiledTimes = new List<int>();
            //暂存项目名称
            List<string> projectList = new List<string>();
            List<int> projectSuccessfulTimes = new List<int>();
            List<int> projectFiledTimes = new List<int>();
            //获取上周一的日期
            DateTime lastMondayDate = DateTime.Now.AddDays(-7);
            try {
                //连接数据库
                string connstr = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=" + mdbPath;
                OleDbConnection tempconn = new OleDbConnection(connstr);
                tempconn.Open();
                OleDbDataAdapter da = new OleDbDataAdapter(@"select * from CILog", tempconn);
                DataSet ds = new DataSet();
                da.Fill(ds, "CILog");
                //倒着遍历,与上周一时间相对比
                for (int i = ds.Tables["CILog"].Rows.Count - 1; i >= 0; i--) {
                    //总次数统计
                    if (DateTime.Parse(ds.Tables["CILog"].Rows[i]["CILogTime"].ToString()) >= lastMondayDate)
                    {
                        //总次数加一
                        allTimes++;
                        //判断本次书否编译成功
                        if (bool.Parse(ds.Tables["CILog"].Rows[i]["CIResult"].ToString()))
                        {
                            //成功次数加一
                            allSuccessfulTimes++;
                        }
                        //失败次数加一
                        else allFiledTimes++;

                        //作者统计
                        bool memberFlag = false;
                        for (int member = 0; member < memberList.Count; member++)
                        {
                            if (ds.Tables["CILog"].Rows[i]["Submitter"].ToString() == memberList[member]) { memberFlag = true; break; }
                        }
                        if (memberFlag == false) { memberList.Add(ds.Tables["CILog"].Rows[i]["Submitter"].ToString()); }

                        //项目统计
                        bool projectFlag = false;
                        for (int project = 0; project < projectList.Count; project++)
                        {
                            if (ds.Tables["CILog"].Rows[i]["ProjectName"].ToString() == projectList[project]) { projectFlag = true; break; }
                        }
                        if (projectFlag == false) { projectList.Add(ds.Tables["CILog"].Rows[i]["ProjectName"].ToString()); }
                    }
                    else break;

                }

                //第二次遍历,统计每个人提交次数以及编译情况

                for (int j = 0; j < memberList.Count; j++)
                {
                    int tempTrue = 0;
                    int tempFalse = 0;
                    for (int i = ds.Tables["CILog"].Rows.Count - 1; i >= 0; i--)
                    {
                        if (DateTime.Parse(ds.Tables["CILog"].Rows[i]["CILogTime"].ToString()) >= lastMondayDate && ds.Tables["CILog"].Rows[i]["Submitter"].ToString() == memberList[j] &&
                            ds.Tables["CILog"].Rows[i]["CIResult"].ToString() == "True")
                        {
                            tempTrue++;
                        }
                        if (DateTime.Parse(ds.Tables["CILog"].Rows[i]["CILogTime"].ToString()) >= lastMondayDate && ds.Tables["CILog"].Rows[i]["Submitter"].ToString() == memberList[j] &&
                            ds.Tables["CILog"].Rows[i]["CIResult"].ToString() == "False")
                        {
                            tempFalse++;
                        }
                    }
                    memberSuccessfulTimes.Add(tempTrue);
                    memberFiledTimes.Add(tempFalse);
                }

                //第三次遍历,统计每个项目提交次数以及编译情况
                for (int j = 0; j < projectList.Count; j++)
                {
                    int tempTrue = 0;
                    int tempFalse = 0;
                    for (int i = ds.Tables["CILog"].Rows.Count - 1; i >= 0; i--)
                    {
                        if (DateTime.Parse(ds.Tables["CILog"].Rows[i]["CILogTime"].ToString()) >= lastMondayDate && ds.Tables["CILog"].Rows[i]["ProjectName"].ToString() == projectList[j] &&
                            ds.Tables["CILog"].Rows[i]["CIResult"].ToString() == "True")
                        {
                            tempTrue++;
                        }
                        if (DateTime.Parse(ds.Tables["CILog"].Rows[i]["CILogTime"].ToString()) >= lastMondayDate && ds.Tables["CILog"].Rows[i]["ProjectName"].ToString() == projectList[j] &&
                            ds.Tables["CILog"].Rows[i]["CIResult"].ToString() == "False")
                        {
                            tempFalse++;
                        }
                    }
                    projectSuccessfulTimes.Add(tempTrue);
                    projectFiledTimes.Add(tempFalse);
                }
                //排版发送邮件内容
                string totalWeekTimes = "";
                string weekByDeveloper = "";
                string buildByDeveloper = "";
                string weekByProject = "";
                string buildByProject = "";
                System.IO.StreamReader sr = new System.IO.StreamReader(reportMailPath);
                string body = string.Empty;
                body = sr.ReadToEnd();

                //总次数信息报告
                totalWeekTimes += "Commit " + allTimes + " times<br/>" +
                                    "Build " + allTimes + " times<br/>" +
                                    allSuccessfulTimes + " passed(" + (((double.Parse(allSuccessfulTimes.ToString())) / (double.Parse(allTimes.ToString())))).ToString("0%") + ")<br/>" +
                                     allFiledTimes + " failed(" + (((double.Parse(allFiledTimes.ToString())) / (double.Parse(allTimes.ToString())))).ToString("0%") + ")";
                //作者信息报告
                for (int i = 0; i < memberList.Count; i++)
                {
                    weekByDeveloper += (i + 1).ToString() + ". " + memberList[i] + " , " + (memberSuccessfulTimes[i] + memberFiledTimes[i]).ToString() + "<br/>";

                    buildByDeveloper += (i + 1).ToString() + ". " + memberList[i] + " , " + (memberSuccessfulTimes[i] + memberFiledTimes[i]).ToString() + " builds, " +
                  memberSuccessfulTimes[i] + " passed(" + (((double.Parse(memberSuccessfulTimes[i].ToString())) / (double.Parse(((memberSuccessfulTimes[i] + memberFiledTimes[i]).ToString()))))).ToString("0%") + "), "
                 + memberFiledTimes[i] + " failed(" + (((double.Parse(memberFiledTimes[i].ToString())) / (double.Parse((memberSuccessfulTimes[i] + memberFiledTimes[i]).ToString())))).ToString("0%") + ") <br/>";
                }
                //项目信息报告
                for (int i = 0; i < projectList.Count; i++)
                {
                    weekByProject += (i + 1).ToString() + ". " + projectList[i] + " , " + (projectSuccessfulTimes[i] + projectFiledTimes[i]).ToString() + "<br/>";
                    buildByProject += (i + 1).ToString() + ". " + projectList[i] + " , " + (projectFiledTimes[i] + projectSuccessfulTimes[i]).ToString() + " builds, " +
                         projectSuccessfulTimes[i].ToString() + " passed(" + (((double.Parse(projectSuccessfulTimes[i].ToString())) / (double.Parse((projectSuccessfulTimes[i] + projectFiledTimes[i]).ToString())))).ToString("0%") + "), "
                        + projectFiledTimes[i].ToString() + " failed(" + (((double.Parse(projectFiledTimes[i].ToString())) / (double.Parse((projectSuccessfulTimes[i] + projectFiledTimes[i]).ToString())))).ToString("0%") + ") <br/>";

                }
                //发送邮件报告
                body = body.Replace("$WEEKTOTAL$", totalWeekTimes);
                body = body.Replace("$COMMIT_DEVELOPER$", weekByDeveloper);
                body = body.Replace("$COMMIT_PROJECT$", weekByProject);
                body = body.Replace("$BUILD_DEVELOPER$", buildByDeveloper);
                body = body.Replace("$BUILD_PROJECT$", buildByProject);
                body = body.Replace("$SERVER_VERSION$", "Send by LuckyCI v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                SmtpClient smtpClient = new SmtpClient();
                MailMessage mailMessage = new MailMessage();
                smtpClient.Host = configInfo.SmtpServer;
                smtpClient.UseDefaultCredentials = true;
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                string thisMonday = DateTime.Now.ToString("yyyy/MM/dd");
                string lastMonday = DateTime.Now.AddDays(-7).ToString("yyyy/MM/dd");

                mailMessage.From = new MailAddress(configInfo.ReportFrom);
                mailMessage.To.Add(configInfo.ReportTo);
                mailMessage.Subject = "Lucky CI Weekly Report " + lastMonday + "-" + thisMonday;
                mailMessage.Body = body;
                mailMessage.SubjectEncoding = Encoding.UTF8;
                mailMessage.BodyEncoding = Encoding.UTF8;
                mailMessage.Priority = MailPriority.High;
                mailMessage.IsBodyHtml = true;
                smtpClient.Send(mailMessage);
                return true;
            }
            catch (Exception ex) { return false; }
        }
示例#8
0
        /// <summary>
        /// 从mongodb中获取数据,发送周报告
        /// </summary>
        /// <param name="mongoConnectionPath"></param>
        /// <param name="reportMailPath"></param>
        /// <param name="configInfo"></param>
        /// <returns></returns>
        public bool SendWeekilReportFromMongodb(string mongoConnectionPath,string reportMailPath, ConfigInfo configInfo)
        {
            //需要统计的数据

            //一周提交总次数
            int allTimes = 0;
            int allSuccessfulTimes = 0;
            int allFiledTimes = 0;

            //暂存作者
            List<string> memberList = new List<string>();
            List<int> memberSuccessfulTimes = new List<int>();
            List<int> memberFiledTimes = new List<int>();
            //暂存项目名称
            List<string> projectList = new List<string>();
            List<int> projectSuccessfulTimes = new List<int>();
            List<int> projectFiledTimes = new List<int>();
            //获取上周一的日期
            DateTime lastMondayDate = DateTime.Now.AddDays(-7);
            try
            {
                //连接mongo数据库
                MongoClient client = new MongoClient(mongoConnectionPath);
                var database = client.GetDatabase("CILog");
                //var collection = database.GetCollection<User>("persion");
                var collection = database.GetCollection<WeeklyReportData>("WeeklyReportData");
                var list =  collection.Find(x => x.Submitter != "").ToList();
                allTimes = list.Count;
                collection.DeleteMany(x => x.Submitter != "");
                //遍历,总成功次数,以及总失败次数
                foreach (var singleTime in list)
                {
                    if (singleTime.BuildResult == "true")
                    {
                        allSuccessfulTimes++;
                    }
                    else { allFiledTimes++; }
                    //作者人名统计
                    bool memberFlag = false;
                    for(int i=0;i< memberList.Count;i++)
                    {
                        if (singleTime.Submitter==memberList[i]) {memberFlag=true; break; }
                    }
                    if (memberFlag == false) { memberList.Add(singleTime.Submitter); }
                    //项目名称统计
                    bool projectFlag = false;
                    for (int j=0;j< projectList.Count;j++)
                    {
                        if (singleTime.ProjectName == projectList[j]) { projectFlag = true;break; }
                    }
                    if (projectFlag == false) { projectList.Add(singleTime.ProjectName); }

                }
                //遍历,统计个人成功失败的次数
                for (int i=0;i<memberList.Count;i++)
                {
                    int tempTrue = 0;
                    int tempFalse = 0;
                    foreach (var singleTime in list)
                    {
                        if (memberList[i]==singleTime.Submitter&&singleTime.BuildResult=="true")
                        {
                            tempTrue++;
                        }
                        if (memberList[i] == singleTime.Submitter && singleTime.BuildResult == "false")
                        {
                            tempFalse++;
                        }
                    }
                    memberSuccessfulTimes.Add(tempTrue);
                    memberFiledTimes.Add(tempFalse);
                }
                //遍历,统计项目成功失败的次数
                for (int i=0;i<projectList.Count;i++)
                {
                    int tempTrue = 0;
                    int tempFalse = 0;
                    foreach (var singleTime in list)
                    {
                        if (projectList[i]==singleTime.ProjectName&&singleTime.BuildResult=="true")
                        {
                            tempTrue++;
                        }
                        if (projectList[i]==singleTime.ProjectName&&singleTime.BuildResult=="false")
                        {
                            tempFalse++;
                        }
                    }
                    projectSuccessfulTimes.Add(tempTrue);
                    projectFiledTimes.Add(tempFalse);
                }

                //排版发送邮件内容
                string totalWeekTimes = "";
                string weekByDeveloper = "";
                string buildByDeveloper = "";
                string weekByProject = "";
                string buildByProject = "";
                System.IO.StreamReader sr = new System.IO.StreamReader(reportMailPath);
                string body = string.Empty;
                body = sr.ReadToEnd();

                //总次数信息报告
                totalWeekTimes += "Commit " + allTimes + " times<br/>" +
                                    "Build " + allTimes + " times<br/>" +
                                    allSuccessfulTimes + " passed(" + (((double.Parse(allSuccessfulTimes.ToString())) / (double.Parse(allTimes.ToString())))).ToString("0%") + ")<br/>" +
                                     allFiledTimes + " failed(" + (((double.Parse(allFiledTimes.ToString())) / (double.Parse(allTimes.ToString())))).ToString("0%") + ")";
                //作者信息报告
                for (int i = 0; i < memberList.Count; i++)
                {
                    weekByDeveloper += (i + 1).ToString() + ". " + memberList[i] + " , " + (memberSuccessfulTimes[i] + memberFiledTimes[i]).ToString() + "<br/>";

                    buildByDeveloper += (i + 1).ToString() + ". " + memberList[i] + " , " + (memberSuccessfulTimes[i] + memberFiledTimes[i]).ToString() + " builds, " +
                  memberSuccessfulTimes[i] + " passed(" + (((double.Parse(memberSuccessfulTimes[i].ToString())) / (double.Parse(((memberSuccessfulTimes[i] + memberFiledTimes[i]).ToString()))))).ToString("0%") + "), "
                 + memberFiledTimes[i] + " failed(" + (((double.Parse(memberFiledTimes[i].ToString())) / (double.Parse((memberSuccessfulTimes[i] + memberFiledTimes[i]).ToString())))).ToString("0%") + ") <br/>";
                }
                //项目信息报告
                for (int i = 0; i < projectList.Count; i++)
                {
                    weekByProject += (i + 1).ToString() + ". " + projectList[i] + " , " + (projectSuccessfulTimes[i] + projectFiledTimes[i]).ToString() + "<br/>";
                    buildByProject += (i + 1).ToString() + ". " + projectList[i] + " , " + (projectFiledTimes[i] + projectSuccessfulTimes[i]).ToString() + " builds, " +
                         projectSuccessfulTimes[i].ToString() + " passed(" + (((double.Parse(projectSuccessfulTimes[i].ToString())) / (double.Parse((projectSuccessfulTimes[i] + projectFiledTimes[i]).ToString())))).ToString("0%") + "), "
                        + projectFiledTimes[i].ToString() + " failed(" + (((double.Parse(projectFiledTimes[i].ToString())) / (double.Parse((projectSuccessfulTimes[i] + projectFiledTimes[i]).ToString())))).ToString("0%") + ") <br/>";

                }
                //发送邮件报告
                body = body.Replace("$WEEKTOTAL$", totalWeekTimes);
                body = body.Replace("$COMMIT_DEVELOPER$", weekByDeveloper);
                body = body.Replace("$COMMIT_PROJECT$", weekByProject);
                body = body.Replace("$BUILD_DEVELOPER$", buildByDeveloper);
                body = body.Replace("$BUILD_PROJECT$", buildByProject);
                body = body.Replace("$SERVER_VERSION$", "Send by LuckyCI v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                SmtpClient smtpClient = new SmtpClient();
                MailMessage mailMessage = new MailMessage();
                smtpClient.Host = configInfo.SmtpServer;
                smtpClient.UseDefaultCredentials = true;
                smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                string thisMonday = DateTime.Now.ToString("yyyy/MM/dd");
                string lastMonday = DateTime.Now.AddDays(-7).ToString("yyyy/MM/dd");

                mailMessage.From = new MailAddress(configInfo.ReportFrom);
                mailMessage.To.Add(configInfo.ReportTo);
                mailMessage.Subject = "Lucky CI Weekly Report " + lastMonday + "-" + thisMonday;
                mailMessage.Body = body;
                mailMessage.SubjectEncoding = Encoding.UTF8;
                mailMessage.BodyEncoding = Encoding.UTF8;
                mailMessage.Priority = MailPriority.High;
                mailMessage.IsBodyHtml = true;
                smtpClient.Send(mailMessage);
                return true;
            }
            catch (Exception ex) { return false; }
        }