コード例 #1
0
        /// <summary>
        /// Impports all the packets for a given message
        /// </summary>
        /// <param name="aMessage"></param>
        private void importPackets(DataDictionary.Tests.DBElements.DBMessage aMessage, int TCS_order)
        {
            string sql = "SELECT TCSOrder, MessageOrder, Pac_ID, Var_Name, Var_Value FROM TSW_MessageBody ORDER BY MessageOrder, Var_Row";

            OleDbDataAdapter adapter = new OleDbDataAdapter(sql, Connection);
            DataSet          dataSet = new DataSet();

            adapter.Fill(dataSet);

            int packetNumber = 0;

            DataDictionary.Tests.DBElements.DBPacket packet = (DataDictionary.Tests.DBElements.DBPacket)DataDictionary.Generated.acceptor.getFactory().createDBPacket();
            if (dataSet.Tables.Count > 0)
            {
                foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                {
                    object[] items        = dataRow.ItemArray;
                    int      order        = (int)items[0];
                    short    messageOrder = (short)items[1];
                    if (order == TCS_order && messageOrder == aMessage.MessageOrder)
                    {
                        short pacId = (short)items[2];
                        if (packetNumber != pacId)
                        {
                            if (packetNumber != 0)
                            {
                                aMessage.AddPacket(packet);
                            }
                            packet       = (DataDictionary.Tests.DBElements.DBPacket)DataDictionary.Generated.acceptor.getFactory().createDBPacket();
                            packetNumber = pacId;
                        }
                        DataDictionary.Tests.DBElements.DBField field = (DataDictionary.Tests.DBElements.DBField)DataDictionary.Generated.acceptor.getFactory().createDBField();
                        string variable = items[3] as string;
                        if (variable != null)
                        {
                            field.Variable = variable;
                        }
                        string value = items[4] as string;
                        if (value != null)
                        {
                            field.Value = DataDictionary.Tests.Translations.Translation.format_decimal(value);
                        }
                        packet.AddField(field);
                    }
                }
                if (packet != null)
                {
                    aMessage.AddPacket(packet);
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Impports all the packets for a given message
        /// </summary>
        /// <param name="aMessage"></param>
        /// <param name="TCS_order"></param>
        // ReSharper disable once InconsistentNaming
        private void ImportPackets(DBMessage aMessage, int TCS_order)
        {
            string sql = "SELECT Pac_ID, Var_Name, Var_Value FROM TSW_MessageBody WHERE (TCSOrder = " + TCS_order +
                         ") AND (MessageOrder = " + aMessage.MessageOrder + ") ORDER BY Var_Row";

            OleDbDataAdapter adapter = new OleDbDataAdapter(sql, Connection);
            DataSet          dataSet = new DataSet();

            adapter.Fill(dataSet);

            DBPacket packet = null;

            if (dataSet.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                {
                    object[] items = dataRow.ItemArray;
                    if ("NID_PACKET".Equals(items[1]))
                    {
                        if (packet != null)
                        {
                            aMessage.AddPacket(packet);
                        }
                        packet = (DBPacket)acceptor.getFactory().createDBPacket();
                    }

                    if (packet != null)
                    {
                        DBField field    = (DBField)acceptor.getFactory().createDBField();
                        string  variable = items[1] as string;
                        if (variable != null)
                        {
                            field.Variable = variable;
                        }
                        string value = items[2] as string;
                        if (value != null)
                        {
                            field.Value = VariableConverter.INSTANCE.Convert(variable, value).ToString();
                        }
                        packet.AddField(field);
                    }
                }

                if (packet != null)
                {
                    aMessage.AddPacket(packet);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Imports all the messages used by this step
        /// </summary>
        /// <param name="aStep"></param>
        private void importStepMessages(DataDictionary.Tests.Step aStep)
        {
            string sql = "SELECT TCSOrder, MessageOrder, MessageType, Var_Name, Var_Value FROM TSW_MessageHeader ORDER BY MessageOrder, Var_Row";

            OleDbDataAdapter adapter = new OleDbDataAdapter(sql, Connection);
            DataSet          dataSet = new DataSet();

            adapter.Fill(dataSet);
            if (dataSet.Tables.Count > 0)
            {
                int messageNumber = 0;
                DataDictionary.Tests.DBElements.DBMessage message = null;
                int order = -1;
                foreach (DataRow dataRow in dataSet.Tables[0].Rows)
                {
                    object[] items = dataRow.ItemArray;
                    order = (int)items[0];
                    if (order == aStep.getTCS_Order())
                    {
                        short messageOrder = (short)items[1];
                        if (messageNumber != messageOrder)  // we create a new Message
                        {
                            if (messageNumber != 0)
                            {
                                aStep.AddMessage(message);
                                importPackets(message, order);
                            }
                            short messageTypeNumber = (short)items[2];
                            DataDictionary.Generated.acceptor.DBMessageType messageType = DataDictionary.Generated.acceptor.DBMessageType.defaultDBMessageType;
                            switch (messageTypeNumber)
                            {
                            case 0:
                                messageType = DataDictionary.Generated.acceptor.DBMessageType.aEUROBALISE;
                                break;

                            case 1:
                                messageType = DataDictionary.Generated.acceptor.DBMessageType.aEUROLOOP;
                                break;

                            case 2:
                                messageType = DataDictionary.Generated.acceptor.DBMessageType.aEURORADIO;
                                break;
                            }
                            message = (DataDictionary.Tests.DBElements.DBMessage)DataDictionary.Generated.acceptor.getFactory().createDBMessage();
                            message.MessageOrder = messageOrder;
                            message.MessageType  = messageType;
                            messageNumber        = messageOrder;
                        }
                        DataDictionary.Tests.DBElements.DBField field = (DataDictionary.Tests.DBElements.DBField)DataDictionary.Generated.acceptor.getFactory().createDBField();
                        string variable = items[3] as string;
                        if (variable != null)
                        {
                            field.Variable = variable;
                        }
                        string value = items[4] as string;
                        if (value != null)
                        {
                            field.Value = DataDictionary.Tests.Translations.Translation.format_decimal(value);
                        }
                        message.AddField(field);
                    }
                }
                if (message != null)
                {
                    aStep.AddMessage(message);
                    importPackets(message, aStep.getTCS_Order());
                }
            }
        }
コード例 #4
0
        private static IValue FillDefaultPacket(DBMessage message, IVariable structure)
        {
            IValue retVal = structure.Value;

            if (isPacket(structure))
            {
                Structure      defaultPacketType = (Structure)structure.Type;
                StructureValue defaultPacket     = new StructureValue(defaultPacketType);

                NameSpace packetNameSpace = structure.NameSpace;

                foreach (DBPacket packet in message.Packets)
                {
                    DBField nidPacketField = packet.Fields[0] as DBField;
                    int     packetID       = int.Parse(nidPacketField.Value);

                    Structure packetType = (Structure)FindStructure(packetID).Type;

                    if (packetType == defaultPacketType)
                    {
                        int defaultPacketIndex = 0;
                        FillStructure(packetNameSpace, packet.Fields, ref defaultPacketIndex, defaultPacket);

                        retVal = defaultPacket;
                    }
                }
            }
            else
            {
                Structure      structureType = structure.Type as Structure;
                StructureValue Structure     = new StructureValue(structureType);
                if (Structure != null)
                {
                    foreach (KeyValuePair <string, IVariable> subVariable in Structure.SubVariables)
                    {
                        if (isPacket(subVariable.Value))
                        {
                            Structure      defaultPacketType = (Structure)subVariable.Value.Type;
                            StructureValue defaultPacket     = new StructureValue(defaultPacketType);

                            NameSpace packetNameSpace = subVariable.Value.NameSpace;

                            foreach (DBPacket packet in message.Packets)
                            {
                                DBField nidPacketField = packet.Fields[0] as DBField;
                                int     packetID       = int.Parse(nidPacketField.Value);

                                Structure packetType = (Structure)FindStructure(packetID).Type;

                                if (packetType == defaultPacketType)
                                {
                                    int defaultPacketIndex = 0;
                                    FillStructure(packetNameSpace, packet.Fields, ref defaultPacketIndex, defaultPacket);

                                    Structure.GetVariable(subVariable.Value.Name).Value = defaultPacket;
                                }
                            }
                        }
                    }
                    retVal = Structure;
                }
            }

            return(retVal);
        }
コード例 #5
0
        private static string format_euroradio_message(DBMessage message)
        {
            EfsSystem system = EfsSystem.Instance;

            NameSpace rbcRoot = findNameSpace("Messages.MESSAGE");

            // Get the EFS namespace corresponding to the message
            // Select the appropriate message type, tracktotrain or traintotrack
            DBField nidMessage = message.Fields[0] as DBField;
            string  msg_id     = get_namespace_from_ID(nidMessage.Value);

            NameSpace nameSpace = OverallNameSpaceFinder.INSTANCE.findByName(rbcRoot, msg_id);

            if (nameSpace == null)
            {
                throw new Exception("Message type not found in EFS");
            }

            // The EURORADIO messages are defined in the namespaces TRACK_TO_TRAIN and TRAIN_TO_TRACK, which enclose the specific message namespaces
            // So we get the message type from nameSpace.EnclosingNameSpace and the actual structure corresponding to the message in nameSpace
            Structure      enclosingStructureType = (Structure)system.FindType(nameSpace.EnclosingNameSpace, "Message");
            StructureValue Message = new StructureValue(enclosingStructureType);


            // Within the message, get the appropriate field and get that structure
            Structure      structureType = (Structure)system.FindType(nameSpace, "Message");
            StructureValue structure     = new StructureValue(structureType);


            // Fill the structure
            int currentIndex = 0;

            FillStructure(nameSpace, message.Fields, ref currentIndex, structure);

            // Fill the default packets
            int translatedPackets = 0;

            foreach (KeyValuePair <string, IVariable> subVariable in structure.SubVariables)
            {
                if (subVariable.Value.TypeName.EndsWith("Message"))
                {
                    // The structure of packets will always be a Message, but in some cases, it is a message that contains
                    // the different options for a single field in the message
                    structure.GetVariable(subVariable.Value.Name).Value = FillDefaultPacket(message, subVariable.Value);

                    translatedPackets++;
                }
            }

            // and fill the packets
            IVariable subSequenceVariable;

            if (structure.SubVariables.TryGetValue("Sequence1", out subSequenceVariable) &&
                message.Packets.Count > translatedPackets)
            {
                subSequenceVariable.Value = get_message_packets(message, nameSpace, system);
            }


            // Fill the correct field in Message with the structure.
            foreach (KeyValuePair <string, IVariable> pair in Message.SubVariables)
            {
                if (msg_id.EndsWith(pair.Key))
                {
                    pair.Value.Type  = structureType;
                    pair.Value.Value = structure;
                }
            }

            return(Message.Name);
        }
コード例 #6
0
        /// <summary>
        ///     Fills the given structure with the values provided from the database
        /// </summary>
        /// <param name="aNameSpace">Namespace of the structure</param>
        /// <param name="fields">Fields to be copied into the structure</param>
        /// <param name="index">Index (of fields list) from which we have to start copying</param>
        /// <param name="aStructure">The structure to be filled</param>
        private static void FillStructure(NameSpace aNameSpace, ArrayList fields, ref int currentIndex,
                                          StructureValue aStructure)
        {
            EfsSystem system = EfsSystem.Instance;

            int j = 0;

            while (currentIndex < fields.Count)
            {
                DBField field = fields[currentIndex] as DBField;

                KeyValuePair <string, IVariable> pair = aStructure.SubVariables.ElementAt(j);
                IVariable variable = pair.Value;

                // conditional variables can be missing in the database fields, but present in our structure => skip them
                while (!variable.Name.StartsWith(field.Variable) && j < aStructure.SubVariables.Count - 1)
                {
                    j++;
                    pair     = aStructure.SubVariables.ElementAt(j);
                    variable = pair.Value;
                }

                // We use StartsWith and not Equals because we can have N_ITER_1 and N_ITER
                if (variable.Name.StartsWith(field.Variable))
                {
                    if (variable.Type is Enum)
                    {
                        Enum type = variable.Type as Enum;
                        foreach (EnumValue enumValue in type.Values)
                        {
                            int value = int.Parse(enumValue.getValue());
                            int other = int.Parse(field.Value);
                            if (value == other)
                            {
                                variable.Value = enumValue;
                                j++;
                                break;
                            }
                        }
                    }
                    else if (variable.Type is Range)
                    {
                        Range  type = variable.Type as Range;
                        object v    = VariableConverter.INSTANCE.Convert(variable.Name, field.Value);

                        string stringValue = v as string;
                        if (stringValue != null)
                        {
                            int intValue;
                            if (int.TryParse(stringValue, out intValue))
                            {
                                v = intValue;
                            }
                        }
                        variable.Value = new IntValue(type, (int)v);
                        j++;
                    }
                    else if (variable.Type is StringType)
                    {
                        StringType type = variable.Type as StringType;
                        variable.Value = new StringValue(type, field.Value);
                        j++;
                    }
                    else
                    {
                        throw new Exception("Unhandled variable type");
                    }

                    if (variable.Name.StartsWith("N_ITER")) // we have to create a sequence
                    {
                        KeyValuePair <string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                        IVariable  sequenceVariable = sequencePair.Value;
                        Collection collectionType   = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName);
                        ListValue  sequence         = new ListValue(collectionType, new List <IValue>());

                        int value = int.Parse(field.Value);
                        for (int k = 0; k < value; k++)
                        {
                            currentIndex++;
                            Structure structureType =
                                (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                            StructureValue structureValue = new StructureValue(structureType);
                            FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                            sequence.Val.Add(structureValue);
                        }
                        sequenceVariable.Value = sequence;
                        j++;
                    }
                }

                // Special case for X_TEXT
                if ("Sequence1".Equals(variable.Name) && "X_TEXT".Equals(field.Variable))
                {
                    KeyValuePair <string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j);
                    IVariable  sequenceVariable = sequencePair.Value;
                    Collection collectionType   = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName);
                    ListValue  sequence         = new ListValue(collectionType, new List <IValue>());
                    while (field != null && "X_TEXT".Equals(field.Variable))
                    {
                        if (string.IsNullOrEmpty(field.Value))
                        {
                            field.Value = " ";
                        }
                        Structure structureType =
                            (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName);
                        StructureValue structureValue = new StructureValue(structureType);
                        FillStructure(aNameSpace, fields, ref currentIndex, structureValue);
                        sequence.Val.Add(structureValue);
                        currentIndex += 1;
                        if (currentIndex < fields.Count)
                        {
                            field = fields[currentIndex] as DBField;
                        }
                        else
                        {
                            field = null;
                        }
                    }
                    sequenceVariable.Value = sequence;
                    j++;
                }

                // if all the fields of the structue are filled, we terminated
                if (j == aStructure.SubVariables.Count)
                {
                    break;
                }
                else
                {
                    currentIndex += 1;
                }
            }
        }
コード例 #7
0
        private static ListValue get_message_packets(DBMessage message, NameSpace nameSpace, EfsSystem system)
        {
            ListValue retVal;

            Collection collectionType    = (Collection)system.FindType(nameSpace, "Collection1");
            Structure  subStructure1Type = (Structure)system.FindType(nameSpace, "SubStructure1");

            string packetLocation = "Messages.PACKET.";

            if (nameSpace.FullName.Contains("TRAIN_TO_TRACK"))
            {
                packetLocation += "TRAIN_TO_TRACK.Message";
            }
            else
            {
                packetLocation += "TRACK_TO_TRAIN.Message";
            }

            Structure packetStructureType = (Structure)system.FindType(nameSpace, packetLocation);

            retVal = new ListValue(collectionType, new List <IValue>());

            foreach (DBPacket packet in message.Packets)
            {
                DBField nidPacketField = packet.Fields[0] as DBField;
                if (nidPacketField.Value != "255") // 255 means "end of information"
                {
                    int            packetId     = int.Parse(nidPacketField.Value);
                    StructureValue subStructure = FindStructure(packetId);

                    int currentIndex = 0;
                    FillStructure(nameSpace, packet.Fields, ref currentIndex, subStructure);

                    StructureValue subStructure1 = new StructureValue(subStructure1Type);

                    // For Balise messages, we have an extra level of information to fill, so here we define StructureVal in one of two ways
                    StructureValue structureVal;
                    if (subStructure1.SubVariables.Count == 1 &&
                        subStructure1.SubVariables.ContainsKey("TRACK_TO_TRAIN"))
                    {
                        // For a Balise message, we have an extra level of structures for TRACK_TO_TRAIN
                        structureVal = new StructureValue(packetStructureType);

                        subStructure1.SubVariables["TRACK_TO_TRAIN"].Value = structureVal;
                    }
                    else
                    {
                        // For RBC, the collection directly holds the different packet types
                        structureVal = subStructure1;
                    }

                    // Find the right variable in the packet to add the structure we just created
                    foreach (KeyValuePair <string, IVariable> pair in structureVal.SubVariables)
                    {
                        string variableName = pair.Key;
                        if (subStructure.Structure.FullName.Contains(variableName))
                        {
                            pair.Value.Value = subStructure;

                            retVal.Val.Add(subStructure1);

                            break;
                        }
                    }
                }
            }

            return(retVal);
        }