示例#1
0
        public async Task <bool> SendSMS(List <String> SMSNumbers)
        {
            FlightProcessorConnection CN = new FlightProcessorConnection();

            if (_AlertType == "Critical")
            {
                foreach (String SMSNumber in SMSNumbers)
                {
                    PortalAlertEmail Notification = new PortalAlertEmail {
                        Attachments  = null,
                        Body         = _AlertMessage,
                        CreatedOn    = DateTime.UtcNow,
                        EmailID      = 0,
                        EmailSubject = $"SMS - {_AlertCategory}",
                        EmailURL     = null,
                        FromAddress  = null,
                        IsSend       = 0,
                        SendOn       = null,
                        SendStatus   = null,
                        SendType     = "SMS",
                        ToAddress    = SMSNumber,
                        UserID       = 0
                    };
                    CN.PortalAlertEmail.Add(Notification);
                } //foreach (String SMSNumber in SMSNumbers)
                await CN.SaveChangesAsync();
            }     //if(_AlertType == "Critical")
            return(true);
        }
示例#2
0
        public static int SMSQue(
            int UserID,
            String ToAddress,
            String Body)
        {
            int QueID = 0;

            using (var ctx = new ExponentPortalEntities()) {
                var Email = new PortalAlertEmail {
                    EmailSubject = "SMS to " + ToAddress,
                    EmailURL     = null,
                    Body         = Body,
                    FromAddress  = "*****@*****.**",
                    ToAddress    = ToAddress,
                    UserID       = UserID,
                    //default values set for items
                    CreatedOn  = DateTime.Now,
                    IsSend     = 0,
                    SendOn     = null,
                    SendStatus = "In Queue",
                    SendType   = "SMS"
                };
                ctx.PortalAlertEmails.Add(Email);
                ctx.SaveChanges();
                QueID = Email.EmailID;
            }

            return(QueID);
        }
示例#3
0
        public static async Task <bool> AddToSmsQueue(PortalAlert alert)
        {
            //Load default Numbers, if not loaded already
            lock (_lockSMSNumbers) {
                if (_GlobalSmsNumbers == null)
                {
                    if (!GetSmsNumbers())
                    {
                        _GlobalSmsNumbers = new List <String>();
                    }
                }
            }
            //Add the SMS Number of local pilot
            List <String> LocalSmsNumbers = _GlobalSmsNumbers.ToList();
            int           PilotID         = (int)alert.PilotID;

            using (FlightProcessorConnection cn = new FlightProcessorConnection()) {
                String PilotSMSNumber = await cn.MSTR_User
                                        .Where(w => w.UserId == PilotID)
                                        .Select(s => s.MobileNo)
                                        .FirstOrDefaultAsync();

                if (!String.IsNullOrWhiteSpace(PilotSMSNumber))
                {
                    LocalSmsNumbers.Add(FixCellNumber(PilotSMSNumber));
                }

                foreach (var CellNumber in LocalSmsNumbers)
                {
                    PortalAlertEmail portalAlertEmail = new PortalAlertEmail {
                        CreatedOn   = DateTime.UtcNow,
                        Attachments = null,
                        Body        = alert.AlertMessage,
                        SendType    = "SMS",
                        ToAddress   = CellNumber,
                        IsSend      = 0,
                        SendStatus  = "Waiting",
                        UserID      = PilotID,
                        SendOn      = null
                    };
                    cn.PortalAlertEmail.Add(portalAlertEmail);
                }

                try {
                    await cn.SaveChangesAsync();

                    return(true);
                } catch {
                }
            }
            return(false);
        }
示例#4
0
        private static AlertSendStatus SendEmail(PortalAlertEmail portalAlertEmail)
        {
            AlertSendStatus alertSendStatus = new AlertSendStatus {
                IsSend = false
            };
            EmailMessage email = new EmailMessage(portalAlertEmail);

            Task taskA = Task.Factory.StartNew(() => { alertSendStatus = email.Send(); });

            taskA.Wait();

            return(alertSendStatus);
        }
示例#5
0
 public static async Task <bool> AddToEmailQueue(PortalAlertEmail portalAlertEmail)
 {
     if (!String.IsNullOrEmpty(portalAlertEmail.ToAddress))
     {
         portalAlertEmail.ToAddress = portalAlertEmail.ToAddress + ";";
     }
     portalAlertEmail.ToAddress += String.Join(";", GlobalEmailIDs);
     using (FlightProcessorConnection cn = new FlightProcessorConnection()) {
         cn.PortalAlertEmail.Add(portalAlertEmail);
         await cn.SaveChangesAsync();
     }
     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);
        }
示例#7
0
        private static async Task <AlertSendStatus> SendSMS(PortalAlertEmail portalAlertEmail)
        {
            SMS sms = new SMS(portalAlertEmail.ToAddress, portalAlertEmail.Body);

            return(await sms.Send());
        }
 public EmailMessage(PortalAlertEmail portalAlertEmail)
 {
     emailMessage = portalAlertEmail;
 }