Exemple #1
0
        /// <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);
        }
        static void Main(string[] args)
        {
            try
            {
                BagTMLog.LogDebug("BagTM Command Line Start", args);

                BagTMLog.LogDebug("BagTM Queue Processing Debug Starting", null);

                IExecutionQueueProcessing queueProcess = new ExecutionDataflowQueueProcessing();

                queueProcess.QueueProcessingDebug();

                BagTMLog.LogDebug("BagTM Queue Processing Debug Ended", null);

                BagTMLog.LogDebug("BagTM Engine Processing Debug Starting", null);

                IExecutionEngineProcessing engineProcess = new ExecutionDataflowEngineProcessing();

                engineProcess.EngineProcessingDebug();

                BagTMLog.LogDebug("BagTM Command Line Debug Ends", null);

                BagTMLog.LogDebug("BagTM Command Line Ending", null);
            }
            catch (ConfigurationErrorsException cee)
            {
                BagTMLog.LogError("BagTM Command Line Ends", args, cee);
            }
        }
        /// <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);
        }
Exemple #4
0
        /// <summary>
        /// Create all message queue for processes
        /// </summary>
        /// <param name="queueType"></param>
        /// <returns></returns>
        private MessageQueue CreateMessageQueue(int queueType)
        {
            switch (queueType)
            {
            case QUEUESUCESS:     //Sucess
                queueInSucess = new MessageQueue(this.GetAppSetting(config, "queueInSucessName") + isDebug);
                BagTMLog.LogDebug("BagTM Queue Processing QueueInSucess", queueInSucess);
                return(queueInSucess);

            case QUEUEERROR:     //Error
                queueInError = new MessageQueue(this.GetAppSetting(config, "queueInErrorName") + isDebug);
                BagTMLog.LogDebug("BagTM Queue Processing QueueInError", queueInError);
                return(queueInError);

            case QUEUEENGINE:     //Engine
                queueEngine = new MessageQueue(this.GetAppSetting(config, "queueEngineName") + isDebug);
                ((XmlMessageFormatter)queueEngine.Formatter).TargetTypes = new Type[2] {
                    typeof(BagTMDBLibrary.OSUSR_UUK_BAGMSGS), typeof(BagTMDBLibrary.OSUSR_UUK_PAXMSGS)
                };
                BagTMLog.LogDebug("BagTM Queue Processing QueueEngine", queueEngine);
                return(queueEngine);

            case QUEUEIN:     //In
                queueIn           = new MessageQueue(this.GetAppSetting(config, "queueInName") + isDebug);
                queueIn.Formatter = messageFormater;
                BagTMLog.LogDebug("BagTM Queue Processing QueueIn", queueIn);
                return(queueIn);

            default:
                throw new QueueProcessingException("Send Message to unkown queue");
            }
        }
        /// <summary>
        /// Task creation for engine processing events
        /// </summary>
        public void EngineProcessing()
        {
            BagTMLog.LogDebug(
                String.Format("BagTM Engine Processing Queue Process Start "), this);

            if (this.isProcessing)
            {
                BagTMLog.LogDebug(
                    String.Format("BagTM Engine Processing Queue Process Is Processing"), this);
                return;
            }

            BagTMLog.LogDebug(
                String.Format("BagTM Engine Processing Task Process Message Define Dataflow Block Number of Messages {0}", parallelismCounter)
                , this);

            Action <int> engineProcess = n =>
            {
                BagTMLog.LogDebug(
                    String.Format("BagTM Engine Processing Task Process Message {0}", n), this);

                EngineProcess(n);
                EngineErrorReprocess(n);
            };

            var opts = new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = parallelismCounter
            };

            var actionBlock = new ActionBlock <int>(engineProcess, opts);

            this.isProcessing = true;

            try
            {
                for (int i = actionBlock.InputCount; i < parallelismCounter; i++)
                {
                    actionBlock.Post(i);
                }

                actionBlock.Complete();
                actionBlock.Completion.Wait();

                this.isProcessing = false;
            }
            catch (Exception e)
            {
                this.isProcessing = false;
                throw e;
            }
            finally
            {
                this.isProcessing = false;
            }

            BagTMLog.LogDebug(
                String.Format("BagTM Engine Processing Queue Process End "), this);
        }
Exemple #6
0
        public BaggageMessageParsing(TTYCollection ttyCollection)
        {
            BagTMLog.LogDebug("BagTM Queue Message Parsing Constructor", this);

            this.ttyCollection = ttyCollection;

            BagTMLog.LogDebug("BagTM Queue Message Parsing Constructor Ending", this);
        }
