public string FormatRecord(CdrElement record)
        {
            IList<CdrElement> childs = record.GetAllChilds();
            if ((childs == null) || (childs.Count == 0)) return String.Empty;

            StringBuilder builder = new StringBuilder();
            FormatterColumn column;
            string fieldValue;

            for (int i = 0; i < _settings.ColumnCount; i++)
            {
                column = _settings.GetColumnAt(i);
                fieldValue = String.Empty;
                foreach (CdrElement element in childs)
                {
                    if (String.Equals(element.Path, column.Definition.Path))
                    {
                        if (!String.IsNullOrEmpty(fieldValue))
                        {
                            fieldValue = String.Format("{0} | {1}", fieldValue, element.Parselet.Value(column.Definition.ValueType, element));
                        }
                        else
                        {
                            fieldValue = element.Parselet.Value(column.Definition.ValueType, element);
                        }
                    }
                }

                builder.AppendFormat(_settings.Format, fieldValue);
            }
            return builder.ToString();
        }
예제 #2
0
        protected void CheckElement(CdrElement element, ElementsStatTable tablePresent, ElementsStatTable tableNone)
        {
            if (element.Path.Equals(element.Name) || (element.Name.Length == 0))
            {
                if (tableNone.ContainsKey(element.Path))
                {
                    tableNone[element.Path]++;
                }
                else
                {
                    tableNone.Add(element.Path, 1);
                }
            }
            else
            {
                if (tablePresent.ContainsKey(element.Path))
                {
                    tablePresent[element.Path]++;
                }
                else
                {
                    tablePresent.Add(element.Path, 1);
                }
            }

            if (element.IsConstructed && !element.IsEmpty)
            {
                foreach (CdrElement child in (element.Value as List <CdrElement>))
                {
                    CheckElement(child, tablePresent, tableNone);
                }
            }
        }
예제 #3
0
        private void ParseElement(CdrElement element)
        {
            ICdrElementDefinition elementDef = DefinitionProvider.FindDefinition(element.Path);
            if (elementDef != null)
            {
                if (elementDef.Name.Length != 0)
                {
                    element.Name = elementDef.Name;
                }

                if (elementDef.Parselet.Length > 0)
                {
                    IParselet parselet = ParseletProvider.FindParselet(elementDef.Parselet);
                    if (parselet != null)
                    {
                        element.Parselet = parselet;
                        element.DefaultValueType = elementDef.ValueType;
                    }
                }
            }

            if (element.Parselet == null && !element.IsConstructed)
            {
                element.Parselet = ParseletProvider.Instance.FindParselet("GenericParselet");
            }

            if ((element.IsConstructed) && (!element.IsEmpty))
            {
                foreach (CdrElement e in (element.Value as List<CdrElement>))
                {
                    this.ParseElement(e);
                }
            }
        }
예제 #4
0
        private void ParseElement(CdrElement element)
        {
            ICdrElementDefinition elementDef = DefinitionProvider.FindDefinition(element.Path);

            if (elementDef != null)
            {
                if (elementDef.Name.Length != 0)
                {
                    element.Name = elementDef.Name;
                }

                if (elementDef.Parselet.Length > 0)
                {
                    IParselet parselet = ParseletProvider.FindParselet(elementDef.Parselet);
                    if (parselet != null)
                    {
                        element.Parselet         = parselet;
                        element.DefaultValueType = elementDef.ValueType;
                    }
                }
            }

            if (element.Parselet == null && !element.IsConstructed)
            {
                element.Parselet = ParseletProvider.Instance.FindParselet("GenericParselet");
            }

            if ((element.IsConstructed) && (!element.IsEmpty))
            {
                foreach (CdrElement e in (element.Value as List <CdrElement>))
                {
                    this.ParseElement(e);
                }
            }
        }
예제 #5
0
        public CdrElement DecodeRecord(Stream asnStream, bool searchSignature)
        {
            TlvObject tlv;
            long      offset = asnStream.Position;

            if (searchSignature && (_cdrSignatures != null))
            {
                int  b   = asnStream.ReadByte();
                bool res = false;
                foreach (byte sgn in _cdrSignatures)
                {
                    if (b == sgn)
                    {
                        res = true;
                        break;
                    }
                }
                if (!res)
                {
                    return(null);
                }
                asnStream.Seek(-1, SeekOrigin.Current);
            }

            BerDecoderResult pr = DecodeTlv(asnStream, out tlv, ref offset, 0, byte.MaxValue);

            CdrElement record = null;

            if ((pr == BerDecoderResult.Finished) && (_tlvParser != null))
            {
                record = _tlvParser.ParseTlvObject(tlv);;
            }

            return(record);
        }
