public List <bool[]> Send(List <ItineraryQueue> itineraryQueues, ItineraryFlightStatus itineraryFlightStatus) { try { Forecast forecast = null; var isAnyItemNotTriggered = itineraryQueues.Any(i => i.IsTriggered == false); if (isAnyItemNotTriggered && itineraryFlightStatus.FlightStatus != "C") { ItineraryWeatherStatusData itineraryWeatherStatusData = new ItineraryWeatherStatusData(new WUDataSource()); forecast = itineraryWeatherStatusData.GetItineraryWeatherStatus(itineraryFlightStatus.ArrivalAirportCode, DateTime.Now); } ItineraryQueue item = itineraryQueues.FirstOrDefault(); bool[] isEmailSent = item != null && !item.IsTriggered ? SendEmail(itineraryQueues, itineraryFlightStatus, forecast) : new bool[itineraryQueues.Count]; var isSMSSent = SendSMS(itineraryQueues, itineraryFlightStatus, forecast); return(new List <bool[]> { isEmailSent, isSMSSent }); } catch (Exception exception) { foreach (var itineraryQueue in itineraryQueues) { ErrorLog.WriteErrorLog(exception, itineraryQueue.BookingID, "MMT_WS_FlightWeather"); } return(new List <bool[]> { new bool[itineraryQueues.Count], new bool[itineraryQueues.Count] }); } }
public ItineraryFlightStatus GetStatus(BaseItinerary requestModel) { _itineraryModel = requestModel; string key = requestModel.AirlineCode + requestModel.FlightNo + requestModel.DepartureDateTime.ToString("ddd") + requestModel.FromCity + requestModel.ToCity; ItineraryFlightStatus response = CommonCache.GetOrInsertIntoCache(GetFlightStatsResponse, key); return(response); }
private ItineraryFlightStatus LogFlightStatus(flightStatusV2 status, ItineraryFlightStatus flightStatus) { using (MMTSqlLiveEntities entities = new MMTSqlLiveEntities(StaticHelperValues.MMTSqlEntitiesConnectionString)) { tbl_FlightStatusLog flightStatusLog = new tbl_FlightStatusLog { AirlineCode = flightStatus.CarrierCode, FlightNo = flightStatus.FlightNumber, Delays = flightStatus.DepartureGateDelayMin, DepartureDate = flightStatus.DepartureDate, Status = flightStatus.FlightStatus, FromAirportCode = _itineraryModel.FromCity, ToAirportCode = _itineraryModel.ToCity, LastModifiedDate = DateTime.Now, Response = XElement.Parse(SerializeDeserialize.SerializeObject(status)).ToString(SaveOptions.DisableFormatting) }; if (flightStatus.EstimatedGateDeparture != DateTime.MinValue) { flightStatusLog.ExpectedDate = flightStatus.EstimatedGateDeparture; } try { entities.tbl_FlightStatusLog.Add(flightStatusLog); entities.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach ( DbValidationError error in dbEx.EntityValidationErrors.SelectMany(entityErr => entityErr.ValidationErrors)) { string errorMessage = string.Format("Error Property Name {0} : Error Message: {1}", error.PropertyName, error.ErrorMessage); ErrorLog.WriteErrorLog(errorMessage, "", "MMT_WS_FlightWeather"); } } catch (Exception exception) { ErrorLog.WriteErrorLog(exception, "", "MMT_WS_FlightWeather"); } } return(flightStatus); }
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 static bool[] SendEmail(IReadOnlyCollection <ItineraryQueue> itineraryQueues, ItineraryFlightStatus itineraryFlightStatus, Forecast forecast) { bool[] isEmailSent = new bool[itineraryQueues.Count]; InteractionMailManager mailManager = new InteractionMailManager(); int i = 0; foreach (FlightWeatherResponse response in itineraryQueues.Select(itineraryQueue => new FlightWeatherResponse { ItineraryFlightStatus = itineraryFlightStatus, ItineraryQueue = itineraryQueue, Forecast = forecast })) { bool emailSent; try { emailSent = mailManager.SendMail(response); } catch (Exception exception) { emailSent = false; ErrorLog.WriteErrorLog(exception, response.ItineraryQueue.BookingID, "MMT_WS_FlightWeather"); } isEmailSent[i++] = emailSent; } return(isEmailSent); }
private ItineraryFlightStatus MapItineraryFlightStatus(flightStatusV2[] statuses, responseFlightStatus responseFlightStatus) { var departureStatus = statuses.First(i => i.departureAirportFsCode == _itineraryModel.FromCity); var arrivalStatus = statuses.First(i => i.arrivalAirportFsCode == _itineraryModel.ToCity); var depAirportInfo = responseFlightStatus.appendix.airports.FirstOrDefault(i => i.iata == _itineraryModel.FromCity); var arrAirportInfo = responseFlightStatus.appendix.airports.FirstOrDefault(i => i.iata == _itineraryModel.ToCity); var airlineInfo = responseFlightStatus.appendix.airlines.FirstOrDefault(i => i.fs == _itineraryModel.AirlineCode); ItineraryFlightStatus flightStatus = new ItineraryFlightStatus { CarrierCode = departureStatus.carrierFsCode, FlightNumber = departureStatus.flightNumber, FlightStatus = departureStatus.status, DepartureAirportCode = departureStatus.departureAirportFsCode, ArrivalAirportCode = arrivalStatus.arrivalAirportFsCode }; if (departureStatus.departureDate != null && departureStatus.departureDate.dateLocal != null) { flightStatus.DepartureDate = Convert.ToDateTime(departureStatus.departureDate.dateLocal); } if (arrivalStatus.arrivalDate != null && arrivalStatus.arrivalDate.dateLocal != null) { flightStatus.ArrivalDate = Convert.ToDateTime(arrivalStatus.arrivalDate.dateLocal); } if (departureStatus.operationalTimes != null && departureStatus.operationalTimes.scheduledGateDeparture != null && departureStatus.operationalTimes.scheduledGateDeparture.dateLocal != null) { flightStatus.ScheduledGateDeparture = Convert.ToDateTime(departureStatus.operationalTimes.scheduledGateDeparture.dateLocal); } if (departureStatus.operationalTimes != null && departureStatus.operationalTimes.estimatedGateDeparture != null && departureStatus.operationalTimes.estimatedGateDeparture.dateLocal != null) { flightStatus.EstimatedGateDeparture = Convert.ToDateTime(departureStatus.operationalTimes.estimatedGateDeparture.dateLocal); } if (departureStatus.operationalTimes != null && departureStatus.operationalTimes.actualGateDeparture != null && departureStatus.operationalTimes.actualGateDeparture.dateLocal != null) { flightStatus.ActualGateDeparture = Convert.ToDateTime(arrivalStatus.operationalTimes.actualGateDeparture.dateLocal); } if (arrivalStatus.operationalTimes != null && arrivalStatus.operationalTimes.scheduledGateArrival != null && arrivalStatus.operationalTimes.scheduledGateArrival.dateLocal != null) { flightStatus.ScheduledGateArrival = Convert.ToDateTime(arrivalStatus.operationalTimes.scheduledGateArrival.dateLocal); } if (arrivalStatus.operationalTimes != null && arrivalStatus.operationalTimes.estimatedGateArrival != null && arrivalStatus.operationalTimes.estimatedGateArrival.dateLocal != null) { flightStatus.EstimatedGateArrival = Convert.ToDateTime(arrivalStatus.operationalTimes.estimatedGateArrival.dateLocal); } if (arrivalStatus.operationalTimes != null && arrivalStatus.operationalTimes.actualGateArrival != null && arrivalStatus.operationalTimes.actualGateArrival.dateLocal != null) { flightStatus.ActualGateArrival = Convert.ToDateTime(arrivalStatus.operationalTimes.actualGateArrival.dateLocal); } if (departureStatus.delays != null) { flightStatus.DepartureGateDelayMin = departureStatus.delays.departureGateDelayMinutes; } if (departureStatus.airportResources != null) { flightStatus.DepTerminal = departureStatus.airportResources.departureTerminal; } if (arrivalStatus.airportResources != null) { flightStatus.ArrTerminal = arrivalStatus.airportResources.arrivalTerminal; } if (depAirportInfo != null) { flightStatus.DepCity = depAirportInfo.city; flightStatus.DepAirport = depAirportInfo.name; } if (arrAirportInfo != null) { flightStatus.ArrCity = arrAirportInfo.city; flightStatus.ArrAirPort = arrAirportInfo.name; } if (airlineInfo != null) { flightStatus.CarrierName = airlineInfo.name; } return(flightStatus); }
private static void SendGeneralTicket(IEnumerable <ItineraryModel> itineraries, ItineraryFlightStatus itineraryFlightStatus) { try { Parallel.ForEach(itineraries, itineraryModel => { itineraryModel.IsProcessed = true; string flightStatus = itineraryFlightStatus != null ? itineraryFlightStatus.FlightStatus : string.Empty; // MoveToDispatch.DoWithSP(itineraryModel.BookingID); ErrorLog.WriteErrorLog("FlightStatus: " + flightStatus, itineraryModel.BookingID, "MMT_WS_FlightWeather"); }); } catch (AggregateException aggregateException) { ErrorLog.WriteErrorLog(aggregateException.Flatten(), "", WindowsServiceName); } catch (Exception exception) { ErrorLog.WriteErrorLog(exception, "", WindowsServiceName); } }