Beispiel #1
0
        public void EveryDay()
        {
            var recievers = _config.Notification.Recievers;

            IDictionary<string, ReportInfo> sourceCodeData = new Dictionary<string, ReportInfo>();

            var sql = GetSql(recievers);

            var data = _unitOfWork.Session.Query(sql);

            var groupedBySourceCode = data.GroupBy(d => d.SourceCode).Select(s => new
            {
                SourceCode = s.Key,
                LevelInfo = new ReportInfo
                {
                    Level25 = s.Where(l => l.Level == 25).Select(c => (int)c.Count).SingleOrDefault(),
                    Level50 = s.Where(l => l.Level == 50).Select(c => (int)c.Count).SingleOrDefault(),
                    Level75 = s.Where(l => l.Level == 75).Select(c => (int)c.Count).SingleOrDefault(),
                    Level100 = s.Where(l => l.Level == 100).Select(c => (int)c.Count).SingleOrDefault(),
                    CreatedAt = s.Select(c => c.CreatedAt).First(),
                    CustomStyles = CustomStyles(s)
                }
            });

            foreach (var group in groupedBySourceCode)
            {
                sourceCodeData.Add(group.SourceCode, group.LevelInfo);
            }

            foreach (Reciever reciever in recievers)
            {
                var filteredSources = reciever.SourceList.Count != 0
                    ? sourceCodeData.Where(k => reciever.SourceList.Contains(k.Key)).ToList()
                    : sourceCodeData.ToList();

                SourceInfoEmailTemplate template = new SourceInfoEmailTemplate() {SourceCodeData = filteredSources};

                var emailBody = template.TransformText();

                var info = new NotificationSenderInfo
                {
                    Body = emailBody,
                    Recipient = reciever.Name,
                    Subject = "Daily monitoring statistic"
                };

                SendEmail(info);
            }
        }
Beispiel #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);
            }
        }
Beispiel #3
0
 private void SendEmail(NotificationSenderInfo info)
 {
     try
     {
         _emailService.SendNotification(info);
     }
     catch (Exception e)
     {
         Console.WriteLine("Cannot send notifaction to {0}", info.Recipient);
     }
 }
 public void Send(NotificationSenderInfo info)
 {
     _emailService.SendNotification(info);
 }