Exemple #7
0
        public PTMMessageParsing(TTYCollection ttyCollection, String hub)
        {
            BagTMLog.LogDebug("BagTM Queue Message Parsing Constructor", this);

            this.ttyCollection = ttyCollection;
            this.hub = hub;
            BagTMLog.LogDebug("BagTM Queue Message Parsing Constructor Ending", this);

        }
        /// <summary>
        /// Engine processing for debug
        /// </summary>
        public void EngineProcess(int n)
        {
            BagTMLog.LogDebug(
                String.Format("BagTM Engine Debug Processing Queue Process Start"), this);

            object[] messages = null;
            try
            {
                this.RefreshRefLists();

                messages = this.ReadQueue(n, QUEUEENGINE);

                if (messages == null)
                {
                    return;
                }

                if (messages[0].GetType().Equals(typeof(OSUSR_UUK_BAGMSGS)))
                {
                    this.bagIntergityProcessing.ProcessBaggageTTYEngine(messages[0], n);
                    Message messageSucess = new Message(messages[0]);
                    messageSucess.Label = "Bag Msgs: " + ((OSUSR_UUK_BAGMSGS)messages[0]).ID;
                    this.SendMessage(messageSucess, n, QUEUESUCESS);
                }
                else if (messages[0].GetType().Equals(typeof(OSUSR_UUK_PAXMSGS)))
                {
                    this.ptmH2HProcessing.ProcessPTMTTYEngine(messages[0], n);
                    Message messageSucess = new Message(messages[0]);
                    messageSucess.Label = "Pax Msgs: " + ((OSUSR_UUK_PAXMSGS)messages[0]).ID;
                    this.SendMessage(messageSucess, n, QUEUESUCESS);
                }
                else if (messages[0].GetType().Equals(typeof(OSUSR_UUK_FLT_INFO)))
                {
                    this.fltInfoProcessing.ProcessFLTINFOEngine(messages[0], n);
                    Message messageSucess = new Message(messages[0]);
                    messageSucess.Label = "Flt Msgs: " + ((OSUSR_UUK_FLT_INFO)messages[0]).ID;
                    this.SendMessage(messageSucess, n, QUEUESUCESS);
                }
                else
                {
                    BagTMLog.LogDebug(
                        String.Format("BagTM Engine Processing Task Process Message read task {0} with message {1} no engine to process message", n, messages[0].GetType()), this);
                    ((Message)messages[1]).Label = String.Format("BagTM Engine Processing Task Process Message read task {0} with message {1} no engine to process message", n, messages[0].GetType()).Substring(0, 120);
                    this.SendMessage(messages[1], n, QUEUEERROR);
                }
            }
            catch (Exception e)
            {
                String message = BagTMLog.LogError(
                    String.Format("BagTM Engine Processing Task {0} Message", n), this, e);
                if (messages != null && messages[0] != null)
                {
                    ((Message)messages[1]).Label = message.Substring(0, 120);
                    this.SendMessage(messages[1], n, QUEUEERROR);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Constructor to create logger and tasks and queue parametrization
        /// </summary>
        public ExecutionDataflowQueueProcessing()
        {
            BagTMLog.LogDebug("BagTM Queue Processing Constructor", this);

            //Get the application configuration file.
            config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None) as Configuration;

            this.hub = this.GetAppSetting(config, "hub");

            String timeSpanParameter = this.GetAppSetting(config, "timeSpan");
            int    timeSpanNumber    = 0;

            if (!int.TryParse(timeSpanParameter, out timeSpanNumber))
            {
                throw new QueueProcessingException("Parameter TimeSpan incorrectly configured");
            }

            this.timeSpan = new TimeSpan((Int64)(timeSpanNumber * TimeSpan.TicksPerSecond));

            BagTMLog.LogDebug("BagTM Queue Processing Timespan " + timeSpanParameter, timeSpan);

            String parallelismCounterParameter = this.GetAppSetting(config, "parallelismCounter");

            if (!int.TryParse(parallelismCounterParameter, out this.parallelismCounter))
            {
                throw new QueueProcessingException("Parameter ParallelismCounter incorrectly configured");
            }

            BagTMLog.LogDebug("BagTM Queue Processing ParallelismCounter " + parallelismCounter, parallelismCounter);

            TTYMessagesSection ttyMsg = ConfigurationManager.GetSection("TTYMessagesSection") as TTYMessagesSection;

            BagTMLog.LogDebug(String.Format("BagTM Queue Processing TTY Parser Collection {0} {1}",
                                            ttyMsg.ttyCollection.GetNumberOfItems(),
                                            ttyMsg.ttyCollection.Describe())
                              , this);

            try
            {
                this.messageFormater = new TTYMessageFormatter(ttyMsg.ttyCollection, new BaggageEntities(), hub);

                BagTMLog.LogDebug("BagTM Queue Processing MessageFormater", messageFormater);

                queueIn       = this.CreateMessageQueue(QUEUEIN);
                queueInSucess = this.CreateMessageQueue(QUEUESUCESS);
                queueInError  = this.CreateMessageQueue(QUEUEERROR);
                queueEngine   = this.CreateMessageQueue(QUEUEENGINE);
                BagTMLog.LogDebug("BagTM Queue Processing QueueEngine", queueEngine);
                BagTMLog.LogDebug("BagTM Queue Processing Constructor Ending", this);
            }
            catch (Exception e)
            {
                BagTMLog.LogError("BagTM Queue Processing Constructor Error ", this, e);
            }
        }
        /// <summary>
        /// Engine processing for debug
        /// </summary>
        public void EngineErrorReprocessAll(int n)
        {
            BagTMLog.LogDebug(
                String.Format("BagTM Engine Debug Reprocessing All Queue Process Start"), this);

            EngineErrorReprocess(n);

            BagTMLog.LogDebug(
                String.Format("BagTM Engine Debug Reprocessing All Queue Process End"), this);
        }
Exemple #11
0
        protected object[] ReadQueue(int n)
        {
            object message = null;

            object[] messages = new object[2];

            BagTMLog.LogDebug(
                String.Format("BagTM Queue Read Task Message Start {0}", n), this);
            Message msg = null;

            try
            {
                if (queueIn.Peek() != null)
                {
                    msg         = queueIn.Receive();
                    messages[1] = msg;

                    if (msg != null)
                    {
                        BagTMLog.LogDebug(
                            String.Format("BagTM Queue Read Task {0} for Message Body Type: {1}", n, msg.BodyType), this);

                        message     = (object)msg.Body;
                        messages[0] = message;

                        BagTMLog.LogInfo(
                            String.Format("BagTM Queue Message Parsed {0}", message), this);

                        BagTMLog.LogDebug(
                            String.Format("BagTM Queue Read Task {0} with Message {1}", n, msg.Id), this);
                    }
                }
            }
            catch (Exception e)
            {
                String messageError = BagTMLog.LogError(
                    String.Format("BagTM Queue Read Task {0} with Error", n), this, e);

                if (msg != null)
                {
                    msg.Label = messageError.Substring(0, 120);
                    this.SendMessage(msg, n, QUEUEERROR);
                }
                throw e;
            }

            BagTMLog.LogDebug(
                String.Format("BagTM Queue Read Task Message End {0}", n), this);


            return(messages);
        }
Exemple #12
0
        public void QueueProcess(int n)
        {
            BagTMLog.LogDebug(
                String.Format("BagTM Queue Debug Processing Queue Process Start"), this);

            object[] messages = null;
            try
            {
                messages = this.ReadQueue(n);
                Message messageEngine = new Message(messages[0]);
                if (messages[0].GetType().Equals(typeof(OSUSR_UUK_BAGMSGS)))
                {
                    messageEngine.Label = "Bag Msgs: " + ((OSUSR_UUK_BAGMSGS)messages[0]).ID;
                }
                else if (messages[0].GetType().Equals(typeof(OSUSR_UUK_PAXMSGS)))
                {
                    messageEngine.Label = "Pax Msgs: " + ((OSUSR_UUK_PAXMSGS)messages[0]).ID;
                }
                this.SendMessage(messageEngine, n, QUEUEENGINE);
                Message messageSucess = (Message)messages[1];
                if (messages[0].GetType().Equals(typeof(OSUSR_UUK_BAGMSGS)))
                {
                    messageSucess.Label = "Bag Msgs: " + ((OSUSR_UUK_BAGMSGS)messages[0]).ID;
                }
                else if (messages[0].GetType().Equals(typeof(OSUSR_UUK_PAXMSGS)))
                {
                    messageSucess.Label = "Pax Msgs: " + ((OSUSR_UUK_PAXMSGS)messages[0]).ID;
                }
                this.SendMessage(messageSucess, n, QUEUESUCESS);
            }
            catch (Exception e)
            {
                String message = BagTMLog.LogError(
                    String.Format("BagTM Queue Processing Error with no TTY message", n), this, e);
                if (messages != null && messages[0] != null)
                {
                    ((Message)messages[1]).Label = message.Substring(0, 120);
                    this.SendMessage(messages[1], n, QUEUEERROR);
                }
                else
                {
                    BagTMLog.LogError(
                        String.Format("BagTM Queue Processing Error with no TTY message", n), this, e);
                }
            }

            BagTMLog.LogDebug(
                String.Format("BagTM Queue Debug Processing Queue Process End"), this);
        }
        public OSUSR_UUK_BAGMSGS Save(BaggageEntities db)
        {
            OSUSR_UUK_BAGMSGS obj = this.getOSUSR_UUK_BAGMSGS();

            obj.TIMESTAMP = now;

            BagTMLog.LogDebug("BagTM Queue About to Write to DB message : " + this.NBAGTAG, obj);

            BaggageEntities dbins = new BaggageEntities();

            try
            {
                dbins.OSUSR_UUK_BAGMSGS.Add(obj);
                dbins.SaveChanges();
                return(obj);
            }
            catch (DbEntityValidationException ex)
            {
                dbins.OSUSR_UUK_BAGMSGS.Remove(obj);
                // 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, " BaggageTTYTable the validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new TableException(exceptionMessage);
            }
            catch (Exception e)
            {
                dbins.OSUSR_UUK_BAGMSGS.Remove(obj);

                throw e;
            }
        }
        /// <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);
        }
Exemple #15
0
        private void refreshList()
        {
            refreshLimit = DateTime.Now.AddMinutes(5);

            BaggageEntities dbSV = new BaggageEntities();

            var sorterVolumeQuery = (from bi in dbSV.OSUSR_UUK_H2H
                                     where bi.IETA != null && bi.IETA >= DateTime.Now
                                     // here I choose each field I want to group by
                                     group bi by new { bi.IETA, bi.IATA } into g
                                     select new
            {
                DATEINIT = (g.Key.IATA != null && ((DateTime)g.Key.IATA).Year > 1900) ?
                           (DateTime)g.Key.IATA : (DateTime)g.Key.IETA,
                Count = g.Sum(x => x.INRBAGS)
            }
                                     ).ToList();

            var sorterVolumePerTime = sorterVolumeQuery
                                      .Select(s => new
            {
                DATEINIT = s.DATEINIT.AddMinutes(-1 * s.DATEINIT.Minute % 5),
                Count    = s.Count
            });

            sorterVolumeCalculate = sorterVolumePerTime
                                    .GroupBy(s => new { s.DATEINIT })
                                    .Select(r => new SorterVolume
            {
                DATEINIT = r.Key.DATEINIT,
                DATEEND  = r.Key.DATEINIT.AddMinutes(5),
                COUNT    = r.Sum(x => (double)x.Count)
            }).ToList <SorterVolume>();

            BagTMLog.LogDebug("BagTM Engine Update H2H Bag Calculate", sorterVolumeCalculate);
        }
        public void UpdateBagIntegrity(OSUSR_UUK_BAGMSGS bag, OSUSR_UUK_BAGINTEG bagIntegrity, String hub, bool isHub, Int32 TTYChange)
        {
            BagTMLog.LogDebug("BagTM Engine Upodate Bag Integrity Start", this);

            BagTMLog.LogDebug("BagTM Engine Upodate Bag Integrity", bag);
            BagTMLog.LogDebug("BagTM Engine Upodate Bag Integrity", bagIntegrity);
            BagTMLog.LogDebug("BagTM Engine Upodate Bag Integrity", hub);
            BagTMLog.LogDebug("BagTM Engine Upodate Bag Integrity", isHub);
            BagTMLog.LogDebug("BagTM Engine Upodate Bag Integrity", TTYChange);
            bool isLocalTTYforHub = false;

            if (isHub && BagTMRulesActions.localBagParameter.Equals(bag.VBAGSOURCIND))
            {
                isLocalTTYforHub = true;
            }

            if (bag.NBAGTAG == null || bagIntegrity.NUMBER != bag.NBAGTAG + bag.NNRTAGS)
            {
                throw new EngineProcessingException(
                          String.Format("Message TTY {0} and BAGTAG {1} not processed due to incosistences.",
                                        bag.SMI, bag.NBAGTAG));
            }

            // Have to be defined what to do
            if (null != bagIntegrity.CLOSE)
            {
                bagIntegrity.CLOSE = null;
            }

            // Create different BagIntegrity record creation for Hub and Local TTY messages
            if (isHub)
            {
                // The message is a local message for Hub transit
                if (isLocalTTYforHub)
                {
                    if (bag.FFLTNR != null && !CommonFunctions.FormatFlightNumber(bag.FFLTNR).Equals(bagIntegrity.IFLTNR))
                    {
                        bagIntegrity.IFLTNR = CommonFunctions.FormatFlightNumber(bag.FFLTNR);
                    }
                    if (bag.FDATE != null && !bag.FDATE.Equals(bagIntegrity.IDATE))
                    {
                        bagIntegrity.IDATE = bag.FDATE;
                    }
                    if (bag.VCITY != null && !bag.VCITY.Equals(bagIntegrity.IORIGIN))
                    {
                        bagIntegrity.IORIGIN = bag.VCITY;
                    }
                    if (bag.SSEAT != null && !bag.SSEAT.Equals(bagIntegrity.ISEAT))
                    {
                        bagIntegrity.ISEAT = bag.SSEAT;
                    }
                    if (bag.OFLTNR != null && !CommonFunctions.FormatFlightNumber(bag.OFLTNR).Equals(bagIntegrity.FFLTNR))
                    {
                        bagIntegrity.FFLTNR = CommonFunctions.FormatFlightNumber(bag.OFLTNR);
                    }
                    if (bag.ODATE != null && !bag.ODATE.Equals(bagIntegrity.FDATE))
                    {
                        bagIntegrity.FDATE = bag.ODATE;
                    }
                    if (bag.ODEST != null && !bag.ODEST.Equals(bagIntegrity.FDEST))
                    {
                        bagIntegrity.FDEST = bag.ODEST;
                    }
                    if (BagTMRulesActions.SMI_BPM.Equals(bag.SMI))
                    {
                        bagIntegrity.BPMIN = BagTMRulesActions.YES;
                    }
                    if (BagTMRulesActions.PAX_BOARDED_STATUS.Equals(bag.SPAXCK))
                    {
                        bagIntegrity.BSMBOARDI = BagTMRulesActions.PAX_BOARDED_STATUS;
                    }

                    switch (TTYChange)
                    {
                    case BagTMRulesActions.BAG_TTY_CHANGE_AUTH:
                        bagIntegrity.IAUT = bag.SAUTL;
                        break;

                    case BagTMRulesActions.BAG_TTY_CHANGE_PAX_BOARDED:
                        bagIntegrity.BSMBOARDI = BagTMRulesActions.PAX_BOARDED_STATUS;
                        break;

                    case BagTMRulesActions.BAG_TTY_CHANGE_LOAD_FAIL:
                        bagIntegrity.BPMIN = BagTMRulesActions.PAX_BOARDED_FAIL;
                        break;

                    case BagTMRulesActions.BAG_TTY_CHANGE_BAGGAGE_OFFLOAD:
                        if (bagIntegrity.IFLTNR != null)
                        {
                            bagIntegrity.IAUT  = BagTMRulesActions.BAG_OFF;
                            bagIntegrity.BPMIN = BagTMRulesActions.BAG_OFF;
                        }
                        if (bagIntegrity.FFLTNR != null)
                        {
                            bagIntegrity.FAUT   = BagTMRulesActions.BAG_OFF;
                            bagIntegrity.BPMHUB = BagTMRulesActions.BAG_OFF;
                        }
                        break;

                    case BagTMRulesActions.BAG_TTY_CHANGE_PAX_CANCEL:
                        if (bagIntegrity.IFLTNR != null)
                        {
                            bagIntegrity.IAUT  = BagTMRulesActions.PAX_AUT_STATUS_CODE;
                            bagIntegrity.BPMIN = BagTMRulesActions.PAX_AUT_STATUS_CODE;
                        }
                        if (bagIntegrity.FFLTNR != null)
                        {
                            bagIntegrity.FAUT   = BagTMRulesActions.PAX_AUT_STATUS_CODE;
                            bagIntegrity.BPMHUB = BagTMRulesActions.PAX_AUT_STATUS_CODE;
                        }
                        break;
                    }
                    if (bag.PPAXNAME.Equals(BagTMRulesActions.BAGGAGE_CREW))
                    {
                        bagIntegrity.FAUT      = BagTMRulesActions.BAG_CREW_VALUE;
                        bagIntegrity.BPMIN     = BagTMRulesActions.BAG_CREW_VALUE;
                        bagIntegrity.BSMBOARDI = BagTMRulesActions.BAG_CREW_VALUE;
                    }
                }
                else
                {
                    if (bag.IFLTNR != null && !CommonFunctions.FormatFlightNumber(bag.IFLTNR).Equals(bagIntegrity.IFLTNR))
                    {
                        bagIntegrity.IFLTNR = CommonFunctions.FormatFlightNumber(bag.IFLTNR);
                    }
                    if (bag.IDATE != null && !bag.IDATE.Equals(bagIntegrity.IDATE))
                    {
                        bagIntegrity.IDATE = bag.IDATE;
                    }
                    if (bag.IORIGIN != null && !bag.IORIGIN.Equals(bagIntegrity.IORIGIN))
                    {
                        bagIntegrity.IORIGIN = bag.IORIGIN;
                    }
                    if (bag.SSEAT != null && !bag.SSEAT.Equals(bagIntegrity.FSEAT))
                    {
                        bagIntegrity.FSEAT = bag.SSEAT;
                    }
                    if (bag.FFLTNR != null && !CommonFunctions.FormatFlightNumber(bag.FFLTNR).Equals(bagIntegrity.FFLTNR))
                    {
                        bagIntegrity.FFLTNR = CommonFunctions.FormatFlightNumber(bag.FFLTNR);
                    }
                    if (bag.FDATE != null && !bag.FDATE.Equals(bagIntegrity.FDATE))
                    {
                        bagIntegrity.FDATE = bag.FDATE;
                    }
                    if (bag.FDEST != null && !bag.FDEST.Equals(bagIntegrity.FDEST))
                    {
                        bagIntegrity.FDEST = bag.FDEST;
                    }

                    if (BagTMRulesActions.SMI_BPM.Equals(bag.SMI))
                    {
                        bagIntegrity.BPMHUB = BagTMRulesActions.YES;
                    }
                    if (BagTMRulesActions.BAGGAGE_RUSH.Equals(bag.EEXCEP) || this.IsRush(bagIntegrity))
                    {
                        bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_RUSH_VALUE;
                    }
                    if (BagTMRulesActions.BAGGAGE_PRIO.Equals(bag.EEXCEP))
                    {
                        bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_PRIO_VALUE;
                    }
                    if (BagTMRulesActions.PAX_BOARDED_STATUS.Equals(bag.SPAXCK))
                    {
                        bagIntegrity.BSMBOARD = BagTMRulesActions.PAX_BOARDED_STATUS;
                    }

                    switch (TTYChange)
                    {
                    case BagTMRulesActions.BAG_TTY_CHANGE_AUTH:
                        bagIntegrity.FAUT = bag.SAUTL;
                        break;

                    case BagTMRulesActions.BAG_TTY_CHANGE_PAX_BOARDED:
                        bagIntegrity.BSMBOARD = BagTMRulesActions.PAX_BOARDED_STATUS;
                        break;

                    case BagTMRulesActions.BAG_TTY_CHANGE_LOAD_FAIL:
                        bagIntegrity.BPMHUB = BagTMRulesActions.PAX_BOARDED_FAIL;
                        break;

                    case BagTMRulesActions.BAG_TTY_CHANGE_BAGGAGE_OFFLOAD:
                        bagIntegrity.FAUT   = BagTMRulesActions.BAG_OFF;
                        bagIntegrity.BPMHUB = BagTMRulesActions.BAG_OFF;
                        break;

                    case BagTMRulesActions.BAG_TTY_CHANGE_PAX_CANCEL:
                        bagIntegrity.FAUT   = BagTMRulesActions.PAX_AUT_STATUS_CODE;
                        bagIntegrity.BPMHUB = BagTMRulesActions.PAX_AUT_STATUS_CODE;
                        break;
                    }
                    if (bag.PPAXNAME.Equals(BagTMRulesActions.BAGGAGE_CREW))
                    {
                        bagIntegrity.FAUT     = BagTMRulesActions.BAG_CREW_VALUE;
                        bagIntegrity.BPMHUB   = BagTMRulesActions.BAG_CREW_VALUE;
                        bagIntegrity.BSMBOARD = BagTMRulesActions.BAG_CREW_VALUE;
                    }
                }
            }
            else
            {
                if (bag.FFLTNR != null && !CommonFunctions.FormatFlightNumber(bag.FFLTNR).Equals(bagIntegrity.FFLTNR))
                {
                    bagIntegrity.FFLTNR = CommonFunctions.FormatFlightNumber(bag.FFLTNR);
                }
                if (bag.FDATE != null && !bag.FDATE.Equals(bagIntegrity.FDATE))
                {
                    bagIntegrity.FDATE = bag.FDATE;
                }
                if (bag.FDEST != null && !bag.FDEST.Equals(bagIntegrity.FDEST))
                {
                    bagIntegrity.FDEST = bag.FDEST;
                }
                if (bag.SSEAT != null && !bag.SSEAT.Equals(bagIntegrity.FSEAT))
                {
                    bagIntegrity.FSEAT = bag.SSEAT;
                }

                if (BagTMRulesActions.SMI_BPM.Equals(bag.SMI))
                {
                    bagIntegrity.BPMHUB = BagTMRulesActions.YES;
                }
                if (BagTMRulesActions.BAGGAGE_RUSH.Equals(bag.EEXCEP) || this.IsRush(bagIntegrity))
                {
                    bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_RUSH_VALUE;
                }
                if (BagTMRulesActions.BAGGAGE_PRIO.Equals(bag.EEXCEP))
                {
                    bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_PRIO_VALUE;
                }
                if (BagTMRulesActions.PAX_BOARDED_STATUS.Equals(bag.SPAXCK))
                {
                    bagIntegrity.BSMBOARD = BagTMRulesActions.PAX_BOARDED_STATUS;
                }

                switch (TTYChange)
                {
                case BagTMRulesActions.BAG_TTY_CHANGE_AUTH:
                    bagIntegrity.FAUT = bag.SAUTL;
                    break;

                case BagTMRulesActions.BAG_TTY_CHANGE_PAX_BOARDED:
                    bagIntegrity.BSMBOARD = BagTMRulesActions.PAX_BOARDED_STATUS;
                    break;

                case BagTMRulesActions.BAG_TTY_CHANGE_LOAD_FAIL:
                    bagIntegrity.BPMHUB = BagTMRulesActions.PAX_BOARDED_FAIL;
                    break;

                case BagTMRulesActions.BAG_TTY_CHANGE_BAGGAGE_OFFLOAD:
                    bagIntegrity.FAUT   = BagTMRulesActions.BAG_OFF;
                    bagIntegrity.BPMHUB = BagTMRulesActions.BAG_OFF;
                    break;

                case BagTMRulesActions.BAG_TTY_CHANGE_PAX_CANCEL:
                    bagIntegrity.FAUT   = BagTMRulesActions.PAX_AUT_STATUS_CODE;
                    bagIntegrity.BPMHUB = BagTMRulesActions.PAX_AUT_STATUS_CODE;
                    break;
                }
                if (bag.PPAXNAME.Equals(BagTMRulesActions.BAGGAGE_CREW))
                {
                    bagIntegrity.FAUT     = BagTMRulesActions.BAG_CREW_VALUE;
                    bagIntegrity.BPMHUB   = BagTMRulesActions.BAG_CREW_VALUE;
                    bagIntegrity.BSMBOARD = BagTMRulesActions.BAG_CREW_VALUE;
                }
            }

            // Change register for baggage groups
            if (!bagIntegrity.NUMBER.EndsWith(BagTMRulesActions.BAGGAGE_NRTAG_001))
            {
                bagIntegrity.FAUT  = (bagIntegrity.FAUT != null) ? BagTMRulesActions.BAG_GROUP_AUT_CODE : null;
                bagIntegrity.IAUT  = (bagIntegrity.IAUT != null) ? BagTMRulesActions.BAG_GROUP_AUT_CODE : null;
                bagIntegrity.BPMIN = (bagIntegrity.BPMIN != null) ? BagTMRulesActions.BAG_GROUP_BPM_CODE : null;
                bagIntegrity.IAUT  = (bagIntegrity.BPMHUB != null) ? BagTMRulesActions.BAG_GROUP_BPM_CODE : null;
            }

            BaggageEntities dbup = new BaggageEntities();

            try
            {
                BagTMLog.LogDebug("BagTM Engine Upodate Bag Integrity Saving", bagIntegrity);

                // Verifies if updating last baggage integrity record, if more then one remove all
                OSUSR_UUK_BAGINTEG lastBaggageIntegraty = this.LastBaggageIntegraty(bagIntegrity);
                if (lastBaggageIntegraty != null && lastBaggageIntegraty.TIMESTAMP != null &&
                    lastBaggageIntegraty.TIMESTAMP > bagIntegrity.TIMESTAMP)
                {
                    this.UpdateBagIntegrity(bag, lastBaggageIntegraty, hub, isHub, TTYChange);
                }
                else
                {
                    if (lastBaggageIntegraty != null)
                    {
                        bagIntegrity = MergeBagIntegrity(bagIntegrity, lastBaggageIntegraty);
                    }

                    bagIntegrity.TIMESTAMP = DateTime.Now;

                    dbup.OSUSR_UUK_BAGINTEG.Attach(bagIntegrity);
                    dbup.Entry(bagIntegrity).State = EntityState.Modified;
                    dbup.SaveChanges();
                }

                BagTMLog.LogInfo("BagTM Engine Update Bag Integrity: " + bagIntegrity.NUMBER, this);
            }
            catch (DbEntityValidationException ex)
            {
                dbup.OSUSR_UUK_BAGINTEG.Remove(bagIntegrity);

                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors;

                // 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)
            {
                dbup.OSUSR_UUK_BAGINTEG.Remove(bagIntegrity);

                throw e;
            }

            BagTMLog.LogDebug("BagTM Engine Upodate Bag Integrity End", this);
        }
        /// <summary>
        /// Constructor to create logger and tasks and queue parametrization
        /// </summary>
        public ExecutionDataflowEngineProcessing()
        {
            BagTMLog.LogDebug("BagTM Engine Processing Constructor", this);

            config = ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None) as Configuration;

            hub = this.GetAppSetting(config, "hub");
            if (hub == null)
            {
                throw new EngineProcessingException("No hub defined to process TTY messages");
            }

            airline = this.GetAppSetting(config, "airline");
            if (airline == null)
            {
                throw new EngineProcessingException("No airline defined to process TTY messages");
            }

            BagTMLog.LogDebug("BagTM Engine Processing hub ", hub);

            String timeSpanParameter = this.GetAppSetting(config, "timeSpan");
            int    timeSpanNumber    = 0;

            if (!int.TryParse(timeSpanParameter, out timeSpanNumber))
            {
                throw new EngineProcessingException("Parameter TimeSpan incorrectly configured");
            }

            this.timeSpan = new TimeSpan((Int64)(timeSpanNumber * TimeSpan.TicksPerMillisecond));

            BagTMLog.LogDebug("BagTM Engine Processing Constructor timeSpanNumber", this.timeSpan);

            String parallelismCounterParameter = this.GetAppSetting(config, "parallelismCounter");

            if (!int.TryParse(parallelismCounterParameter, out this.parallelismCounter))
            {
                throw new EngineProcessingException("Parameter ParallelismCounter incorrectly configured");
            }

            BagTMLog.LogDebug("BagTM Engine Processing Constructor parallelismCounterParameter", parallelismCounterParameter);

            queueEngine       = this.CreateMessageQueue(QUEUEENGINE);
            queueEngineSucess = this.CreateMessageQueue(QUEUESUCESS);
            queueEngineError  = this.CreateMessageQueue(QUEUEERROR);

            BagTMLog.LogDebug("BagTM Engine Processing Constructor queueEngine", queueEngine);
            BagTMLog.LogDebug("BagTM Engine Processing Constructor queueEngineSucess", queueEngineSucess);
            BagTMLog.LogDebug("BagTM Engine Processing Constructor queueEngineError", queueEngineError);

            baggageTerminalCode = this.GetAppSetting(config, "baggageTerminal");
            if (baggageTerminalCode == null)
            {
                throw new EngineProcessingException("No baggage terminal configured");
            }

            String sorterTimeParameter = this.GetAppSetting(config, "sorterTime");

            if (!int.TryParse(sorterTimeParameter, out sorterTime))
            {
                throw new EngineProcessingException("Parameter sorter time incorrectly configured");
            }

            String etcgParameter = this.GetAppSetting(config, "etcg");

            if (!int.TryParse(sorterTimeParameter, out etcg))
            {
                throw new EngineProcessingException("Parameter estimated time to close gate incorrectly configured");
            }

            defaultEquipment = this.GetAppSetting(config, "defaultEquipment");
            if (!int.TryParse(defaultEquipment, out int aux))
            {
                throw new EngineProcessingException("Parameter default equipment incorrectly configured");
            }

            defaultStandFrom = this.GetAppSetting(config, "defaultStandFrom");
            if (defaultStandFrom == null)
            {
                throw new EngineProcessingException("No default stand from configured");
            }

            defaultGateTo = this.GetAppSetting(config, "defaultGateTo");
            if (defaultGateTo == null)
            {
                throw new EngineProcessingException("No default stand to configured");
            }

            String maxPaxTurnaroundParameter = this.GetAppSetting(config, "maxPaxTurnaround");

            if (!int.TryParse(maxPaxTurnaroundParameter, out this.maxPaxTurnaround))
            {
                throw new EngineProcessingException("No max pax turnaround configured");
            }

            String maxBaggageTurnaroundParameter = this.GetAppSetting(config, "maxBaggageTurnaround");

            if (!int.TryParse(maxBaggageTurnaroundParameter, out this.maxBaggageTurnaround))
            {
                throw new EngineProcessingException("No max baggage turnaround configured");
            }

            String maxSorterThroughPutParameter = this.GetAppSetting(config, "maxSorterThroughPut");

            if (!int.TryParse(maxSorterThroughPutParameter, out this.maxSorterThroughPut))
            {
                throw new EngineProcessingException("No max sorter through put configured");
            }

            String minLoadUnloadTimeParameter = this.GetAppSetting(config, "minLoadUnloadTime");

            if (!int.TryParse(minLoadUnloadTimeParameter, out this.minLoadUnloadTime))
            {
                throw new EngineProcessingException("No min load / unload configured");
            }

            String maxLoadUnloadTimeParameter = this.GetAppSetting(config, "maxLoadUnloadTime");

            if (!int.TryParse(maxLoadUnloadTimeParameter, out this.maxLoadUnloadTime))
            {
                throw new EngineProcessingException("No max load / unload configured");
            }

            //Load rules
            var repository = new RuleRepository();

            Type[] ruleTypes = new Type[13];
            repository.Load(x => x
                            .From(Assembly.GetExecutingAssembly()).To("BagTMRuleSet")
                            .Where(r => r.IsTagged("BagIntegrity")));

            BagTMLog.LogDebug("BagTM Engine Processing Constructor repository", repository);

            //Compile rules
            var ruleSets = repository.GetRuleSets();
            var compiler = new RuleCompiler();

            factory = compiler.Compile(ruleSets);

            //Create a working session
            factory.Events.FactInsertedEvent      += BagRulesEventMonitorization.OnFactInsertedEvent;
            factory.Events.FactUpdatedEvent       += BagRulesEventMonitorization.OnFactUpdatedEvent;
            factory.Events.FactRetractedEvent     += BagRulesEventMonitorization.OnFactRetractedEvent;
            factory.Events.ActivationCreatedEvent += BagRulesEventMonitorization.OnActivationCreatedEvent;
            factory.Events.ActivationUpdatedEvent += BagRulesEventMonitorization.OnActivationUpdatedEvent;
            factory.Events.ActivationDeletedEvent += BagRulesEventMonitorization.OnActivationDeletedEvent;
            factory.Events.RuleFiringEvent        += BagRulesEventMonitorization.OnRuleFiringEvent;
            factory.Events.RuleFiredEvent         += BagRulesEventMonitorization.OnRuleFireEvent;
            factory.Events.ActionFailedEvent      += BagRulesEventMonitorization.OnActionFailedEvent;
            factory.Events.ConditionFailedEvent   += BagRulesEventMonitorization.OnConditionFailedEvent;

            this.sorterVolumeMap = new SorterProcessingVolumeMap();

            BagTMLog.LogDebug("BagTM Engine Processing Constructor factory", factory);

            this.RefreshRefLists();

            BagTMLog.LogDebug(
                String.Format("BagTM Engine Processing Task Process Message Define Dataflow Block Parallelism Counter {0}", parallelismCounter)
                , this);

            BagTMLog.LogDebug("BagTM Engine Processing Constructor Ending", this);
        }
Exemple #18
0
        public Object parse(String messageString, BaggageEntities db)
        {
            BagTMLog.LogDebug(
                String.Format("BagTM Queue Message Parsing TTY {0}", messageString), this);

            String[]         elements;
            String[]         components;
            String           keyTTY;
            String           keyElement;
            IBaggageTTYTable messageObject = null;
            String           methodName;
            String           parameter = null;
            String           messageStripped;

            // At this stage formatter alredy removed headers
            messageStripped = this.RemoveHeaders(messageString);
            elements        = Regex.Split(messageStripped, matchElements);

            try
            {
                BagTMLog.LogDebug(
                    String.Format("BagTM Queue Message Parsing TTY Message element[0] {0} element[0].lenght {1}",
                                  elements[0], elements[0].Length), this);

                if (elements[0] != null && elements[0].Length > 2 && ttyCollection.HasTTY(elements[0].Substring(0, 3)))
                {
                    keyTTY = elements[0].Substring(0, 3);

                    BagTMLog.LogDebug(
                        String.Format("BagTM Queue Message Parsing TTY Message with Key {0} Processing by EntityName {1} and Type {2}",
                                      keyTTY, ttyCollection.GetTTYElement(keyTTY).entityName,
                                      Type.GetType(ttyCollection.GetTTYElement(keyTTY).entityName)), this);

                    messageObject = (IBaggageTTYTable)Activator.CreateInstance(Type.GetType(ttyCollection.GetTTYElement(keyTTY).entityName));
                    messageObject.Clean();

                    foreach (string element in elements)
                    {
                        components = Regex.Split(element, matchComponents);

                        keyElement = (!element.Equals(elements[0])) ? components[0] : "default";

                        BagTMLog.LogDebug(
                            String.Format("BagTM Queue Message Parsing TTY Message with Key {0} Processing KeyElement {1} for Element {2} and Components[0] {3} ",
                                          keyTTY, keyElement, element, components[0]), this);

                        if (components[0] != null && ttyCollection.HasTTYElement(keyTTY, keyElement))
                        {
                            foreach (TTYComponentConfigElement config in ttyCollection.GetTTYElement(keyTTY).ttyElements.GetTTYElementElement(keyElement).ttycomponents)
                            {
                                BagTMLog.LogDebug(
                                    String.Format("BagTM Queue Message Parsing TTY Message with Config Size {0}", ttyCollection.GetTTYElement(keyTTY).ttyElements.GetTTYElementElement(keyElement).ttycomponents.Count), this);

                                BagTMLog.LogDebug(
                                    String.Format("BagTM Queue Message Parsing TTY Message key {0}, keyElement {1}, position {2} and substring {3} from components {4}",
                                                  keyTTY, keyElement, config.GetPositionInt(), config.substring, components.Length), this);

                                parameter  = null;
                                methodName = config.methodName;

                                // To process all components based on XML configuration
                                if (config.GetPositionInt() < 0)
                                {
                                    // If position = 0 then all components in the same attribute
                                    // Also remove . and /
                                    parameter = element.Substring(components[0].Length + 1);
                                }
                                else if (config.GetPositionInt() < components.Length)
                                {
                                    if (config.substring != null && config.substring.Length > 0)
                                    {
                                        if (components[config.GetPositionInt()].Length >= config.StartSubString() + config.LenghtSubString())
                                        {
                                            parameter = components[config.GetPositionInt()].
                                                        Substring(config.StartSubString(), config.LenghtSubString());
                                        }
                                        else
                                        {
                                            parameter = null;
                                        }
                                    }
                                    else
                                    {
                                        parameter = components[config.GetPositionInt()];
                                    }
                                }

                                if (config.GetPositionInt() < components.Length)
                                {
                                    BagTMLog.LogDebug(
                                        String.Format("BagTM Queue Message Parsing TTY Message key {0} and keyElement {1} position {2} to method {3} with parameters {4}",
                                                      keyTTY, keyElement, config.position, methodName, parameter), this);

                                    // Not necessary if parameter is null since no change to object
                                    if (parameter != null)
                                    {
                                        messageObject.SetValue(methodName, parameter);
                                    }

                                    BagTMLog.LogDebug(
                                        String.Format("BagTM Queue Message Parsing TTY Message key {0} and keyElement {1} position {2} stored object {3}",
                                                      keyTTY, keyElement, config.position, messageObject.ToString()), this);
                                }
                            }
                        }
                        else
                        {
                            BagTMLog.LogDebug(
                                String.Format("BagTM Queue Message Parsing TTY Message key {0} and keyElement {1} does not process in element {2}",
                                              keyTTY, keyElement, element), this);
                        }
                    }
                }
                else
                {
                    BagTMLog.LogDebug(
                        String.Format("BagTM Queue Message Parsing TTY Message key {0} does not process {1}", elements[0], messageString), this);
                }
            } catch (Exception e)
            {
                BagTMLog.LogError("BagTM Queue Message Parsing TTY Parser Error", this, e);

                throw e;
            }

            BagTMLog.LogDebug(
                String.Format("BagTM Queue Message Parsing TTY Parser Collection {0}", messageString), this);

            // Se o objeto estiver instanciado então foi preenchido e deve ser guardado em base de dados
            if (messageObject != null)
            {
                BagTMLog.LogInfo(
                    String.Format("BagTM Queue Message Message Parsed {0}", messageObject), this);
                return(messageObject.Save(db));
            }
            else
            {
                return(null);
            }
        }
 public static void OnRuleFireEvent(object sender, AgendaEventArgs e)
 {
     BagTMLog.LogDebug(
         String.Format("BagTM Engine Processing Rules Fired {0}", e.Rule.Name), sender);
 }
        /// <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);
        }
        public void CreateBagIntegrity(OSUSR_UUK_BAGMSGS bag, OSUSR_UUK_BAGINTEG bagIntegrity, String hub, bool isHub)
        {
            BagTMLog.LogDebug("BagTM Engine Create Bag Integrity Start", this);

            BagTMLog.LogDebug("BagTM Engine Create Bag Integrity ", bag);
            BagTMLog.LogDebug("BagTM Engine Create Bag Integrity ", bagIntegrity);
            BagTMLog.LogDebug("BagTM Engine Create Bag Integrity ", hub);
            BagTMLog.LogDebug("BagTM Engine Create Bag Integrity ", isHub);

            bool isLocalTTYforHub   = false;
            bool isLocalEndingInHub = false;

            if (isHub && BagTMRulesActions.localBagParameter.Equals(bag.VBAGSOURCIND))
            {
                isLocalTTYforHub = true;
            }
            if (isHub && isLocalTTYforHub && bag.OFLTNR == null)
            {
                isLocalEndingInHub = true;
            }
            if (isHub && !isLocalTTYforHub && bag.IFLTNR != null)
            {
                isLocalEndingInHub = true;
            }

            bagIntegrity.NUMBER    = bag.NBAGTAG + bag.NNRTAGS;
            bagIntegrity.CLOSE     = null;
            bagIntegrity.TIMESTAMP = DateTime.Now;

            // Create different BagIntegrity record creation for Hub and Local TTY messages
            if (isHub)
            {
                // The message is a local message for Hub transit
                if (isLocalTTYforHub)
                {
                    bagIntegrity.IFLTNR  = CommonFunctions.FormatFlightNumber(bag.FFLTNR);
                    bagIntegrity.IDATE   = bag.FDATE;
                    bagIntegrity.IORIGIN = bag.VCITY;
                    bagIntegrity.ISEAT   = bag.SSEAT;
                    bagIntegrity.IAUT    = bag.SAUTL;
                    // Fill the FFP information for the flight
                    if (bag.YFQTV != null)
                    {
                        if (bag.YFQTV.Contains(BagTMRulesActions.FFP_GOLD))
                        {
                            bagIntegrity.IFFP = BagTMRulesActions.FFP_GOLD_VALUE;
                        }
                        else if (bag.YFQTV.Contains(BagTMRulesActions.FFP_SILVER))
                        {
                            bagIntegrity.IFFP = BagTMRulesActions.FFP_SILVER_VALUE;
                        }
                        else
                        {
                            bagIntegrity.IFFP = BagTMRulesActions.FFP_BLUE_VALUE;
                        }
                    }
                    // If TTY implicates a onward flight out of the Hub
                    if (!isLocalEndingInHub)
                    {
                        bagIntegrity.FFLTNR = CommonFunctions.FormatFlightNumber(bag.OFLTNR);
                        bagIntegrity.FDATE  = bag.ODATE;
                        bagIntegrity.FDEST  = bag.ODEST;
                    }
                    if (BagTMRulesActions.SMI_BPM.Equals(bag.SMI))
                    {
                        bagIntegrity.BPMIN = BagTMRulesActions.YES;
                    }
                    if (BagTMRulesActions.PAX_BOARDED_STATUS.Equals(bag.SPAXCK))
                    {
                        bagIntegrity.BSMBOARDI = BagTMRulesActions.PAX_BOARDED_STATUS;
                    }
                    if (BagTMRulesActions.BAGGAGE_RUSH.Equals(bag.EEXCEP) || this.IsRush(bagIntegrity))
                    {
                        bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_RUSH_VALUE;
                    }
                    if (BagTMRulesActions.BAGGAGE_PRIO.Equals(bag.EEXCEP))
                    {
                        bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_PRIO_VALUE;
                    }
                    if (bag.PPAXNAME.Equals(BagTMRulesActions.BAGGAGE_CREW))
                    {
                        bagIntegrity.IAUT      = BagTMRulesActions.BAG_CREW_VALUE;
                        bagIntegrity.BPMIN     = BagTMRulesActions.BAG_CREW_VALUE;
                        bagIntegrity.BSMBOARDI = BagTMRulesActions.BAG_CREW_VALUE;
                    }
                }
                else
                {
                    bagIntegrity.IFLTNR  = CommonFunctions.FormatFlightNumber(bag.IFLTNR);
                    bagIntegrity.IDATE   = bag.IDATE;
                    bagIntegrity.IORIGIN = bag.IORIGIN;
                    bagIntegrity.FFLTNR  = CommonFunctions.FormatFlightNumber(bag.FFLTNR);
                    bagIntegrity.FDATE   = bag.FDATE;
                    bagIntegrity.FDEST   = bag.FDEST;
                    bagIntegrity.FAUT    = bag.SAUTL;
                    bagIntegrity.FSEAT   = bag.SSEAT;
                    // Fill the FFP information for the flight
                    if (bag.YFQTV != null)
                    {
                        if (bag.YFQTV.Contains(BagTMRulesActions.FFP_GOLD))
                        {
                            bagIntegrity.OFFP = BagTMRulesActions.FFP_GOLD_VALUE;
                        }
                        else if (bag.YFQTV.Contains(BagTMRulesActions.FFP_SILVER))
                        {
                            bagIntegrity.OFFP = BagTMRulesActions.FFP_SILVER_VALUE;
                        }
                        else
                        {
                            bagIntegrity.OFFP = BagTMRulesActions.FFP_BLUE_VALUE;
                        }
                    }
                    if (BagTMRulesActions.SMI_BPM.Equals(bag.SMI))
                    {
                        bagIntegrity.BPMHUB = BagTMRulesActions.YES;
                    }
                    if (BagTMRulesActions.PAX_BOARDED_STATUS.Equals(bag.SPAXCK))
                    {
                        bagIntegrity.BSMBOARD = BagTMRulesActions.PAX_BOARDED_STATUS;
                    }
                    if (BagTMRulesActions.BAGGAGE_RUSH.Equals(bag.EEXCEP) || this.IsRush(bagIntegrity))
                    {
                        bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_RUSH_VALUE;
                    }
                    if (BagTMRulesActions.BAGGAGE_PRIO.Equals(bag.EEXCEP))
                    {
                        bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_PRIO_VALUE;
                    }
                    if (bag.PPAXNAME.Equals(BagTMRulesActions.BAGGAGE_CREW))
                    {
                        bagIntegrity.FAUT     = BagTMRulesActions.BAG_CREW_VALUE;
                        bagIntegrity.BPMHUB   = BagTMRulesActions.BAG_CREW_VALUE;
                        bagIntegrity.BSMBOARD = BagTMRulesActions.BAG_CREW_VALUE;
                    }
                }
            }
            else
            {
                bagIntegrity.FFLTNR = CommonFunctions.FormatFlightNumber(bag.FFLTNR);
                bagIntegrity.FDATE  = bag.FDATE;
                bagIntegrity.FDEST  = bag.FDEST;
                bagIntegrity.FAUT   = bag.SAUTL;
                bagIntegrity.FSEAT  = bag.SSEAT;
                // Fill the FFP information for the flight
                if (bag.YFQTV != null)
                {
                    if (bag.YFQTV.Contains(BagTMRulesActions.FFP_GOLD))
                    {
                        bagIntegrity.OFFP = BagTMRulesActions.FFP_GOLD_VALUE;
                    }
                    else if (bag.YFQTV.Contains(BagTMRulesActions.FFP_SILVER))
                    {
                        bagIntegrity.OFFP = BagTMRulesActions.FFP_SILVER_VALUE;
                    }
                    else
                    {
                        bagIntegrity.OFFP = BagTMRulesActions.FFP_BLUE_VALUE;
                    }
                }
                if (BagTMRulesActions.SMI_BPM.Equals(bag.SMI))
                {
                    bagIntegrity.BPMHUB = BagTMRulesActions.YES;
                }
                if (BagTMRulesActions.PAX_BOARDED_STATUS.Equals(bag.SPAXCK))
                {
                    bagIntegrity.BSMBOARD = BagTMRulesActions.PAX_BOARDED_STATUS;
                }
                if (BagTMRulesActions.BAGGAGE_RUSH.Equals(bag.EEXCEP) || this.IsRush(bagIntegrity))
                {
                    bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_RUSH_VALUE;
                }
                if (BagTMRulesActions.BAGGAGE_PRIO.Equals(bag.EEXCEP))
                {
                    bagIntegrity.ISRUSH = BagTMRulesActions.BAGGAGE_PRIO_VALUE;
                }
                if (bag.PPAXNAME.Equals(BagTMRulesActions.BAGGAGE_CREW))
                {
                    bagIntegrity.FAUT     = BagTMRulesActions.BAG_CREW_VALUE;
                    bagIntegrity.BPMHUB   = BagTMRulesActions.BAG_CREW_VALUE;
                    bagIntegrity.BSMBOARD = BagTMRulesActions.BAG_CREW_VALUE;
                }
            }

            // Change register for baggage groups
            if (!bagIntegrity.NUMBER.EndsWith(BagTMRulesActions.BAGGAGE_NRTAG_001))
            {
                bagIntegrity.FAUT  = (bagIntegrity.FAUT != null) ? BagTMRulesActions.BAG_GROUP_AUT_CODE : null;
                bagIntegrity.IAUT  = (bagIntegrity.IAUT != null) ? BagTMRulesActions.BAG_GROUP_AUT_CODE : null;
                bagIntegrity.BPMIN = (bagIntegrity.BPMIN != null) ? BagTMRulesActions.BAG_GROUP_BPM_CODE : null;
                bagIntegrity.IAUT  = (bagIntegrity.BPMHUB != null) ? BagTMRulesActions.BAG_GROUP_BPM_CODE : null;
            }

            BaggageEntities dbin = new BaggageEntities();

            try
            {
                BagTMLog.LogDebug("BagTM Engine Create Bag Integrity Saving", bagIntegrity);

                dbin.OSUSR_UUK_BAGINTEG.Add(bagIntegrity);
                dbin.SaveChanges();
                BagTMLog.LogInfo("BagTM Engine Create Bag Integrity: " + bagIntegrity.NUMBER, this);
            }
            catch (DbEntityValidationException ex)
            {
                dbin.OSUSR_UUK_BAGINTEG.Remove(bagIntegrity);

                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors;

                // 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)
            {
                dbin.OSUSR_UUK_BAGINTEG.Remove(bagIntegrity);

                throw e;
            }
            BagTMLog.LogDebug("BagTM Engine Create Bag Integrity 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>
        /// Read queue
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        protected object[] ReadQueue(int n, int queueType)
        {
            object message = null;

            object[] messages = new object[2];

            BagTMLog.LogDebug(
                String.Format("BagTM Engine Read Task Message Start {0}", n), this);

            Message msg = null;

            try
            {
                MessageQueue queueUse = this.CreateMessageQueue(queueType);

                try
                {
                    msg         = queueUse.Receive(this.timeSpan);
                    messages[1] = msg;
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("Timeout"))
                    {
                        return(null);
                    }
                    queueUse = this.CreateMessageQueue(queueType);

                    msg         = queueUse.Receive(this.timeSpan);
                    messages[1] = msg;
                }

                if (msg != null)
                {
                    BagTMLog.LogDebug(
                        String.Format("BagTM Engine Read Task {0} for Message Body Type: {1}", n, msg.BodyType), this);

                    message     = (Object)msg.Body;
                    messages[0] = message;

                    BagTMLog.LogInfo("BagTM Engine TTY Message: " + message, this);

                    BagTMLog.LogDebug(
                        String.Format("BagTM Engine Read Task {0} with Message {1}", n, msg.Id), this);
                }
            }
            catch (Exception e)
            {
                BagTMLog.LogError(
                    String.Format("BagTM Engine Read Task {0} with Error", n), this, e);

                if (msg != null)
                {
                    this.SendMessage(msg, n, QUEUEERROR);
                }

                throw e;
            }

            BagTMLog.LogDebug(
                String.Format("BagTM Engine Read Task Message End {0}", n), this);

            return(messages);
        }
        /// <summary>
        /// Refresh reference list to ensure
        /// </summary>
        private void RefreshRefLists()
        {
            try
            {
                // BagTimes Reference
                if (this.refList == null)
                {
                    this.refList = this.SearchBagTimesReference();
                }

                BagTMLog.LogDebug("BagTM Engine Processing Constructor refList", refList);

                // Equipements Types
                if (this.equipementTypeList == null)
                {
                    this.equipementTypeList = this.SearchEquipementsTypes();
                }

                BagTMLog.LogDebug("BagTM Engine Processing Constructor equipementTypeList", equipementTypeList);

                // Taxi Times
                if (this.taxiTimesList == null)
                {
                    this.taxiTimesList = this.SearchTaxiTimes();
                }

                BagTMLog.LogDebug("BagTM Engine Processing Constructor taxiTimesList", taxiTimesList);

                // Registrations
                if (this.registrationList == null)
                {
                    this.registrationList = this.SearchRegistration();
                }

                BagTMLog.LogDebug("BagTM Engine Processing Constructor registrationList", registrationList);
            }
            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 query errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new EngineProcessingException(exceptionMessage);
            }

            if (this.h2hProcessing == null)
            {
                this.h2hProcessing = new H2HProcessing(this.hub, this.defaultEquipment, this.defaultStandFrom,
                                                       this.defaultGateTo, this.baggageTerminalCode, this.minLoadUnloadTime, this.maxLoadUnloadTime,
                                                       this.maxBaggageTurnaround, this.sorterVolumeMap, this.maxSorterThroughPut, this.sorterTime,
                                                       this.refList, this.equipementTypeList, this.taxiTimesList, this.registrationList);
            }

            if (this.ptmH2HProcessing == null)
            {
                this.ptmH2HProcessing = new PTMH2HProcessing(this.hub, this.etcg, this.maxPaxTurnaround, this.airline);
            }

            if (this.bagIntergityProcessing == null)
            {
                this.bagIntergityProcessing = new BagIntegrityProcessing(this.hub, this.airline, this.factory, this.h2hProcessing);
            }

            if (this.fltInfoProcessing == null)
            {
                this.fltInfoProcessing = new FLTINFOProcessing(this.h2hProcessing, this.ptmH2HProcessing);
            }
        }
        /// <summary>
        /// Send object to engine message queue
        /// </summary>
        /// <param name="messageObject"></param>
        protected void SendMessage(object messageObject, int n, int queueType)
        {
            BagTMLog.LogDebug(
                String.Format("BagTM Engine Send Task Message Start {0}", n), this);

            MessageQueue queueUse = this.CreateMessageQueue(queueType);

            // Send a message to the queue.
            if (queueUse.Transactional == true)
            {
                BagTMLog.LogDebug(
                    String.Format("BagTM Engine Create Transaction to Send Task {0}", n), this);

                // Create a transaction.
                MessageQueueTransaction myTransaction = new
                                                        MessageQueueTransaction();

                BagTMLog.LogDebug(
                    String.Format("BagTM Engine Transaction Created to Send Task {0}", n), this);

                // Begin the transaction.
                myTransaction.Begin();

                BagTMLog.LogDebug(
                    String.Format("BagTM Engine Begin Transaction to Send Task {0}", n), this);

                try
                {
                    // Send the message.
                    queueUse.Send(messageObject, myTransaction);
                }
                catch (Exception)
                {
                    queueUse = this.CreateMessageQueue(queueType);

                    // Send the message.
                    queueUse.Send(messageObject, myTransaction);
                }
                BagTMLog.LogDebug(
                    String.Format("BagTM Engine Message Sent Task {0}", n), this);

                // Commit the transaction.
                myTransaction.Commit();

                BagTMLog.LogInfo(
                    String.Format("BagTM Engine Message Sent {0}", messageObject), this);

                BagTMLog.LogDebug(
                    String.Format("BagTM Engine Transaction Commited Task {0}", n), this);
            }
            else
            {
                BagTMLog.LogDebug(
                    String.Format("BagTM Engine No Transaction to Send Task {0}", n), this);

                queueUse.Send(messageObject);

                BagTMLog.LogInfo(
                    String.Format("Engine Queue Message Sent {0}", messageObject), this);

                BagTMLog.LogDebug(
                    String.Format("BagTM Engine Message Sent No Transaction Task {0}", n), this);
            }

            return;
        }
 public static void OnActionFailedEvent(object sender, ActionErrorEventArgs e)
 {
     BagTMLog.LogDebug(
         String.Format("BagTM Engine Processing Rules Action Failed {0}", e.Action), sender);
 }
Exemple #27
0
        /// <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);
        }