예제 #6
0
        public static CdrElement CreateFromTlv(TlvObject tlv)
        {
            CdrElement element = new CdrElement();

            element._offset        = tlv.Offset;
            element._path          = tlv.Path;
            element._name          = tlv.Path;
            element._isConstructed = tlv.IsConstructed;
            if (!tlv.IsEmpty)
            {
                if (tlv.IsConstructed)
                {
                    List <CdrElement> val = new List <CdrElement>((tlv.Value as List <TlvObject>).Count);
                    foreach (TlvObject ch in (tlv.Value as List <TlvObject>))
                    {
                        val.Add(CdrElement.CreateFromTlv(ch));
                    }
                    ;
                    element._value = val;
                }
                else
                {
                    byte[] src = (tlv.Value as byte[]);
                    byte[] dst = new byte[src.Length];
                    Array.Copy(src, dst, src.Length);
                    element._value = dst;
                }
            }

            return(element);
        }
예제 #7
0
        public CdrElement ParseTlvObject(TlvObject tlv)
        {
            CdrElement element = CdrElement.CreateFromTlv(tlv);

            this.ParseElement(element);

            return(element);
        }
예제 #8
0
        public string FormatRecord(CdrElement record)
        {
            IList <CdrElement> childs = record.GetAllChilds();

            if ((childs == null) || (childs.Count == 0))
            {
                return(String.Empty);
            }

            StringBuilder   builder = new StringBuilder();
            FormatterColumn column;
            string          fieldValue;

            for (int i = 0; i < _settings.ColumnCount; i++)
            {
                column     = _settings.GetColumnAt(i);
                fieldValue = String.Empty;
                foreach (CdrElement element in childs)
                {
                    if (String.Equals(element.Path, column.Definition.Path))
                    {
                        if (!String.IsNullOrEmpty(fieldValue))
                        {
                            fieldValue = String.Format("{0} | {1}", fieldValue, element.Parselet.Value(column.Definition.ValueType, element));
                        }
                        else
                        {
                            fieldValue = element.Parselet.Value(column.Definition.ValueType, element);
                        }
                    }
                }

                builder.AppendFormat(_settings.Format, fieldValue);
            }
            return(builder.ToString());
        }
예제 #9
0
        public static CdrElement CreateFromTlv(TlvObject tlv)
        {
            CdrElement element = new CdrElement();
            element._offset = tlv.Offset;
            element._path = tlv.Path;
            element._name = tlv.Path;
            element._isConstructed = tlv.IsConstructed;
            if (!tlv.IsEmpty)
            {
                if (tlv.IsConstructed)
                {
                    List<CdrElement> val = new List<CdrElement>((tlv.Value as List<TlvObject>).Count);
                    foreach (TlvObject ch in (tlv.Value as List<TlvObject>))
                    {
                        val.Add(CdrElement.CreateFromTlv(ch));
                    };
                    element._value = val;
                }
                else
                {
                    byte[] src = (tlv.Value as byte[]);
                    byte[] dst = new byte[src.Length];
                    Array.Copy(src, dst, src.Length);
                    element._value = dst;
                }
            }

            return element;
        }
        protected void CheckElement(CdrElement element, ElementsStatTable tablePresent, ElementsStatTable tableNone)
        {
            if (element.Path.Equals(element.Name) || (element.Name.Length == 0))
            {
                if (tableNone.ContainsKey(element.Path))
                {
                    tableNone[element.Path]++;
                }
                else
                {
                    tableNone.Add(element.Path, 1);
                }
            }
            else
            {
                if (tablePresent.ContainsKey(element.Path))
                {
                    tablePresent[element.Path]++;
                }
                else
                {
                    tablePresent.Add(element.Path, 1);
                }
            }

            if (element.IsConstructed && !element.IsEmpty)
            {
                foreach (CdrElement child in (element.Value as List<CdrElement>))
                    CheckElement(child, tablePresent, tableNone);
            }
        }