/// <summary> /// Calculate the correct message to reinsert so the PTMH2H table is updated /// </summary> /// <param name="ptm"></param> /// <returns></returns> public void CalculateErrorReprocessing(OSUSR_UUK_PAXMSGS ptm, int n) { System.Nullable <DateTime> lastPTMDateTime = this.SearchLastPTMForFlight(ptm); if (lastPTMDateTime != null && ptm.TIMESTAMP != null && ((DateTime)ptm.TIMESTAMP).CompareTo((DateTime)lastPTMDateTime) > 0) { OSUSR_UUK_FLT_INFO flightInfoI = null; // Obtain list of message from Baggage table if (ptm.IFLTNR != null && ptm.IDATE != null) { flightInfoI = this.SearchFlightInfo(ptm.IFLTNR, ptm.IDATE, ptm.IORIGIN, this.hub); if (flightInfoI != null && flightInfoI.FLT_NR != null) { this.EngineUpdatePTMH2H(flightInfoI, (DateTime)ptm.TIMESTAMP); } else { throw new EngineProcessingException("PTM TTY messagen with unrecognized flight"); } } else { throw new EngineProcessingException("PTM TTY messagen with unrecognized flight"); } } }
/// <summary> /// Process PTM logic /// </summary> /// <param name="messageObject"></param> /// <param name="n"></param> public void ProcessPTMTTYEngine(Object messageObject, int n) { BagTMLog.LogDebug("BagTM Engine PTM TTY", this); // Only process message if is a baggage message if (messageObject.GetType() != typeof(OSUSR_UUK_PAXMSGS)) { throw new EngineProcessingException("Not a PTM message."); } OSUSR_UUK_PAXMSGS ptm = (OSUSR_UUK_PAXMSGS)messageObject; BagTMLog.LogDebug("BagTM Engine Search FlightInfoI and FlightInfoF", this); OSUSR_UUK_FLT_INFO flightInfoI = null; // Obtain list of message from Baggage table if (ptm.IFLTNR != null && ptm.IDATE != null) { flightInfoI = this.SearchFlightInfo(ptm.IFLTNR, ptm.IDATE, ptm.IORIGIN, this.hub); if (flightInfoI != null && flightInfoI.FLT_NR != null) { this.EngineUpdatePTMH2H(flightInfoI, (DateTime)ptm.TIMESTAMP); } else { throw new EngineProcessingException("PTM TTY messagen with unrecognized flight"); } } else { throw new EngineProcessingException("PTM TTY messagen with unrecognized flight"); } BagTMLog.LogDebug("BagTM Engine Baggage PTM TTY End", this); }
/// <summary> /// Update H2H table based on flight information /// </summary> public void EngineUpdateH2H(OSUSR_UUK_FLT_INFO flightInfoI, OSUSR_UUK_FLT_INFO flightInfoF, bool isHub) { BagTMLog.LogDebug("BagTM Engine Update H2H Start", this); try { BagTMLog.LogDebug("BagTM Engine Update H2H FlightInfoI", flightInfoI); BagTMLog.LogDebug("BagTM Engine Update H2H FlightInfoF", flightInfoF); BagTMLog.LogDebug("BagTM Engine Update H2H Hub", this.hub); BagTMLog.LogDebug("BagTM Engine Update Search H2H", this); String iFLTNR = null; System.Nullable <DateTime> iDATE = null; String iORIGIN = null; String iDEST = null; String fFLTNR = null; System.Nullable <DateTime> fDATE = null; String fORIGIN = null; String fDEST = null; iFLTNR = (flightInfoI != null) ? CommonFunctions.FormatFlightNumber(flightInfoI.OPERATOR + flightInfoI.FLT_NR) : null; iDATE = (flightInfoI != null) ? flightInfoI.STD : null; iORIGIN = (flightInfoI != null) ? flightInfoI.FROM_IATA : null; iDEST = (flightInfoI != null) ? flightInfoI.TO_IATA : null; fFLTNR = (flightInfoF != null) ? CommonFunctions.FormatFlightNumber(flightInfoF.OPERATOR + flightInfoF.FLT_NR) : null; fDATE = (flightInfoF != null) ? flightInfoF.STD : null; fORIGIN = (flightInfoF != null) ? flightInfoF.FROM_IATA : null; fDEST = (flightInfoF != null) ? flightInfoF.TO_IATA : null; OSUSR_UUK_H2H h2h = this.SearchH2HyByFlightPair( iFLTNR, iDATE, iORIGIN, fFLTNR, fDATE, fORIGIN); BagTMLog.LogDebug("BagTM Engine Update H2H List", h2h); BaggageEntities dbinup = new BaggageEntities(); var bagQuery = from s in dbinup.OSUSR_UUK_BAGINTEG select s; var bagList = bagQuery.Where(s => s.IFLTNR == iFLTNR && DbFunctions.TruncateTime(s.IDATE) == DbFunctions.TruncateTime(iDATE) && s.IORIGIN == iORIGIN && (s.IAUT != BagTMRulesActions.PAX_AUT_STATUS_CODE || s.IAUT != BagTMRulesActions.BAG_GROUP_AUT_CODE)) .ToList(); BagTMLog.LogDebug("BagTM Engine Update Calculate BagIntegrity Bag Count", bagList); var bagCalculate = (from bi in bagList // here I choose each field I want to group by group bi by new { bi.IFLTNR, bi.IDATE, bi.IORIGIN, bi.FFLTNR, bi.FDATE, bi.FDEST } into g select new { IFLTNR = g.Key.IFLTNR, IDATE = g.Key.IDATE, IORIGIN = g.Key.IORIGIN, OFLTNR = g.Key.FFLTNR, ODATE = g.Key.FDATE, ODEST = g.Key.FDEST, Count = g.Count() } ).ToList(); BagTMLog.LogDebug("BagTM Engine Update H2H Bag Calculate", bagCalculate); if (h2h != null) { BagTMLog.LogDebug("BagTM Engine Update H2H Flight Process", h2h); h2h.IDATE = (flightInfoI != null) ? flightInfoI.STD : null; h2h.IETA = (flightInfoI != null) ? flightInfoI.ETA : null; h2h.IATA = (flightInfoI != null) ? flightInfoI.ATA : null; h2h.ISTAND = (flightInfoI != null) ? flightInfoI.TO_STAND : null; h2h.HULLOPEN = (flightInfoI != null) ? flightInfoI.DOOROPEN : null; h2h.IFLTINFOID = (flightInfoI != null && flightInfoI.ID != 0) ? (System.Nullable <int>)flightInfoI.ID : null; h2h.ODATE = (flightInfoF != null) ? flightInfoF.STD : null; h2h.ETD = (flightInfoF != null) ? flightInfoF.ETD : null; h2h.ATD = (flightInfoF != null) ? flightInfoF.ATD : null; h2h.STANDD = (flightInfoF != null) ? flightInfoF.FROM_STAND : null; h2h.HULLCLOSE = (flightInfoF != null) ? flightInfoF.DOORCLOSED : null; h2h.OFLTINFOID = (flightInfoF != null && flightInfoF.ID != 0) ? (System.Nullable <int>)flightInfoF.ID : null; var calcBaggageFlightIF = bagCalculate.Where(s => s.IFLTNR == h2h.IFLTNR && s.IDATE == ((h2h.IDATE != null) ? ((DateTime)h2h.IDATE).Date : h2h.IDATE) && s.IORIGIN == h2h.IORIGIN && s.OFLTNR == h2h.OFLTNR && s.ODATE == ((h2h.ODATE != null) ? ((DateTime)h2h.ODATE).Date : h2h.ODATE)) .FirstOrDefault(); var calcBaggageFlightI = bagCalculate.Where(s => s.IFLTNR == h2h.IFLTNR && s.IDATE == ((h2h.IDATE != null) ? ((DateTime)h2h.IDATE).Date : h2h.IDATE) && s.IFLTNR != null) .GroupBy(s => new { s.IFLTNR, s.IDATE }) .Select(r => new { FLIGHT = r.Key.IFLTNR, DATE = r.Key.IDATE, SUMBAGGAGES = r.Sum(x => x.Count) }).FirstOrDefault(); BagTMLog.LogDebug("BagTM Engine Update H2H Exist", calcBaggageFlightIF); if (calcBaggageFlightIF != null && calcBaggageFlightIF.Count > 0) { // To update inbound NRBAGS count for Hub messages if (h2h.IFLTNR != null) { h2h.INRBAGS = calcBaggageFlightIF.Count; h2h.OLNRBAGS = 0; } else { h2h.INRBAGS = 0; h2h.OLNRBAGS = calcBaggageFlightIF.Count; } if (h2h.OFLTNR == null) { h2h.OLNRBAGS = 0; } BagTMLog.LogInfo("BagTM Engine H2H Update: " + h2h.ID, this); } else { // To update inbound NRBAGS count for Hub messages if (isHub) { h2h.INRBAGS = 0; } else { h2h.OLNRBAGS = 0; } } System.Nullable <int> inboundFlightEquip = null; if (flightInfoI != null && flightInfoI.AC_REGISTRATION != null) { OSUSR_UUK_REGISTRATIONS reg = registrationList.Where(x => x.ACREGISTRATION == flightInfoI.AC_REGISTRATION) .FirstOrDefault <OSUSR_UUK_REGISTRATIONS>(); inboundFlightEquip = (reg != null) ? reg.EQUIPTYPEID : (System.Nullable <int>)Convert.ToInt32(this.defaultEquipment); } System.Nullable <int> outboundFlightEquip = null; if (flightInfoF != null && flightInfoF.AC_REGISTRATION != null) { OSUSR_UUK_REGISTRATIONS reg = registrationList.Where(x => x.ACREGISTRATION == flightInfoF.AC_REGISTRATION) .FirstOrDefault <OSUSR_UUK_REGISTRATIONS>(); outboundFlightEquip = (reg != null) ? reg.EQUIPTYPEID : (System.Nullable <int>)Convert.ToInt32(this.defaultEquipment); } Decimal[] timesInbound = this.CalculateTimes( (inboundFlightEquip != null) ? inboundFlightEquip : (System.Nullable <int>)Convert.ToInt32(this.defaultEquipment), (flightInfoI != null) ? flightInfoI.TO_STAND : this.defaultStandFrom, (flightInfoI != null) ? this.baggageTerminalCode : this.defaultGateTo); Decimal[] timesOutbound = this.CalculateTimes( (outboundFlightEquip != null) ? outboundFlightEquip : (System.Nullable <int>)Convert.ToInt32(this.defaultEquipment), (flightInfoF != null) ? this.baggageTerminalCode : this.defaultStandFrom, (flightInfoF != null) ? flightInfoF.FROM_GATE : this.defaultGateTo); Double calcETU = 0; Double calcETL = 0; // Calculate times and insert if flight exists if (h2h.IFLTNR != null) { h2h.IUNLOAD = (calcBaggageFlightI != null) ? timesInbound[0] * (Decimal)calcBaggageFlightI.SUMBAGGAGES : 0; h2h.IINJECT = (calcBaggageFlightI != null) ? timesInbound[1] * (Decimal)calcBaggageFlightI.SUMBAGGAGES : 0; h2h.ITAXI = (calcBaggageFlightI != null) ? timesInbound[3] : 0; // Calculate ETU calcETU = Convert.ToDouble(h2h.IUNLOAD + h2h.IINJECT + h2h.ITAXI); calcETU = Math.Max(this.minLoadUnloadTime * 60 + Convert.ToDouble(h2h.IINJECT) + Convert.ToDouble(h2h.ITAXI), calcETU); calcETU = Math.Min(this.maxLoadUnloadTime * 60 + Convert.ToDouble(h2h.IINJECT) + Convert.ToDouble(h2h.ITAXI), calcETU); h2h.ETU = (h2h.HULLOPEN != null && h2h.HULLOPEN.Value.Year != 1900) ? h2h.HULLOPEN : (h2h.IATA != null && h2h.IATA.Value.Year != 1900) ? h2h.IATA : (h2h.IETA != null && h2h.IETA.Value.Year != 1900) ? h2h.IETA : null; if (h2h.ETU != null) { h2h.ETU = ((DateTime)h2h.ETU).AddSeconds(Math.Min(calcETU, (double)this.maxBaggageTurnaround * 60)); } } if (h2h.OFLTNR != null) { h2h.OLOAD = (calcBaggageFlightIF != null) ? timesOutbound[2] * (Decimal)calcBaggageFlightIF.Count : 0; h2h.OINJECT = (calcBaggageFlightIF != null) ? timesOutbound[1] * (Decimal)calcBaggageFlightIF.Count : 0; h2h.OTAXI = (calcBaggageFlightIF != null) ? timesOutbound[3] : 0; // Calculate ETL calcETL = Convert.ToDouble(h2h.OLOAD + h2h.OINJECT + h2h.OTAXI); calcETL = Math.Max(this.minLoadUnloadTime * 60 + Convert.ToDouble(h2h.OINJECT) + Convert.ToDouble(h2h.OTAXI), calcETL); calcETL = Math.Min(this.maxLoadUnloadTime * 60 + Convert.ToDouble(h2h.OINJECT) + Convert.ToDouble(h2h.OTAXI), calcETL); h2h.ETL = (h2h.HULLOPEN != null && h2h.HULLOPEN.Value.Year != 1900) ? h2h.HULLOPEN : (h2h.IATA != null && h2h.IATA.Value.Year != 1900) ? h2h.IATA : (h2h.IETA != null && h2h.IETA.Value.Year != 1900) ? h2h.IETA : null; if (h2h.ETL != null) { // Calc final ETL time calcETL = calcETL + this.processSorterProcessingTimes((DateTime)h2h.ETL) * 60; h2h.ETL = ((DateTime)h2h.ETL).AddSeconds(Math.Min(calcETU + calcETL, 2 * (double)this.maxBaggageTurnaround * 60)); h2h.ETLU = ((DateTime)h2h.ETL).AddSeconds(calcETU + calcETL); } } try { // Calculate Hub time h2h.HUB = (h2h.ETL != null && h2h.ETD != null && ((DateTime)h2h.ETL).Year > 1900 && ((DateTime)h2h.ETD).Year > 1900) ? (System.Nullable <int>)((TimeSpan)(h2h.ETD - h2h.ETL)).TotalMinutes : null; BagTMLog.LogDebug("BagTM Engine Update to ", h2h); dbinup.OSUSR_UUK_H2H.Attach(h2h); dbinup.Entry(h2h).State = EntityState.Modified; BagTMLog.LogInfo("BagTM Engine H2H Update: " + h2h.ID, this); } catch (DbEntityValidationException ex) { dbinup.OSUSR_UUK_H2H.Remove(h2h); // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new EngineProcessingException(exceptionMessage); } catch (Exception e) { dbinup.OSUSR_UUK_H2H.Remove(h2h); throw e; } } else { OSUSR_UUK_H2H newH2H = new OSUSR_UUK_H2H(); newH2H.IFLTNR = iFLTNR; newH2H.IORIGIN = iORIGIN; newH2H.IDATE = iDATE; newH2H.IETA = (flightInfoI != null) ? flightInfoI.ETA : null; newH2H.IATA = (flightInfoI != null) ? flightInfoI.ATA : null; newH2H.ISTAND = (flightInfoI != null) ? flightInfoI.TO_STAND : null; newH2H.HULLOPEN = (flightInfoI != null) ? flightInfoI.DOOROPEN : null; newH2H.IFLTINFOID = (flightInfoI != null && flightInfoI.ID != 0) ? (System.Nullable <int>)flightInfoI.ID : null; newH2H.ONTOFLIGHT = fFLTNR; newH2H.OFLTNR = fFLTNR; newH2H.ODATE = fDATE; newH2H.ETD = (flightInfoF != null) ? flightInfoF.ETD : null; newH2H.ATD = (flightInfoF != null) ? flightInfoF.ATD : null; newH2H.STANDD = (flightInfoF != null) ? flightInfoF.FROM_STAND : null; newH2H.HULLCLOSE = (flightInfoF != null) ? flightInfoF.DOORCLOSED : null; newH2H.OFLTINFOID = (flightInfoF != null && flightInfoF.ID != 0) ? (System.Nullable <int>)flightInfoF.ID : null; // To update inbound NRBAGS count for Hub messages if (newH2H.IFLTNR != null) { newH2H.INRBAGS = 1; newH2H.OLNRBAGS = 0; } else { newH2H.INRBAGS = 0; newH2H.OLNRBAGS = 1; } if (newH2H.OFLTNR == null) { newH2H.OLNRBAGS = 0; } System.Nullable <int> inboundFlightEquip = null; if (flightInfoI != null && flightInfoI.AC_REGISTRATION != null) { OSUSR_UUK_REGISTRATIONS reg = registrationList.Where(x => x.ACREGISTRATION == flightInfoI.AC_REGISTRATION) .FirstOrDefault <OSUSR_UUK_REGISTRATIONS>(); inboundFlightEquip = (reg != null) ? reg.EQUIPTYPEID : (System.Nullable <int>)Convert.ToInt32(this.defaultEquipment); } System.Nullable <int> outboundFlightEquip = null; if (flightInfoF != null && flightInfoF.AC_REGISTRATION != null) { OSUSR_UUK_REGISTRATIONS reg = registrationList.Where(x => x.ACREGISTRATION == flightInfoI.AC_REGISTRATION) .FirstOrDefault <OSUSR_UUK_REGISTRATIONS>(); outboundFlightEquip = (reg != null) ? reg.EQUIPTYPEID : (System.Nullable <int>)Convert.ToInt32(this.defaultEquipment); } Decimal[] timesInbound = this.CalculateTimes( (inboundFlightEquip != null) ? inboundFlightEquip : (System.Nullable <int>)Convert.ToInt32(this.defaultEquipment), (flightInfoI != null) ? flightInfoI.TO_STAND : this.defaultStandFrom, (flightInfoI != null) ? this.baggageTerminalCode : this.defaultGateTo); Decimal[] timesOutbound = this.CalculateTimes( (outboundFlightEquip != null) ? outboundFlightEquip : (System.Nullable <int>)Convert.ToInt32(this.defaultEquipment), (flightInfoF != null) ? this.baggageTerminalCode : this.defaultStandFrom, (flightInfoF != null) ? flightInfoF.FROM_GATE : this.defaultGateTo); Double calcETU = 0; Double calcETL = 0; // Calculate times and insert if flight exists if (newH2H.IFLTNR != null) { newH2H.IUNLOAD = timesInbound[0]; newH2H.IINJECT = timesInbound[1]; newH2H.ITAXI = timesInbound[3]; // Calculate ETU calcETU = Convert.ToDouble(newH2H.IUNLOAD + newH2H.IINJECT + newH2H.ITAXI); calcETU = Math.Max(this.minLoadUnloadTime * 60 + Convert.ToDouble(newH2H.IINJECT) + Convert.ToDouble(newH2H.ITAXI), calcETU); calcETU = Math.Min(this.maxLoadUnloadTime * 60 + Convert.ToDouble(newH2H.IINJECT) + Convert.ToDouble(newH2H.ITAXI), calcETU); newH2H.ETU = (newH2H.HULLOPEN != null && newH2H.HULLOPEN.Value.Year != 1900) ? newH2H.HULLOPEN : (newH2H.IATA != null && newH2H.IATA.Value.Year != 1900) ? newH2H.IATA : (newH2H.IETA != null && newH2H.IETA.Value.Year != 1900) ? newH2H.IETA : null; if (newH2H.ETU != null) { newH2H.ETU = ((DateTime)newH2H.ETU).AddSeconds(Math.Min(calcETU, (double)this.maxBaggageTurnaround * 60)); } } if (newH2H.OFLTNR != null) { newH2H.OLOAD = timesOutbound[2]; newH2H.OINJECT = timesOutbound[1]; newH2H.OTAXI = timesOutbound[3]; // Calculate ETL calcETL = Convert.ToDouble(newH2H.OLOAD + newH2H.OINJECT + newH2H.OTAXI); calcETL = Math.Max(this.minLoadUnloadTime * 60 + Convert.ToDouble(newH2H.OINJECT) + Convert.ToDouble(newH2H.OTAXI), calcETL); calcETL = Math.Min(this.maxLoadUnloadTime * 60 + Convert.ToDouble(newH2H.OINJECT) + Convert.ToDouble(newH2H.OTAXI), calcETL); newH2H.ETL = (newH2H.HULLOPEN != null && newH2H.HULLOPEN.Value.Year != 1900) ? newH2H.HULLOPEN : (newH2H.IATA != null && newH2H.IATA.Value.Year != 1900) ? newH2H.IATA : (newH2H.IETA != null && newH2H.IETA.Value.Year != 1900) ? newH2H.IETA : null; if (newH2H.ETL != null) { // Calc final ETL time calcETL = calcETL + this.processSorterProcessingTimes((DateTime)newH2H.ETL) * 60; newH2H.ETL = ((DateTime)newH2H.ETL).AddSeconds(Math.Min(calcETU + calcETL, 2 * (double)this.maxBaggageTurnaround * 60)); newH2H.ETLU = ((DateTime)newH2H.ETL).AddSeconds(calcETU + calcETL); } } try { // Calculate Hub time newH2H.HUB = (newH2H.ETL != null && newH2H.ETD != null && ((DateTime)newH2H.ETL).Year > 1900 && ((DateTime)newH2H.ETD).Year > 1900) ? (System.Nullable <int>)((TimeSpan)(newH2H.ETD - newH2H.ETL)).TotalMinutes : null; OSUSR_UUK_H2H h2hExist = this.SearchH2HInformation( newH2H.IFLTNR, newH2H.IDATE, newH2H.IORIGIN, newH2H.OFLTNR, newH2H.ODATE, ""); if (h2hExist != null && h2hExist.IFLTNR != null) { EngineUpdateH2H(flightInfoI, flightInfoF, isHub); BagTMLog.LogDebug("BagTM Engine Update H2H Already Exist", h2hExist); return; } dbinup.OSUSR_UUK_H2H.Add(newH2H); BagTMLog.LogInfo("BagTM Engine H2H Create: " + newH2H.ID, this); BagTMLog.LogDebug("BagTM Engine Update H2H Create", newH2H); } catch (DbEntityValidationException ex) { dbinup.OSUSR_UUK_H2H.Remove(newH2H); // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new EngineProcessingException(exceptionMessage); } catch (Exception e) { dbinup.OSUSR_UUK_H2H.Remove(newH2H); throw e; } } dbinup.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new EngineProcessingException(exceptionMessage); } BagTMLog.LogDebug("BagTM Engine Update H2H End", this); }
/// <summary> /// Update H2H table based on flight information /// </summary> public void EngineUpdatePTMH2H(OSUSR_UUK_FLT_INFO flightInfoI, DateTime stampPTM) { BagTMLog.LogDebug("BagTM Engine Update PTM H2H Start", this); int i = 0; BaggageEntities db = new BaggageEntities(); try { BagTMLog.LogDebug("BagTM Engine Update PTM H2H FlightInfoI", flightInfoI); BagTMLog.LogDebug("BagTM Engine Update PTM H2H Hub", hub); BagTMLog.LogDebug("BagTM Engine Update Search PTM H2H", this); String iFLTNR = (flightInfoI != null) ? CommonFunctions.FormatFlightNumber(flightInfoI.OPERATOR + flightInfoI.FLT_NR) : null; System.Nullable <DateTime> iDATE = (flightInfoI != null) ? flightInfoI.STD : null; String iORIGIN = (flightInfoI != null) ? flightInfoI.FROM_IATA : null; String iDEST = (flightInfoI != null) ? flightInfoI.TO_IATA : null; System.Nullable <DateTime> stamp = stampPTM; List <OSUSR_UUK_PTM_H2H> h2hList = this.SearchPTMH2HInformation( iFLTNR, iDATE, iORIGIN); List <OSUSR_UUK_PTMREFS2G> refStandGateTimes = this.SearchRefStandGateTimes(); List <OSUSR_UUK_PTM_REF_SEC_TIME> secTimes = this.SearchSecTimes(); BagTMLog.LogDebug("BagTM Engine Update PTM H2H List", h2hList); var ptmQuery = from s in db.OSUSR_UUK_PAXMSGS where s.TIMESTAMP == stamp select s; var ptmList = ptmQuery.Where(s => s.IFLTNR == iFLTNR && s.IDATE == ((DateTime)iDATE).Date && s.IORIGIN == iORIGIN && s.TIMESTAMP == stamp) .Select(x => new { x.IFLTNR, x.IDATE, x.IORIGIN, x.OFLTNR, x.ODATE, x.ODEST, x.RESERVATIONSTATUS }) .Distinct() .ToList(); BagTMLog.LogDebug("BagTM Engine Update Obtain PTM TTY list", ptmList); OSUSR_UUK_FLT_INFO flightInfoF; foreach (OSUSR_UUK_PTM_H2H h2h in h2hList) { flightInfoF = null; BagTMLog.LogDebug("BagTM Engine Update PTM H2H Flight Process", h2h); i++; var ptmListH2H = ptmList.Where(s => s.IFLTNR == h2h.IFLTNR && s.IDATE == h2h.IDATE && s.IORIGIN == h2h.IORIGIN && s.OFLTNR == h2h.OFLTNR && s.ODATE == h2h.ODATE && s.ODEST == h2h.ODEST && s.RESERVATIONSTATUS == h2h.STATUS) .ToList(); var h2hExists = ptmListH2H.FirstOrDefault(); BagTMLog.LogDebug("BagTM Engine Update Calculate PTMH2H PAX Count", ptmListH2H); var PAXCalculate = ptmQuery.Where(s => s.IFLTNR == h2h.IFLTNR && s.IDATE == h2h.IDATE && s.IORIGIN == h2h.IORIGIN && s.OFLTNR == h2h.OFLTNR && s.ODATE == h2h.ODATE && s.ODEST == h2h.ODEST && s.RESERVATIONSTATUS == h2h.STATUS) .GroupBy(x => new { x.IFLTNR, x.IDATE, x.IORIGIN, x.OFLTNR, x.ODATE, x.ODEST, x.RESERVATIONSTATUS }) .Select(x => new { IFLTNR = x.Key.IFLTNR, IDATE = x.Key.IDATE, IORIGIN = x.Key.IORIGIN, OFLTNR = x.Key.OFLTNR, ODATE = x.Key.ODATE, ODEST = x.Key.ODEST, RESERVATIONSTATUS = x.Key.RESERVATIONSTATUS, SumFIRST = x.Sum(z => z.FIRST), SumBUSINESS = x.Sum(z => z.BUSINESS), SumECONOMY = x.Sum(z => z.ECONOMY) } ).FirstOrDefault(); BagTMLog.LogDebug("BagTM Engine Update H2H Exist", PAXCalculate); if (h2h.OFLTNR != null && h2h.ODATE != null) { flightInfoF = this.SearchFlightInfo(h2h.OFLTNR, h2h.ODATE, hub, h2h.ODEST); } else { flightInfoF = new OSUSR_UUK_FLT_INFO(); } BagTMLog.LogDebug("BagTM Engine Search FlightInfoF", flightInfoF); if (PAXCalculate != null && PAXCalculate.IFLTNR != null) { // To update inbound NRBAGS count for Hub messages h2h.FIRST = PAXCalculate.SumFIRST; h2h.BUSINESS = PAXCalculate.SumBUSINESS; h2h.ECONOMY = PAXCalculate.SumECONOMY; h2h.ETA = (flightInfoI != null && flightInfoI.DOOROPEN != null && flightInfoI.DOOROPEN.Value.Year != 1900) ? flightInfoI.DOOROPEN : (flightInfoI != null && flightInfoI.ATA != null && flightInfoI.ATA.Value.Year != 1900) ? flightInfoI.ATA : (flightInfoI != null && flightInfoI.ETA != null && flightInfoI.ETA.Value.Year != 1900) ? flightInfoI.ETA : null; h2h.GATE = (flightInfoF != null && flightInfoF.FROM_GATE != null) ? flightInfoF.FROM_GATE : null; h2h.ETD = (flightInfoF != null && flightInfoF.DOORCLOSED != null && flightInfoF.DOORCLOSED.Value.Year != 1900) ? flightInfoF.DOORCLOSED : (flightInfoF != null && flightInfoF.ATD != null && flightInfoF.ATD.Value.Year != 1900) ? flightInfoF.ATD : (flightInfoF != null && flightInfoF.ETD != null && flightInfoF.ETD.Value.Year != 1900) ? flightInfoF.ETD : (flightInfoF != null && flightInfoF.STD != null && flightInfoF.STD.Value.Year != 1900) ? flightInfoF.STD : null; h2h.STAND = (flightInfoI != null && flightInfoI.TO_STAND != null) ? flightInfoI.TO_STAND : null; h2h.STATUS = PAXCalculate.RESERVATIONSTATUS; h2h.IFLTINFOID = (flightInfoI != null) ? (System.Nullable <int>)flightInfoI.ID : null; h2h.OFLTINFOID = (flightInfoF != null) ? (System.Nullable <int>)flightInfoF.ID : null; System.Nullable <DateTime> etg = null; if (flightInfoI != null) { if (flightInfoI.DOOROPEN != null) { etg = flightInfoI.DOOROPEN; } else if (flightInfoI.ATA != null) { etg = flightInfoI.ATA; } else if (flightInfoI.ETA != null) { etg = flightInfoI.ETA; } } // Obtain security times from table OSUSR_UUK_PTMREFS2G refStandGateTime = refStandGateTimes.Where( s => s.GATE == h2h.GATE && s.STAND == h2h.STAND).FirstOrDefault(); int standGateMinutes = (refStandGateTime != null && refStandGateTime.MINUTES != null) ? (int)refStandGateTime.MINUTES / 2 : 0; if (refStandGateTime != null && SEC_Y.Equals(refStandGateTime.SEC)) { OSUSR_UUK_PTM_REF_SEC_TIME secTime = secTimes.Where( s => s.WEEK == ((DateTime)h2h.IDATE).DayOfWeek.ToString() && s.FROM_TIME > ((DateTime)etg).AddMinutes(standGateMinutes)) .FirstOrDefault(); h2h.SEC = (secTime != null && secTime.TIME != null) ? standGateMinutes + (int)secTime.TIME : standGateMinutes; } else { h2h.SEC = standGateMinutes; } if (h2h.ETD != null) { h2h.ETCG = h2h.ETD; h2h.ETCG.Value.AddMinutes(-1 * etcg); } h2h.ETG = h2h.ETA; h2h.ETG = (h2h.ETG != null) ? (System.Nullable <DateTime>)((DateTime)h2h.ETG).AddMinutes( Math.Min((h2h.SEC != null) ? (int)h2h.SEC : 0, this.maxPaxTurnaround)) : null; h2h.HUB = (h2h.ETD != null && h2h.ETG != null) ? (System.Nullable <int>)((TimeSpan)(h2h.ETD - h2h.ETG)).TotalMinutes : null; BagTMLog.LogInfo("BagTM Engine H2H Update: " + h2h.ID, this); } else { // To update inbound NRBAGS count for Hub messages h2h.FIRST = 0; h2h.BUSINESS = 0; h2h.ECONOMY = 0; h2h.ETA = (flightInfoI != null && flightInfoI.ETA != null) ? flightInfoI.ETA : null; h2h.GATE = (flightInfoF != null && flightInfoF.FROM_GATE != null) ? flightInfoF.FROM_GATE : null; h2h.ETD = (flightInfoF != null && flightInfoF.ETD != null) ? flightInfoF.ETD : null; h2h.STAND = (flightInfoI != null && flightInfoI.TO_STAND != null) ? flightInfoI.TO_STAND : null; h2h.STATUS = null; h2h.SEC = 0; h2h.ETG = null; h2h.ETCG = null; h2h.HUB = null; } db.OSUSR_UUK_PTM_H2H.Attach(h2h); db.Entry(h2h).State = EntityState.Modified; BagTMLog.LogInfo("BagTM Engine PTM H2H Update: " + h2h.ID, this); ptmList.Remove(h2hExists); } OSUSR_UUK_PTM_H2H newH2H = null; foreach (var ptmNotIn in ptmList) { flightInfoF = null; // Verify if passengers in connection with a FI flight if (ptmNotIn.OFLTNR != null && !ptmNotIn.OFLTNR.StartsWith(this.airline)) { continue; } newH2H = new OSUSR_UUK_PTM_H2H(); var PAXCalculate = ptmQuery.Where(s => s.IFLTNR == ptmNotIn.IFLTNR && s.IDATE == ptmNotIn.IDATE && s.IORIGIN == ptmNotIn.IORIGIN && s.OFLTNR == ptmNotIn.OFLTNR && s.ODATE == ptmNotIn.ODATE && s.ODEST == ptmNotIn.ODEST && s.RESERVATIONSTATUS == ptmNotIn.RESERVATIONSTATUS) .GroupBy(x => new { x.IFLTNR, x.IDATE, x.IORIGIN, x.OFLTNR, x.ODATE, x.ODEST, x.RESERVATIONSTATUS }) .Select(x => new { IFLTNR = x.Key.IFLTNR, IDATE = x.Key.IDATE, IORIGIN = x.Key.IORIGIN, OFLTNR = x.Key.OFLTNR, ODATE = x.Key.ODATE, ODEST = x.Key.ODEST, RESERVATIONSTATUS = x.Key.RESERVATIONSTATUS, SumFIRST = x.Sum(z => z.FIRST), SumBUSINESS = x.Sum(z => z.BUSINESS), SumECONOMY = x.Sum(z => z.ECONOMY) } ).FirstOrDefault(); BagTMLog.LogDebug("BagTM Engine Update H2H Don't Exist", PAXCalculate); if (PAXCalculate != null && PAXCalculate.IFLTNR != null) { // To update inbound NRBAGS count for Hub messages newH2H.FIRST = PAXCalculate.SumFIRST; newH2H.BUSINESS = PAXCalculate.SumBUSINESS; newH2H.ECONOMY = PAXCalculate.SumECONOMY; } else { newH2H.FIRST = 0; newH2H.BUSINESS = 0; newH2H.ECONOMY = 0; } if (ptmNotIn.OFLTNR != null && ptmNotIn.ODATE != null) { flightInfoF = this.SearchFlightInfo(ptmNotIn.OFLTNR, ptmNotIn.ODATE, hub, ptmNotIn.ODEST); } else { flightInfoF = new OSUSR_UUK_FLT_INFO(); } BagTMLog.LogDebug("BagTM Engine Search FlightInfoF", flightInfoF); newH2H.IFLTNR = ptmNotIn.IFLTNR; newH2H.IDATE = ptmNotIn.IDATE; newH2H.IORIGIN = ptmNotIn.IORIGIN; newH2H.OFLTNR = ptmNotIn.OFLTNR; newH2H.ODATE = ptmNotIn.ODATE; newH2H.ODEST = ptmNotIn.ODEST; newH2H.ETA = (flightInfoI != null && flightInfoI.DOOROPEN != null && flightInfoI.DOOROPEN.Value.Year != 1900) ? flightInfoI.DOOROPEN : (flightInfoI != null && flightInfoI.ATA != null && flightInfoI.ATA.Value.Year != 1900) ? flightInfoI.ATA : (flightInfoI != null && flightInfoI.ETA != null && flightInfoI.ETA.Value.Year != 1900) ? flightInfoI.ETA : null; newH2H.GATE = (flightInfoF != null && flightInfoF.FROM_GATE != null) ? flightInfoF.FROM_GATE : null; newH2H.ETD = (flightInfoF != null && flightInfoF.DOORCLOSED != null && flightInfoF.DOORCLOSED.Value.Year != 1900) ? flightInfoF.DOORCLOSED : (flightInfoF != null && flightInfoF.ATD != null && flightInfoF.ATD.Value.Year != 1900) ? flightInfoF.ATD : (flightInfoF != null && flightInfoF.ETD != null && flightInfoF.ETD.Value.Year != 1900) ? flightInfoF.ETD : (flightInfoF != null && flightInfoF.STD != null && flightInfoF.STD.Value.Year != 1900) ? flightInfoF.STD : null; newH2H.STAND = (flightInfoI != null && flightInfoI.TO_STAND != null) ? flightInfoI.TO_STAND : null; newH2H.STATUS = ptmNotIn.RESERVATIONSTATUS; newH2H.IFLTINFOID = (flightInfoI != null) ? (System.Nullable <int>)flightInfoI.ID : null; newH2H.OFLTINFOID = (flightInfoF != null) ? (System.Nullable <int>)flightInfoF.ID : null; System.Nullable <DateTime> etcg = null; if (flightInfoI != null) { if (flightInfoI.DOOROPEN != null && flightInfoI.DOOROPEN.Value.Year != 1900) { etcg = flightInfoI.DOOROPEN; } else if (flightInfoI.ATA != null && flightInfoI.ATA.Value.Year != 1900) { etcg = flightInfoI.ATA; } else if (flightInfoI.ETA != null && flightInfoI.ETA.Value.Year != 1900) { etcg = flightInfoI.ETA; } } // Obtain security times from table OSUSR_UUK_PTMREFS2G refStandGateTime = refStandGateTimes.Where( s => s.GATE == newH2H.GATE && s.STAND == newH2H.STAND).FirstOrDefault(); int standGateMinutes = (refStandGateTime != null && refStandGateTime.MINUTES != null) ? (int)refStandGateTime.MINUTES / 2 : 0; if (refStandGateTime != null && SEC_Y.Equals(refStandGateTime.SEC)) { OSUSR_UUK_PTM_REF_SEC_TIME secTime = secTimes.Where( s => s.WEEK == ((DateTime)newH2H.IDATE).DayOfWeek.ToString() && s.FROM_TIME > ((DateTime)flightInfoF.ETA).AddMinutes(standGateMinutes)).FirstOrDefault(); newH2H.SEC = (secTime != null && secTime.TIME != null) ? standGateMinutes + (int)secTime.TIME : standGateMinutes; } else { newH2H.SEC = standGateMinutes; } newH2H.ETG = newH2H.ETA; newH2H.ETG = (newH2H.ETG != null) ? (System.Nullable <DateTime>)((DateTime)newH2H.ETG).AddMinutes( Math.Min((newH2H.SEC != null) ? (int)newH2H.SEC : 0, this.maxPaxTurnaround)) : null; newH2H.HUB = (newH2H.ETD != null && newH2H.ETG != null) ? (System.Nullable <int>)((TimeSpan)(newH2H.ETD - newH2H.ETG)).TotalMinutes : null; try { db.OSUSR_UUK_PTM_H2H.Add(newH2H); BagTMLog.LogInfo("BagTM Engine PTM H2H Create: " + newH2H.ID, this); } catch (DbEntityValidationException ex) { db.OSUSR_UUK_PTM_H2H.Remove(newH2H); // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new EngineProcessingException(exceptionMessage); } } try { db.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new EngineProcessingException(exceptionMessage); } } catch (Exception e) { BagTMLog.LogError("BagTM Engine Error updating PTM H2H Table", this, e); throw e; } BagTMLog.LogDebug("BagTM Engine Update PTM H2H End", this); }
/// <summary> /// Process engine rules /// </summary> /// <param name="messageObject"></param> /// <param name="n"></param> public void ProcessBaggageTTYEngine(Object messageObject, int n) { BagTMLog.LogDebug("BagTM Engine Baggage TTY", this); // Only process message if is a baggage message if (messageObject.GetType() != typeof(OSUSR_UUK_BAGMSGS)) { throw new EngineProcessingException("Not a baggage message."); } OSUSR_UUK_BAGMSGS bag = (OSUSR_UUK_BAGMSGS)messageObject; int nrtag = 0; try { nrtag = Convert.ToInt32(bag.NNRTAGS); } catch (Exception e) { BagTMLog.LogError("Bag NNRTAG is not an number.", bag, e); } if (nrtag > 1) { for (int i = 0; i < nrtag; i++) { var inst = bag.GetType().GetMethod("MemberwiseClone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); OSUSR_UUK_BAGMSGS bagClone = (OSUSR_UUK_BAGMSGS)inst.Invoke(bag, null); bagClone.NNRTAGS = "001"; bagClone.NBAGTAG = (Convert.ToDecimal(bagClone.NBAGTAG) + i).ToString("0000000000"); ProcessBaggageTTYEngine(bagClone, n); } } BagTMLog.LogDebug("BagTM Engine Search BaggageIntegraty", bag); // Obtain baggage from Baggage Integraty table OSUSR_UUK_BAGINTEG bagIntegraty = this.SearchBaggageIntegratyByBagIdentifier(bag.NBAGTAG + bag.NNRTAGS); if (bagIntegraty == null) { bagIntegraty = new OSUSR_UUK_BAGINTEG(); } BagTMLog.LogDebug("BagTM Engine Search BaggageIntegraty Found ", bagIntegraty); BagTMLog.LogDebug("BagTM Engine Search FlightInfoI and FlightInfoF", this); OSUSR_UUK_FLT_INFO flightInfoI = null; OSUSR_UUK_FLT_INFO flightInfoF = null; bool isHub = false; bool isLocalTTYforHub = false; bool isLocalEndingInHub = false; if ((BagTMRulesActions.hubBagParameter.Equals(bag.VBAGSOURCIND) && this.hub.Equals(bag.VCITY)) || (BagTMRulesActions.localBagParameter.Equals(bag.VBAGSOURCIND) && this.hub.Equals(bag.FDEST))) { isHub = true; } if (isHub && BagTMRulesActions.localBagParameter.Equals(bag.VBAGSOURCIND)) { isLocalTTYforHub = true; } if (isHub && isLocalTTYforHub && (bag.OFLTNR == null || !bag.OFLTNR.StartsWith(this.airline))) { isLocalEndingInHub = true; } if (isHub && !isLocalTTYforHub && bag.IFLTNR != null) { isLocalEndingInHub = true; } // Obtain list of message from Baggage table if (isHub) { if (!isLocalEndingInHub) { if (bag.FFLTNR != null && bag.FDATE != null && bag.FFLTNR.StartsWith(this.airline)) { flightInfoI = this.SearchFlightInfo(bag.FFLTNR, bag.FDATE, bag.VCITY, bag.FDEST); } else { flightInfoI = new OSUSR_UUK_FLT_INFO(); } if (bag.OFLTNR != null && bag.ODATE != null && bag.OFLTNR.StartsWith(this.airline)) { flightInfoF = this.SearchFlightInfo(bag.OFLTNR, bag.ODATE, hub, bag.ODEST); } else { flightInfoF = new OSUSR_UUK_FLT_INFO(); } } else { if (bag.IFLTNR != null && bag.IDATE != null && bag.IFLTNR.StartsWith(this.airline)) { flightInfoI = this.SearchFlightInfo(bag.IFLTNR, bag.IDATE, bag.IORIGIN, bag.VCITY); } else { flightInfoI = new OSUSR_UUK_FLT_INFO(); } if (bag.FFLTNR != null && bag.FDATE != null && bag.FFLTNR.StartsWith(this.airline)) { flightInfoF = this.SearchFlightInfo(bag.FFLTNR, bag.FDATE, bag.VCITY, bag.FDEST); } else { flightInfoF = new OSUSR_UUK_FLT_INFO(); } } } else { if (bag.FFLTNR != null && bag.FDATE != null && bag.FFLTNR.StartsWith(this.airline)) { flightInfoF = this.SearchFlightInfo(bag.FFLTNR, bag.FDATE, bag.VCITY, bag.FDEST); } else { flightInfoF = new OSUSR_UUK_FLT_INFO(); } flightInfoI = new OSUSR_UUK_FLT_INFO(); } BagTMLog.LogDebug("BagTM Engine Search FlightInfoI", flightInfoI); BagTMLog.LogDebug("BagTM Engine Search FlightInfoF", flightInfoF); BagTMLog.LogDebug("BagTM Engine Rules Execution", this); // Run engine process rules this.EngineRulesExecution(bag, bagIntegraty, flightInfoI, flightInfoF, hub, factory); // Verify if is a baggage board if (BagTMRulesActions.PAX_BOARDED_STATUS.Equals(bag.SPAXCK)) { BagTMLog.LogDebug("BagTM Engine Boaded Pax", this); this.ProcessBoardBaggageTTY(bag, bagIntegraty, flightInfoI, flightInfoF, hub, factory); } if (flightInfoF == null || flightInfoF.FLT_NR == null || flightInfoI == null) { BagTMLog.LogDebug("No update to H2H since no flight information, please check flight in FLT_INFO table.", this); } else { // Reprocess Hull 2 Hull table for selected flight if (isHub || (hub.Equals(bag.VCITY) && BagTMRulesActions.localBagParameter.Equals(bag.VBAGSOURCIND))) { this.h2hProcessing.EngineUpdateH2H(flightInfoI, flightInfoF, isHub); } } BagTMLog.LogDebug("BagTM Engine Baggage TTY End", this); }
/// <summary> /// Load and execute engine rules /// </summary> public void EngineRulesExecution(OSUSR_UUK_BAGMSGS bag, OSUSR_UUK_BAGINTEG bagIntegraty, OSUSR_UUK_FLT_INFO flightInfoI, OSUSR_UUK_FLT_INFO flightInfoF, String hub, ISessionFactory factory) { BagTMLog.LogDebug("BagTM Engine Rules Execution Start", this); ISession session = factory.CreateSession(); try { bagIntegraty.IATD = (flightInfoI != null && flightInfoI.ATD != null) ? flightInfoI.ATD : (flightInfoI != null && flightInfoI.ETD != null) ? flightInfoI.ETD : (flightInfoI != null && flightInfoI.STD != null) ? flightInfoI.STD : null; bagIntegraty.FATD = (flightInfoF != null && flightInfoF.ATD != null) ? flightInfoF.ATD : (flightInfoF != null && flightInfoF.ETD != null) ? flightInfoF.ETD : (flightInfoF != null && flightInfoF.STD != null) ? flightInfoF.STD : null; session.Insert(hub); //Insert facts into rules engine's memory session.Insert(bag); session.Insert(bagIntegraty); //Start match/resolve/act cycle session.Fire(); } catch (Exception e) { BagTMLog.LogError("BagTM Engine Error Processing Rules", this, e); throw e; } BagTMLog.LogDebug("BagTM Engine Rules Execution Ending", this); }
/// <summary> /// Load and execute engine rules /// </summary> public void ProcessBoardBaggageTTY(OSUSR_UUK_BAGMSGS bag, OSUSR_UUK_BAGINTEG bagIntegraty, OSUSR_UUK_FLT_INFO flightInfoI, OSUSR_UUK_FLT_INFO flightInfoF, String hub, ISessionFactory factory) { BagTMLog.LogDebug("BagTM Engine Process Board Baggage Start", this); try { List <OSUSR_UUK_BAGMSGS> listOfBagBoarded = this.SearchBaggageMsgsByFlightandSeatNumber(bag); foreach (OSUSR_UUK_BAGMSGS boardBag in listOfBagBoarded) { OSUSR_UUK_BAGINTEG boardBagInteg = this.SearchBaggageIntegratyByBagIdentifier(boardBag.NBAGTAG + boardBag.NNRTAGS); if (boardBagInteg == null) { boardBagInteg = new OSUSR_UUK_BAGINTEG(); } var inst = bag.GetType().GetMethod("MemberwiseClone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); OSUSR_UUK_BAGMSGS bagClone = (OSUSR_UUK_BAGMSGS)inst.Invoke(bag, null); bagClone.NNRTAGS = boardBag.NNRTAGS; bagClone.NBAGTAG = boardBag.NBAGTAG; BagTMLog.LogDebug("BagTM Board Baggage Engine Rules Execution", this); // Run engine process rules this.EngineRulesExecution(bagClone, boardBagInteg, flightInfoI, flightInfoF, hub, factory); } } catch (Exception e) { BagTMLog.LogError("BagTM Engine Error Process Board Baggage", this, e); throw e; } BagTMLog.LogDebug("BagTM Engine Process Board Baggage Ending", this); }
/// <summary> /// Process engine rules /// </summary> /// <param name="messageObject"></param> /// <param name="n"></param> public void ProcessFLTINFOEngine(Object messageObject, int n) { BagTMLog.LogDebug("BagTM Engine FLT INFO", this); // Only process message if is a baggage message if (messageObject.GetType() != typeof(OSUSR_UUK_FLT_INFO)) { throw new EngineProcessingException("Not a FLTINFO message."); } OSUSR_UUK_FLT_INFO info = (OSUSR_UUK_FLT_INFO)messageObject; OSUSR_UUK_FLT_INFO flightInfoF = null; OSUSR_UUK_FLT_INFO flightInfoI = null; bool isHub = false; BaggageEntities db = new BaggageEntities(); var h2hQuery = from s in db.OSUSR_UUK_H2H select s; var h2hList = h2hQuery.Where(s => s.IFLTINFOID == info.ID || s.OFLTINFOID == info.ID) .OrderByDescending(x => x.ID) .ToList <OSUSR_UUK_H2H>(); foreach (OSUSR_UUK_H2H h2h in h2hList) { flightInfoF = this.SearchFlightInfoByPK((h2h.OFLTINFOID != null) ? (int)h2h.OFLTINFOID : 0); flightInfoI = this.SearchFlightInfoByPK((h2h.IFLTINFOID != null) ? (int)h2h.IFLTINFOID : 0); flightInfoI = (flightInfoI != null) ? flightInfoI : new OSUSR_UUK_FLT_INFO(); isHub = (flightInfoI != null && flightInfoI.FLT_NR != null) ? true : false; BagTMLog.LogDebug("BagTM Engine Search FlightInfoI", flightInfoI); BagTMLog.LogDebug("BagTM Engine Search FlightInfoF", flightInfoF); BagTMLog.LogDebug("BagTM Engine Rules H2H", this); if (flightInfoF == null || flightInfoF.FLT_NR == null || flightInfoI == null) { BagTMLog.LogDebug("No update to H2H since no flight information, please check flight in FLT_INFO table.", this); } else { this.h2hProcessing.EngineUpdateH2H(flightInfoI, flightInfoF, isHub); } } var ptmH2HQuery = from s in db.OSUSR_UUK_PTM_H2H select s; var ptmH2HList = ptmH2HQuery.Where(s => s.IFLTINFOID == info.ID || s.OFLTINFOID == info.ID) .OrderByDescending(x => x.ID) .ToList <OSUSR_UUK_PTM_H2H>(); foreach (OSUSR_UUK_PTM_H2H ptmH2H in ptmH2HList) { flightInfoF = this.SearchFlightInfoByPK((ptmH2H.OFLTINFOID != null) ? (int)ptmH2H.OFLTINFOID : 0); flightInfoI = this.SearchFlightInfoByPK((ptmH2H.IFLTINFOID != null) ? (int)ptmH2H.IFLTINFOID : 0); flightInfoI = (flightInfoI != null) ? flightInfoI : new OSUSR_UUK_FLT_INFO(); isHub = (flightInfoI != null && flightInfoI.FLT_NR != null) ? true : false; BagTMLog.LogDebug("BagTM Engine Search FlightInfoI", flightInfoI); BagTMLog.LogDebug("BagTM Engine Search FlightInfoF", flightInfoF); BagTMLog.LogDebug("BagTM Engine Rules H2H", this); if (flightInfoF == null || flightInfoF.FLT_NR == null || flightInfoI == null) { BagTMLog.LogDebug("No update to H2H since no flight information, please check flight in FLT_INFO table.", this); } else { this.ptmH2HProcessing.EngineUpdatePTMH2H(flightInfoI, (DateTime)this.ptmH2HProcessing.SearchLastPTMForFlight(ptmH2H)); } } BagTMLog.LogDebug("BagTM Engine FLT INFO End", this); }