Exemplo n.º 1
0
        public static string GetSMSText(FlightWeatherResponse flightWeatherResponse)
        {
            string flightNo = flightWeatherResponse.ItineraryQueue.AirlineCode + "-" +
                              flightWeatherResponse.ItineraryQueue.FlightNo;
            DateTime depDate = flightWeatherResponse.ItineraryFlightStatus.EstimatedGateDeparture == DateTime.MinValue
            ? flightWeatherResponse.ItineraryFlightStatus.ScheduledGateDeparture : flightWeatherResponse.ItineraryFlightStatus.EstimatedGateDeparture;
            string airlineName = flightWeatherResponse.ItineraryFlightStatus.CarrierName;
            string sectorName  = flightWeatherResponse.ItineraryQueue.FromCity + "-" +
                                 flightWeatherResponse.ItineraryQueue.ToCity;
            StringBuilder smsText = new StringBuilder();

            switch (flightWeatherResponse.ItineraryQueue.Status)
            {
            case "S":
                if (flightWeatherResponse.ItineraryFlightStatus.DepartureGateDelayMin < AllowedDelayMin)
                {
                    smsText = smsText.AppendFormat("Your flight {0} from {1} is On Time. Departure time: {2} hrs on {3}. ",
                                                   flightNo,
                                                   sectorName,
                                                   depDate.ToString("hh:mm tt"),
                                                   depDate.ToString("d"));
                }
                else
                {
                    smsText = smsText.AppendFormat("Your flight {0} from {1} is delayed by {2} mins. New Departure time: {3} hrs on {4}. ",
                                                   flightNo,
                                                   sectorName,
                                                   flightWeatherResponse.ItineraryFlightStatus.DepartureGateDelayMin,
                                                   depDate.ToString("hh:mm tt"),
                                                   depDate.ToString("d"));
                }
                break;

            case "C":
                return(smsText.AppendFormat("Your flight {0} from {1} has been cancelled. Please contact airline for further enquiry.",
                                            flightNo,
                                            sectorName).ToString());
            }
            if (!String.IsNullOrWhiteSpace(flightWeatherResponse.ItineraryFlightStatus.DepTerminal))
            {
                smsText = smsText.AppendFormat("Departure Terminal: {0}. ",
                                               flightWeatherResponse.ItineraryFlightStatus.DepTerminal);
            }
            if (flightWeatherResponse.Forecast != null &&
                flightWeatherResponse.Forecast.simpleforecast != null &&
                flightWeatherResponse.Forecast.simpleforecast.forecastday.Count > 0)
            {
                var currentDayForecast = flightWeatherResponse.Forecast.simpleforecast.forecastday.First();
                smsText =
                    smsText.AppendFormat(
                        "Weather in {0}- Min temp: {1}C, Max Temp: {2}C.",
                        flightWeatherResponse.ItineraryFlightStatus.ArrCity, currentDayForecast.low.celsius,
                        currentDayForecast.high.celsius);
            }
            return(smsText.ToString());
        }
        public bool SendMail(FlightWeatherResponse flightWeatherResponse)
        {
            string body    = GetBody(flightWeatherResponse);
            var    subject = MailText.EmailSubject(flightWeatherResponse);

            using (MMT_WEBS_InteractionManagerSoapClient client = new MMT_WEBS_InteractionManagerSoapClient())
            {
                if (string.IsNullOrWhiteSpace(body))
                {
                    return(false);
                }
                EMailAttachment[] attachments = null;
                if (flightWeatherResponse.ItineraryFlightStatus.FlightStatus == "S")
                {
                    try
                    {
                        attachments = new EMailAttachment[1];
                        EMailAttachment attachment = new EMailAttachment
                        {
                            Content   = MailManager.GetETicketBytes(flightWeatherResponse.ItineraryQueue),
                            ContentId = "E-Ticket",
                            FileName  = flightWeatherResponse.ItineraryQueue.BookingID + ".E-Ticket.pdf"
                        };
                        attachments[0] = attachment;
                    }
                    catch (Exception exception)
                    {
                        ErrorLog.WriteErrorLog(exception, flightWeatherResponse.ItineraryQueue.BookingID, "MMT_WS_FlightWeather");
                    }
                }

                EMailMessage mailMessage = new EMailMessage
                {
                    To            = new[] { flightWeatherResponse.ItineraryQueue.BookingDetails.Email },
                    Subject       = subject,
                    Source        = MailText.Source,
                    ReferenceNo   = flightWeatherResponse.ItineraryQueue.BookingID,
                    IsBodyHtml    = true,
                    Body          = body,
                    From          = MailText.From,
                    ReferenceType = "BookingID",
                    RequestDate   = DateTime.Now,
                    Attachment    = attachments,
                    emailType     = EmailType.General
                };
                string errorMessage = string.Empty;
                return(client.SendEmail(mailMessage, ref errorMessage));
            }
        }
        private static bool[] SendSMS(IEnumerable <ItineraryQueue> itineraryQueues, ItineraryFlightStatus itineraryFlightStatus, Forecast forecast)
        {
            EFMailManager smsManager = new EFMailManager();
            List <FlightWeatherResponse> responses = new List <FlightWeatherResponse>();

            foreach (var itineraryQueue in itineraryQueues)
            {
                FlightWeatherResponse response = new FlightWeatherResponse
                {
                    ItineraryFlightStatus = itineraryFlightStatus,
                    ItineraryQueue        = itineraryQueue
                };
                if (!itineraryQueue.IsTriggered)
                {
                    response.Forecast = forecast;
                }
                responses.Add(response);
            }
            bool[] isSMSSent = smsManager.SendSMS(responses);
            return(isSMSSent);
        }
 private string GetBody(FlightWeatherResponse flightWeatherResponse)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         using (StreamReader rd = new StreamReader(ms))
         {
             const string         fileName = "Template.xslt";
             XslCompiledTransform trans    = Helper.CommonCache.GetOrInsertIntoCache(GetXslCompiledTransform, "FlightWeatherMailTemplate",
                                                                                     Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", fileName));
             if (trans == null)
             {
                 return(string.Empty);
             }
             XmlWriter writer  = XmlWriter.Create(ms, trans.OutputSettings);
             XElement  element = getXElement(flightWeatherResponse);
             trans.Transform(element.CreateReader(), writer);
             ms.Position = 0;
             return(rd.ReadToEnd());
         }
     }
 }
