Ejemplo n.º 1
0
        private void ProcessBreakerReports()
        {
            DateTime today        = DateTime.Now;
            DateTime firstOfMonth = today.AddDays(1 - today.Day).AddMonths(-1);
            DateTime endOfMonth   = firstOfMonth.AddMonths(1).AddDays(-1);

            AllBreakersReport report = new AllBreakersReport(firstOfMonth, endOfMonth);

            byte[] pdf = report.createPDF();
            if (pdf == null)
            {
                return;
            }
            byte[] csv = ExportAllToCSV(report.DataTable, firstOfMonth, endOfMonth);
            if (csv == null)
            {
                return;
            }

            using (MemoryStream pdfStream = new MemoryStream(pdf))
                using (MemoryStream csvStream = new MemoryStream(csv))
                {
                    string fileName       = "AllBreakersReport_" + firstOfMonth.ToString("MM_dd_yyyy") + "_" + endOfMonth.ToString("MM_dd_yyyy");
                    string pdfContentType = "application/pdf";
                    string csvContentType = "text/csv";
                    string pdfName        = fileName + ".pdf";
                    string csvName        = fileName + ".csv";

                    List <Attachment> attachments = new List <Attachment>()
                    {
                        new Attachment(pdfStream, pdfName, pdfContentType),
                        new Attachment(csvStream, csvName, csvContentType)
                    };

                    using (DataContext dataConext = new DataContext("systemSettings"))
                    {
                        EmailWriter emailWriter = new EmailWriter(dataConext, PQReportsSettings, EmailSettings);

                        emailWriter.SendEmailWithAttachment(BreakerReportsSettings.EmailList.Split(',').ToList(), $"Breaker Report for {fileName}", "", attachments);
                    }
                }
        }
Ejemplo n.º 2
0
        private void ProcessPQReports()
        {
            DateTime today        = DateTime.Now;
            DateTime firstOfMonth = today.AddDays(1 - today.Day).AddMonths(-1);
            DateTime endOfMonth   = firstOfMonth.AddMonths(1).AddDays(-1);

            using (DataContext dataContext = new DataContext("systemSettings"))
            {
                // TODO: There is no EmailGroupAssetGroup
                IEnumerable <Meter> meters = dataContext.Table <Meter>().QueryRecordsWhere("ID IN (SELECT MeterID FROM MeterAssetGroup WHERE AssetGroupID IN (SELECT AssetGroupID FROM EmailGroupAssetGroup WHERE EmailGroupID = (SELECT ID FROM EmailGroup WHERE Name = 'PQ Report')))");

                foreach (Meter meter in meters)
                {
                    ProcessMonthlyReport(meter, firstOfMonth, endOfMonth, dataContext);
                }

                EmailWriter emailWriter = new EmailWriter(dataContext, PQReportsSettings, EmailSettings);
                emailWriter.Execute(firstOfMonth.Month, firstOfMonth.Year);
            }
        }