Exemple #28
0
        /// <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);
        }
Exemple #29
0
        public Object parse(String messageString, BaggageEntities db)
        {
            BagTMLog.LogDebug(
                String.Format("BagTM Queue Message Parsing PTM TTY {0}", messageString), this);

            Match flight;
            MatchCollection outbounds;
            IPTMTTYTable messageObject = null;
            String methodName;
            String parameter = null;
            String messageStripped;

            // At this stage formatter alredy removed headers
            messageStripped = this.RemoveHeaders(messageString);
            flight = Regex.Match(messageString, matchFlights);
            outbounds = Regex.Matches(messageString.Remove(0, flight.Length), matchOutbounds);

            try
            {
                BagTMLog.LogDebug(
                    String.Format("BagTM Queue Message Parsing PTM TTY Message flight {0}", flight.Value), this);

                PTMTTYTable paxmsgs = new PTMTTYTable();

                TTYComponentConfigElement configFlight = ttyCollection.GetTTYElement("PTM").ttyElements.GetTTYElementElement("default").ttycomponents.GetTTYElementElement("Flight");
                
                if (!flight.Success)
                    throw new PTMParsingException("No flight information impossible to process PTM message.");

                DateTime messageTimestamp = DateTime.Now;

                if (outbounds.Count > 0)
                {
                    foreach (Match outbound in outbounds)
                    {

                        messageObject = (IPTMTTYTable)Activator.CreateInstance(Type.GetType(ttyCollection.GetTTYElement("PTM").entityName));

                        BagTMLog.LogDebug(
                                String.Format("BagTM Queue Message Parsing PTM TTY Message flight {0}", flight.Value), this);

                        parameter = flight.Value.Substring(4, flight.Length - 10);
                        methodName = configFlight.methodName;
                        // Not necessary if parameter is null since no change to object
                        if (parameter != null) messageObject.SetValue(methodName, parameter);

                        TTYComponentConfigElement configOutbound = ttyCollection.GetTTYElement("PTM").ttyElements.GetTTYElementElement("default").ttycomponents.GetTTYElementElement("Outbounds");

                        BagTMLog.LogDebug(
                            String.Format("BagTM Queue Message Parsing PTM TTY Message flight {0} and outbound {1}", flight.Value, outbound.Value), this);
                        parameter = outbound.Value;
                        methodName = configOutbound.methodName;
                        // Not necessary if parameter is null since no change to object
                        if (parameter != null) messageObject.SetValue(methodName, parameter);

                        // Create timestamp message identifier
                        messageObject.SetValue("Stamp", messageTimestamp.ToString());

                        // Se o objeto estiver instanciado então foi preenchido e deve ser guardado em base de dados
                        if (messageObject != null)
                        {
                            BagTMLog.LogInfo(
                                    String.Format("BagTM Queue Message PTM Message Outbound Parsed {0}", messageObject), this);
                            messageObject.Save(db, hub);
                        }
                    }

                }
                else
                {
                    messageObject = (IPTMTTYTable)Activator.CreateInstance(Type.GetType(ttyCollection.GetTTYElement("PTM").entityName));

                    BagTMLog.LogDebug(
                            String.Format("BagTM Queue Message Parsing PTM TTY Message flight {0}", flight.Value), this);

                    parameter = flight.Value.Substring(4, flight.Length - 10);
                    methodName = configFlight.methodName;
                    // Not necessary if parameter is null since no change to object
                    if (parameter != null) messageObject.SetValue(methodName, parameter);

                    // Se o objeto estiver instanciado então foi preenchido e deve ser guardado em base de dados
                    if (messageObject != null)
                    {
                        BagTMLog.LogInfo(
                                String.Format("BagTM Queue Message PTM Message Parsed {0}", messageObject), this);
                        messageObject.Save(db, hub);
                    }
                }

                return ((PTMTTYTable)messageObject).getOSUSR_UUK_PAXMSGS();

            } catch (Exception e)
            {
                BagTMLog.LogError("BagTM Queue Message Parsing PTM TTY Parser Error", this, e);
                
                throw e;
            }
            
        }
 public static void OnActivationDeletedEvent(object sender, AgendaEventArgs e)
 {
     BagTMLog.LogDebug(
         String.Format("BagTM Engine Processing Rules Events Fact about to Delete {0}", e.Rule.Name), sender);
 }