示例#1
0
        public EncoderData ValidateAnyDataType(DataHub _oDataHub)
        {
            string sNameOfType;

            oResult = new EncoderData();
            DataType oDataType = new DataType();

            Console.Write("Enter a name of Type: ");
            sNameOfType = Console.ReadLine().ToUpper();
            if (sNameOfType != "SEQUENCE")
            {
                oDataType = _oDataHub.FindDataTypeByName(sNameOfType);
                if (oDataType != null)
                {
                    oResult = Validate("\n\nFound Data Type " +
                                       oDataType.TypeName, oDataType, _oDataHub);
                }
                else
                {
                    oResult.sErrorDescription = "Data Type " + sNameOfType + " not found!";
                    oResult.bCanEncode        = false;
                }
            }
            else
            {
                Console.WriteLine("\n\nCreate a sequence to encode.");
                oDataType = CreateSequence(_oDataHub);
                oResult   = Validate("\n\nCreated Sequence: ", oDataType, _oDataHub);
            }

            return(oResult);
        }
示例#2
0
        private DataType FindParrent(DataHub _oDataHub, string ParrentName)
        {
            DataType _oDataType = new DataType();

            _oDataType = _oDataHub.FindDataTypeByName(ParrentName);
            return(_oDataType.oOtherData.TagNumber != 0 ?
                   _oDataType : FindParrent(_oDataHub, _oDataType.oOtherData.ParrentType));
        }
示例#3
0
        private DataType CreateSequence(DataHub oDataHub)
        {
            int      iSequenceIndex   = 0;
            DataType _oDataType       = CloneDataType(oDataHub.FindDataTypeByName("SEQUENCE"));
            bool     SequenceComplete = false;
            string   SequenceChoice   = string.Empty;
            string   sDataTypeName;

            while (!SequenceComplete)
            {
                SequenceChoice = string.Empty;
                Console.Write("\nEnter a {0} Data Type name: ", iSequenceIndex++);
                _oDataType.oSequence.lElements.Add(new SequenceElement());
                _oDataType.oSequence.lElements.Last().ElementName = iSequenceIndex.ToString();
                sDataTypeName = Console.ReadLine().ToUpper();
                if (sDataTypeName == "SEQUENCE")
                {
                    Console.WriteLine("\n\n────────────────────────────────────────────────────\n" +
                                      "Create a new sequence at {0} position of parent sequence." +
                                      "\n─────────────────────────────────────────────────────────────", iSequenceIndex);
                    _oDataType.oSequence.lElements.Last().ElementType = CreateSequence(oDataHub);
                }
                else
                {
                    _oDataType.oSequence.lElements.Last().ElementType = oDataHub.FindDataTypeByName(sDataTypeName);
                }
                while (SequenceChoice != "Y" && SequenceChoice != "y" && SequenceChoice != "N" && SequenceChoice != "n")
                {
                    Console.WriteLine("\n\nNext data type in sequece? (Y/N)");
                    Console.Write("\n=>");
                    SequenceChoice = Console.ReadLine();
                }
                if (SequenceChoice == "N" || SequenceChoice == "n")
                {
                    SequenceComplete = true;
                    Console.WriteLine("\n────────────────────────────────────────────────────" +
                                      "\nEnd of Sequence.\n────────────────────────────────────────────────────");
                }
            }
            return(_oDataType);
        }
示例#4
0
        private Tuple <DataType, string> FindParrent(string _Class, int _TagNumber)
        {
            string TypeName;
            var    ParrentDataType = oDataHub.FindDataTypeByTag(_Class, _TagNumber);

            if (ParrentDataType != null)
            {
                if (ParrentDataType.oOtherData.ParrentType == null)
                {
                    TypeName = ParrentDataType.TypeName;
                }
                else
                {
                    var OriginParrent = oDataHub.FindDataTypeByName(ParrentDataType.oOtherData.ParrentType);
                    while (OriginParrent.oOtherData.ParrentType != null)
                    {
                        OriginParrent = oDataHub.FindDataTypeByName(OriginParrent.oOtherData.ParrentType);
                    }
                    TypeName = OriginParrent.TypeName;
                }
                return(Tuple.Create(ParrentDataType, TypeName));
            }
            return(null);
        }
