Ejemplo n.º 1
0
        }//public String GetAlert

        public async Task <bool> Save()
        {
            using (FlightProcessorConnection CN = new FlightProcessorConnection()) {
                //Add to Portal Alert table, to record SMS
                PortalAlert ThisAlert = new PortalAlert {
                    AccountID      = _Flight.AccountID,
                    AlertCategory  = _AlertCategory,
                    AlertMessage   = _AlertMessage,
                    AlertType      = _AlertType,
                    Altitude       = (int)_Flight.Altitude,
                    ApprovalID     = _Flight.GetBase().ApprovalID,
                    CreatedOn      = DateTime.UtcNow,
                    DroneID        = _Flight.GetBase().DroneID,
                    FlightDataID   = _Flight.LastProcessedID,
                    FlightReadTime = _Flight.LastFlightDate,
                    Latitude       = _Flight.GetBase().Latitude,
                    Longitude      = _Flight.GetBase().Longitude,
                    PilotID        = _Flight.GetBase().PilotID,
                    FlightID       = _Flight.GetBase().ID
                };

                CN.PortalAlert.Add(ThisAlert);
                await CN.SaveChangesAsync();

                if (_AlertType == "Critical")
                {
                    await AlertQueue.AddToSmsQueue(ThisAlert);
                }
            }
            return(true);
        }
        public async Task <bool> GenerateReport()
        {
            String ReportPath     = ConfigurationManager.AppSettings["ReportPath"];
            String ReportURL      = ConfigurationManager.AppSettings["ReportURL"] + _FlightID.ToString();
            String ReportEmailURL = ConfigurationManager.AppSettings["ReportEmailURL"] + _FlightID.ToString();
            String PDFPath        = System.IO.Path.Combine(ReportPath, $"{_FlightID}.pdf");

            //Generate PDF
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
            converter.Options.MarginBottom       = 10;
            converter.Options.MarginLeft         = 10;
            converter.Options.MarginRight        = 10;
            converter.Options.MarginTop          = 10;
            converter.Options.EmbedFonts         = true;
            converter.Options.DrawBackground     = true;
            converter.Options.JavaScriptEnabled  = true;
            converter.Options.KeepImagesTogether = true;
            try {
                SelectPdf.PdfDocument doc = converter.ConvertUrl(ReportURL);
                doc.Save(PDFPath);
                doc.Close();
            } catch {
                return(false);
            }

            String NotificationEmails = _Approval?.EmailAddress;

            PortalAlertEmail portalAlertEmail = new PortalAlertEmail {
                CreatedOn    = DateTime.UtcNow,
                Attachments  = PDFPath,
                Body         = null,
                EmailSubject = $"Post Flight Report - {_FlightID}",
                EmailURL     = ReportEmailURL,
                SendType     = "Email",
                ToAddress    = NotificationEmails,
                IsSend       = 0,
                SendStatus   = "Waiting",
                UserID       = PilotID,
                SendOn       = null
            };

            await AlertQueue.AddToEmailQueue(portalAlertEmail);

            return(false);
        }