示例#1
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;
            }
            
        }
示例#2
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);
            }
        }