示例#5
0
        public EncoderData Validate(string _title, DataType _oDataType, DataHub _oDataHub)
        {
            //Console.WriteLine("Iteration: " + iteration);
            //Console.WriteLine("Count: " + oResult.ValueToEncode.Count);
            if (_oDataType != null)
            {
                if (iteration == 0)
                {
                    if (!bSendDataType)
                    {
                        oResult.ValueToEncode.Add(string.Empty);
                        oResult._oDataType = _oDataType;
                        bSendDataType      = true;
                    }
                }
                if (_oDataType.oSequence.lElements.Count > 1 || _oDataType.oSequence.lElements.Count == 0)
                {
                    Console.WriteLine(_title);
                    Console.WriteLine("────────────────────────────────────────────────────");
                    _oDataType.PresentData(1);
                    Console.WriteLine("────────────────────────────────────────────────────");
                }
                Console.ForegroundColor = ConsoleColor.Gray;
                if (_oDataType.TypeName == "INTEGER")
                {
                    oResult.bCanEncode = IntegerValidation(_oDataType);
                    return(oResult);
                }
                else if (_oDataType.TypeName == "OCTET STRING")
                {
                    oResult.bCanEncode = OctetStringValidation(_oDataType);
                    return(oResult);
                }
                else if (_oDataType.TypeName == "OBJECT IDENTIFIER")
                {
                    oResult.bCanEncode = ObjectIdentifierValidation(_oDataType);
                    return(oResult);
                }
                else if (_oDataType.TypeName == "NULL")
                {
                    oResult.bCanEncode = true;
                    return(oResult);
                }
                else if (_oDataType.TypeName == "BOOLEAN")
                {
                    oResult.bCanEncode = BooleanValidation(_oDataType);
                    return(oResult);
                }
                else if (_oDataType.oSequence.lElements.Count() == 0)
                {
                    if (!_oDataType.EmptyCheck(_oDataType.oOtherData.ParrentType))
                    {
                        DataType oNewDataType = new DataType();
                        oNewDataType = CloneDataType(_oDataHub.FindDataTypeByName(_oDataType.oOtherData.ParrentType));
                        if (oNewDataType != null)
                        {
                            if (_oDataType.oRange.Max != 0)
                            {
                                if (oNewDataType.oRange.Max > _oDataType.oRange.Max || oNewDataType.oRange.Max == 0)
                                {
                                    oNewDataType.oRange.Max = _oDataType.oRange.Max;
                                }
                                if (oNewDataType.oRange.Min < _oDataType.oRange.Min)
                                {
                                    oNewDataType.oRange.Min = _oDataType.oRange.Min;
                                }
                            }
                            if (_oDataType.oSize.Size != 0)
                            {
                                if (oNewDataType.oSize.Size > _oDataType.oSize.Size || oNewDataType.oSize.Size == 0)
                                {
                                    oNewDataType.oSize.Size = _oDataType.oSize.Size;
                                }
                            }
                        }

                        if (Validate("Parrent of Data Type " + _oDataType.TypeName + " with child restrictions", oNewDataType, _oDataHub).bCanEncode)
                        {
                            if (oNewDataType.TypeName == "INTEGER")
                            {
                                oResult.bCanEncode = IntegerValidation(_oDataType, Int64.Parse(oResult.ValueToEncode[iteration]));
                                return(oResult);
                            }
                            if (oNewDataType.TypeName == "OCTET STRING")
                            {
                                oResult.bCanEncode = OctetStringValidation(_oDataType, oResult.ValueToEncode[iteration]);
                                return(oResult);
                            }
                            if (oNewDataType.TypeName == "OBJECT IDENTIFIER")
                            {
                                oResult.bCanEncode = ObjectIdentifierValidation(_oDataType, oResult.ValueToEncode[iteration]);
                                return(oResult);
                            }
                            if (oNewDataType.TypeName == "BOOLEAN")
                            {
                                oResult.bCanEncode = BooleanValidation(_oDataType, oResult.ValueToEncode[iteration]);
                                return(oResult);
                            }
                        }
                        return(oResult);
                    }
                }
                else if (_oDataType.oSequence.lElements.Count > 0)
                {
                    foreach (SequenceElement _SequenceElement in _oDataType.oSequence.lElements)
                    {
                        if (_SequenceElement != _oDataType.oSequence.lElements[0])
                        {
                            oResult.ValueToEncode.Add(string.Empty);
                        }
                        if (!Validate("\n\n" + (_oDataType.oSequence.lElements.IndexOf(_SequenceElement) + 1)
                                      + " element of Sequence:", _SequenceElement.ElementType, _oDataHub).bCanEncode)
                        {
                            oResult.bCanEncode = false;
                            return(oResult);
                        }
                        if (!(_SequenceElement == _oDataType.oSequence.lElements.Last()))
                        {
                            iteration++;
                        }
                    }
                    oResult.bCanEncode = true;
                    return(oResult);
                }
                oResult.sErrorDescription = "Parameters of Data Type is not recognized!";
                oResult.bCanEncode        = false;
                return(oResult);
            }
            else
            {
                oResult.sErrorDescription = "Data Type of chosen Object not found!";
                oResult.bCanEncode        = false;
                return(oResult);
            }
        }
示例#6
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());
            }
        }