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] }); } }
private void ProcessQueue(object obj) { ConcurrentDictionary <string, ItineraryQueue> queues = (ConcurrentDictionary <string, ItineraryQueue>)obj; while (queues.Count > 0) { foreach (var itemToRemove in queues.Where(i => (i.Value.ExpectedDateTime != DateTime.MinValue && i.Value.PickTime > i.Value.ExpectedDateTime.AddMinutes(-MinMinute)))) { ItineraryQueue itineraryQueue; queues.TryRemove(itemToRemove.Key, out itineraryQueue); } var toProcess = queues.Where(i => i.Value.PickTime < DateTime.Now) .GroupBy(i => i.Value.AirlineCode + i.Value.FlightNo + i.Value.DepartureDateTime.ToString("t") + i.Value.FromCity + i.Value.ToCity).ToList(); try { Parallel.ForEach(toProcess, eachEntry => { ItineraryQueue item = eachEntry.First().Value; try { var itineraryFlightStatus = FlightStatusData.GetItineraryFlightStatus(item); if (item.IsTriggered == false || (item.DelayInMinute != itineraryFlightStatus.DepartureGateDelayMin && Math.Abs(itineraryFlightStatus.DepartureGateDelayMin - item.DelayInMinute) > DiffInDelayMin)) { ItineraryFlightWeatherMail itineraryFlightWeatherMail = new ItineraryFlightWeatherMail(); itineraryFlightWeatherMail.Send(eachEntry.Select(i => i.Value).ToList(), itineraryFlightStatus); } eachEntry.ToList().ForEach(i => { i.Value.DelayInMinute = itineraryFlightStatus.DepartureGateDelayMin; i.Value.ExpectedDateTime = itineraryFlightStatus.EstimatedGateDeparture == DateTime.MinValue ? itineraryFlightStatus.ScheduledGateDeparture : itineraryFlightStatus.EstimatedGateDeparture; i.Value.PickTime = i.Value.PickTime.AddMinutes(ResendMailMin); i.Value.IsTriggered = true; }); } catch (Exception ex) { eachEntry.ToList().ForEach(i => { i.Value.PickTime = i.Value.PickTime.AddMinutes(ResendMailMin); i.Value.IsTriggered = true; }); foreach (var keyValuePair in eachEntry) { ErrorLog.WriteErrorLog(ex, keyValuePair.Value.BookingID, WindowsServiceName); } } }); } catch (AggregateException aggregateException) { ErrorLog.WriteErrorLog(aggregateException.Flatten(), "", WindowsServiceName); } catch (Exception exception) { ErrorLog.WriteErrorLog(exception, "", WindowsServiceName); } Thread.Sleep(6000); } }
public void objTimer_Elapsed(object sender, ElapsedEventArgs e) { try { _objTimer.Enabled = false; FlightDataSource dataSource = new FlightDataSource(); dataSource.GetItineraryData(_itineraryModels); RemoveStaleItinerary(_itineraryModels); var itineraryModelsGroupedByFlight = _itineraryModels.Where(i => i.IsProcessed == false) .GroupBy(i => i.AirlineCode + i.FlightNo + i.DepartureDateTime.ToString("t") + i.FromCity + i.ToCity); foreach (var itineraries in itineraryModelsGroupedByFlight) { ItineraryModel model = itineraries.FirstOrDefault(); if (model == null) { continue; } try { var itineraryFlightStatus = FlightStatusData.GetItineraryFlightStatus(model); if (itineraryFlightStatus != null && (new[] { "S", "C" }).Any(i => i == itineraryFlightStatus.FlightStatus.ToUpper())) { DateTime triggerDateTime = itineraryFlightStatus.DepartureGateDelayMin < AllowedDelayMin ? itineraryFlightStatus.DepartureDate.AddMinutes(-MinMinute) : DateTime.Now; foreach (ItineraryModel itineraryModel in itineraries) { string key = itineraryModel.BookingID + "-" + itineraryModel.AirlineCode + itineraryModel.FlightNo + "-" + itineraryModel.PNR + "-" + itineraryModel.DepartureDateTime.ToString("t"); ItineraryQueue queue = Mapper.Map <ItineraryQueue>(itineraryModel); queue.IsTriggered = false; queue.PickTime = triggerDateTime; queue.Status = itineraryFlightStatus.FlightStatus; queue.ExpectedDateTime = itineraryFlightStatus.EstimatedGateDeparture == DateTime.MinValue ? itineraryFlightStatus.ScheduledGateDeparture : itineraryFlightStatus.EstimatedGateDeparture; _itineraryQueues.TryAdd(key, queue); itineraryModel.IsProcessed = true; } } else { SendGeneralTicket(itineraries, itineraryFlightStatus); } } catch (Exception exception) { SendGeneralTicket(itineraries, exception); } } StartThreadsForQueue(_itineraryQueues); } catch (Exception exception) { ErrorLog.WriteErrorLog(exception, "", WindowsServiceName); } finally { _objTimer.Enabled = true; HeartBeatLoggerClass logger = new HeartBeatLoggerClass(); logger.Log(WindowsServiceName); } }