Exemplo n.º 1
0
        private byte[] DataTypeClassification(DataType _oDataType, List <string> _ValueToEncode, DataHub _oDataHub)
        {
            int    iTagNumber = 0;
            string sClass     = null;

            if (_oDataType.oSequence.lElements.Count == 0)
            {
                if (_oDataType.oOtherData.ParrentType == null)
                {
                    return(_oDataType.oOtherData.Class != null?
                           Encode(_ValueToEncode[iteration], _oDataType.oOtherData.Class, _oDataType.oOtherData.TagNumber, _oDataType.oOtherData.TagNumber) :
                               Encode(_ValueToEncode[iteration], "CONTEXT-SPECIFIC", _oDataType.oOtherData.TagNumber, _oDataType.oOtherData.TagNumber));
                }
                else
                {
                    if (_oDataType.oOtherData.EncodingType == "EXPLICIT")
                    {
                        int    iParrentTagNumber = 0;
                        string sParrentClass     = null;

                        iTagNumber = ClassificationIdentifier(_oDataHub, _oDataType).Key;
                        sClass     = ClassificationIdentifier(_oDataHub, _oDataType).Value;

                        oDataType         = _oDataHub.FindDataTypeByName(_oDataType.oOtherData.ParrentType);
                        iParrentTagNumber = ClassificationIdentifier(_oDataHub, oDataType).Key;
                        sParrentClass     = ClassificationIdentifier(_oDataHub, oDataType).Value;
                        while (oDataType.oOtherData.ParrentType != null)
                        {
                            oDataType = _oDataHub.FindDataTypeByName(oDataType.oOtherData.ParrentType);
                        }

                        return(Encode(_ValueToEncode[iteration], sClass, sParrentClass, iTagNumber, iParrentTagNumber, oDataType.oOtherData.TagNumber));
                    }
                    else
                    {
                        iTagNumber = ClassificationIdentifier(_oDataHub, _oDataType).Key;
                        sClass     = ClassificationIdentifier(_oDataHub, _oDataType).Value;

                        oDataType = _oDataHub.FindDataTypeByName(_oDataType.oOtherData.ParrentType);
                        while (oDataType.oOtherData.ParrentType != null)
                        {
                            oDataType = _oDataHub.FindDataTypeByName(oDataType.oOtherData.ParrentType);
                        }

                        return(Encode(_ValueToEncode[iteration], sClass, iTagNumber, oDataType.oOtherData.TagNumber));
                    }
                }
            }
            else
            {
                byte[] EncodedIdentifier;
                byte[] EncodedLenght;
                byte[] EncodedContents = new byte[0];

                if (_oDataType.oOtherData.ParrentType == null)
                {
                    EncodedIdentifier = EncodeIdentifier(_oDataType.oOtherData.Class, true, _oDataType.oOtherData.TagNumber);
                }
                else
                {
                    iTagNumber = ClassificationIdentifier(_oDataHub, _oDataType).Key;
                    sClass     = ClassificationIdentifier(_oDataHub, _oDataType).Value;

                    EncodedIdentifier = EncodeIdentifier(sClass, true, iTagNumber);
                }

                foreach (SequenceElement oSequenceElement in _oDataType.oSequence.lElements)
                {
                    if (iteration == 0)
                    {
                        EncodedContents = DataTypeClassification(oSequenceElement.ElementType, _ValueToEncode, _oDataHub);
                    }
                    else
                    {
                        EncodedContents = EncodedContents.Concat(DataTypeClassification(oSequenceElement.ElementType, _ValueToEncode, _oDataHub)).ToArray();
                    }
                    if (oSequenceElement != _oDataType.oSequence.lElements.Last())
                    {
                        iteration++;
                    }
                }

                EncodedLenght = EncodeLenght(EncodedContents);
                PrintEncodedValue(EncodedIdentifier, EncodedLenght, EncodedContents);

                return(EncodedIdentifier.Concat(EncodedLenght.Concat(EncodedContents)).ToArray());
            }
        }