Пример #1
0
        /// <summary>
        /// 处理消息事件,统一放到此函数里面,此函数放到OnStart中,减少服务启动时的时间。
        /// </summary>
        public void HandleMessage()
        {
            //需要当作参数传递的路径
            string config             = System.AppDomain.CurrentDomain.BaseDirectory;
            int    p                  = config.LastIndexOf("\\");
            string parent             = config.Substring(0, p - 23);
            string CIConfigPath       = parent + "\\common\\res\\CIconfig.xml";
            string mailPath           = parent + "\\common\\SendMail.html";
            string mailWeekReportPath = parent + "\\common\\WeeklyReport.html";
            string dbPath             = parent + "\\common\\res\\CILog.mdb";
            string logPath            = parent + "\\log\\log.txt";

            //连接Rabbit
            ConnectRabbitMQ();
            //取回一条数据,并且当此数据处理完成,发送给Rabbit一条确认机制,之后再取回另一条数据。
            while (true)
            {
                using (var connection = factory.CreateConnection())
                {
                    using (var channel = connection.CreateModel())
                    {
                        channel.QueueDeclare("BuildResultInfo", false, false, false, null);

                        var consumer = new QueueingBasicConsumer(channel);
                        channel.BasicConsume("BuildResultInfo", false, consumer);
                        BasicDeliverEventArgs ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                        var body    = ea.Body;
                        var message = Encoding.UTF8.GetString(body);
                        JavaScriptSerializer Serializer      = new JavaScriptSerializer();
                        ProjectInfo          projectInfoData = Serializer.Deserialize <ProjectInfo>(message);
                        channel.BasicAck(ea.DeliveryTag, false);

                        //数据存储到mongoDB数据库
                        SaveInfoToDataBase(projectInfoData, dbPath, logPath);


                        //发送Email以及slack
                        ConfigInfo    configInfo = _configController.ConfigQuery("config/preferences", CIConfigPath);
                        SendMailSlack sendInfo   = new SendMailSlack(projectInfoData, mailPath, CIConfigPath, dbPath, configInfo, mailWeekReportPath);
                        sendInfo.SendMail();
                        sendInfo.SendSlack();
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 处理消息事件,统一放到此函数里面,此函数放到OnStart中,减少服务启动时的时间。
        /// </summary>
        public void HandleMessage()
        {
            //需要当作参数传递的路径
            string config = System.AppDomain.CurrentDomain.BaseDirectory;
            int p = config.LastIndexOf("\\");
            string parent = config.Substring(0, p - 23);
            string CIConfigPath = parent + "\\common\\res\\CIconfig.xml";
            string mailPath = parent + "\\common\\SendMail.html";
            string mailWeekReportPath = parent + "\\common\\WeeklyReport.html";
            string dbPath = parent + "\\common\\res\\CILog.mdb";
            string logPath = parent + "\\log\\log.txt";

            //连接Rabbit
            ConnectRabbitMQ();
            //取回一条数据,并且当此数据处理完成,发送给Rabbit一条确认机制,之后再取回另一条数据。
            while (true)
            {
                using (var connection = factory.CreateConnection())
                {
                    using (var channel = connection.CreateModel())
                    {
                        channel.QueueDeclare("BuildResultInfo", false, false, false, null);

                        var consumer = new QueueingBasicConsumer(channel);
                        channel.BasicConsume("BuildResultInfo", false, consumer);
                        BasicDeliverEventArgs ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                        var body = ea.Body;
                        var message = Encoding.UTF8.GetString(body);
                        JavaScriptSerializer Serializer = new JavaScriptSerializer();
                        ProjectInfo projectInfoData = Serializer.Deserialize<ProjectInfo>(message);
                        channel.BasicAck(ea.DeliveryTag, false);

                        //数据存储到mongoDB数据库
                        SaveInfoToDataBase(projectInfoData, dbPath, logPath);

                        //发送Email以及slack
                        ConfigInfo configInfo = _configController.ConfigQuery("config/preferences", CIConfigPath);
                        SendMailSlack sendInfo = new SendMailSlack(projectInfoData, mailPath, CIConfigPath, dbPath, configInfo, mailWeekReportPath);
                        sendInfo.SendMail();
                        sendInfo.SendSlack();
                    }
                }
            }
        }