Esempio n. 1
0
        private bool NeedToSendNotification(Report report, Fact[] facts)
        {
            using (var scope = _objectFactory.CreateScope())
            {
                var unitOfWork = scope.Resolve<IUnitOfWork>();
                var previousReportDateSql = QueryStore.PreviousReportBySourceCode();

                var previousReportDate = unitOfWork.Session.Query(previousReportDateSql, new {report.SourceCode});

                var currentCount = Enum.GetValues(typeof (FactLevel))
                    .Cast<FactLevel>()
                    .ToDictionary(l => (int)l, l => facts.Count(f => f.Level == l));

                var previousCount = Enum.GetValues(typeof (FactLevel))
                    .Cast<FactLevel>()
                    .ToDictionary(l => (int) l, l => previousReportDate.Count(f => f.Level == (int) l));

                foreach (var current in currentCount)
                {
                    if (previousCount[current.Key] != current.Value)
                    {
                        return true;
                    }
                }

                return false;
            }
        }
Esempio n. 2
0
        public void SendNewReport(Report report, Fact[] facts)
        {
            var sourceCode = report.SourceCode;

               var recievers =  _config.Notification.Recievers.Cast<Reciever>()
                .Where(r => r.SourceList.Count == 0 || r.SourceList.Contains(sourceCode));

            var levelCount = new ReportInfo
            {
                CreatedAt = report.CreatedAt,
                Level25 = facts.Count(f => f.Level == FactLevel.Normal),
                Level50 = facts.Count(f => f.Level == FactLevel.Warning),
                Level75 = facts.Count(f => f.Level == FactLevel.Error),
                Level100 = facts.Count(f => f.Level == FactLevel.Critical),
                CustomStyles = CustomStyles(report.CreatedAt)
            };

            foreach (var reciever in recievers)
            {
                var data = new List<KeyValuePair<string, ReportInfo>>
                {
                    new KeyValuePair<string, ReportInfo>(sourceCode, levelCount)

                };
                SourceInfoEmailTemplate template = new SourceInfoEmailTemplate() { SourceCodeData = data };
                var emailBody = template.TransformText();

                var info = new NotificationSenderInfo
                {
                    Body = emailBody,
                    Recipient = reciever.Name,
                    Subject = string.Format("[{0}] new important events", report.SourceCode )
                };

                SendEmail(info);
            }
        }