Exemplo n.º 5
0
        public static string EmailSubject(FlightWeatherResponse flightWeatherResponse)
        {
            string flightNo = flightWeatherResponse.ItineraryQueue.AirlineCode + "-" +
                              flightWeatherResponse.ItineraryQueue.FlightNo;
            string subject     = String.Empty;
            string airlineName = flightWeatherResponse.ItineraryFlightStatus.CarrierName;
            string sectorName  = flightWeatherResponse.ItineraryQueue.FromCity + "-" +
                                 flightWeatherResponse.ItineraryQueue.ToCity;

            switch (flightWeatherResponse.ItineraryQueue.Status)
            {
            case "S":
                subject = String.Format("Upcoming Flight : {0} ({1}) Status",
                                        flightNo,
                                        sectorName);
                break;

            case "L":
                subject = String.Format("Upcoming Flight : {0} ({1}) Status",
                                        flightNo,
                                        sectorName);
                break;

            case "C":
                subject = String.Format("Upcoming Flight : {0} ({1}) Status",
                                        flightNo,
                                        sectorName);
                break;
            }
            if (flightWeatherResponse.ItineraryQueue.Status != "C" && flightWeatherResponse.Forecast != null &&
                flightWeatherResponse.Forecast.simpleforecast != null &&
                flightWeatherResponse.Forecast.simpleforecast.forecastday.Count > 0)
            {
                subject =
                    subject + string.Format(
                        " & Weather in {0}",
                        flightWeatherResponse.ItineraryFlightStatus.ArrCity);
            }
            return(subject);
        }
 public bool SendSMS(FlightWeatherResponse flightWeatherResponse)
 {
     throw new NotImplementedException();
 }
 private XElement getXElement(FlightWeatherResponse flightWeatherResponse)
 {
     return(XElement.Parse(SerializeDeserialize.SerializeObject(flightWeatherResponse)));
 }