示例#1
0
        /// <summary>
        /// Creates an accessor depending on the format.
        /// </summary>
        /// <param name="start">the zero-based index of the first byte of the accessor</param>
        /// <param name="length">the length of the accessor</param>
        /// <param name="format">the format of the accessor</param>
        /// <param name="encoding">the encoding of the accessed records</param>
        /// <returns>a new accessor with the correct parameters</returns>
        protected object GetAccessor(int start, int length, string format, Encoding encoding)
        {
            object result;

            switch (format)
            {
            case StringFormat:
            case SubstringFormat:
                result = new StringAccessor {
                    Encoding = encoding, Start = start, Length = length
                };
                break;

            case ZonedFormat:
                result = new ZonedAccessor {
                    Encoding = encoding, Length = length, Start = start
                };
                break;

            case PackedFormat:
                result = new PackedAccessor {
                    Encoding = encoding, Length = length, Start = start
                };
                break;

            case SignedBinaryFormat:
                result = new BinaryAccessor {
                    Encoding = encoding, Length = length, Start = start, Signed = true
                };
                break;

            case BinaryFormat:
                result = new BinaryAccessor {
                    Encoding = encoding, Length = length, Start = start, Signed = false
                };
                break;

            default:
                throw new ParsingException("Unknown format: " + format);
            }
            return(result);
        }
示例#2
0
 /// <summary>
 /// Creates an accessor depending on the format.
 /// </summary>
 /// <param name="start">the zero-based index of the first byte of the accessor</param>
 /// <param name="length">the length of the accessor</param>
 /// <param name="format">the format of the accessor</param>
 /// <param name="encoding">the encoding of the accessed records</param>
 /// <returns>a new accessor with the correct parameters</returns>
 protected object GetAccessor(int start, int length, string format, Encoding encoding)
 {
     object result;
     switch (format)
     {
         case StringFormat:
         case SubstringFormat:
             result = new StringAccessor { Encoding = encoding, Start = start, Length = length };
             break;
         case ZonedFormat:
             result = new ZonedAccessor { Encoding = encoding, Length = length, Start = start };
             break;
         case PackedFormat:
             result = new PackedAccessor { Encoding = encoding, Length = length, Start = start };
             break;
         case SignedBinaryFormat:
             result = new BinaryAccessor { Encoding = encoding, Length = length, Start = start, Signed = true };
             break;
         case BinaryFormat:
             result = new BinaryAccessor { Encoding = encoding, Length = length, Start = start, Signed = false };
             break;
         default:
             throw new ParsingException("Unknown format: " + format);
     }
     return result;
 }
示例#3
0
        /// <summary>
        /// Parses an accessor.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <param name="format">the format of the parsed accessor</param>
        /// <returns>an <see cref="IAccessor{T}"/></returns>
        private object ParseAccessor(Lexer lexer, string defaultFormat, out string format)
        {
            var elements = new List<string>();
            format = null;

            do
            {
                elements.Add(lexer.Current);
            } while (lexer.MoveNext() && lexer.Current != ClosingPar &&
                     !LogicalOperators.Contains(lexer.Current) && !ComparisonOperators.Contains(lexer.Current));

            if (elements.Count == 1)
            {
                // decimal constant
                return new ConstantAccessor<decimal> { Constant = decimal.Parse(elements[0]) };
            }
            if (elements.Count == 2 && elements[0] == "C")
            {
                // string constant
                var constant = elements[1].Substring(1, elements[1].Length - 2);
                return new ConstantAccessor<string> { Constant = constant };
            }
            if (elements.Count == 2 && elements[0] == "X")
            {
                // HexaDecimal constant
                var constant = elements[1].Substring(1, elements[1].Length - 2);
                BinaryAccessor accessor =  new BinaryAccessor ();
                int value = Convert.ToInt32(constant, 16);
                byte[] bytes = Enumerable.Range(0, constant.Length).Where(x => x % 2 == 0).Select(x => Convert.ToByte(constant.Substring(x, 2), 16)).ToArray();
                accessor.SetBytes(bytes, bytes, 0);
                decimal constant1 = Convert.ToInt32(constant, 16);

                return new ConstantAccessor<decimal> { Constant = constant1 };     
            }
            // field accesor
            var start = int.Parse(elements[0]) - 1;
            var length = int.Parse(elements[1]);
            format = elements.Count == 3 ? elements[2] : defaultFormat;
            return GetAccessor(start, length, format, Encoding);
        }
示例#4
0
        /// <summary>
        /// Creates an accessor depending on the format.
        /// </summary>
        /// <param name="start">the zero-based index of the first byte of the accessor</param>
        /// <param name="length">the length of the accessor</param>
        /// <param name="format">the format of the accessor</param>
        /// <param name="encoding">the encoding of the accessed records</param>
        /// <returns>a new accessor with the correct parameters</returns>
        protected object GetAccessor(int start, int length, string format, Encoding encoding)
        {
            object result;

            switch (format)
            {
            case StringFormat:
            case SubstringFormat:
                result = new StringAccessor {
                    Encoding = encoding, Start = start, Length = length
                };
                break;

            case ZonedFormat:
                result = new ZonedAccessor {
                    Encoding = encoding, Length = length, Start = start
                };
                break;

            case PackedFormat:
                result = new PackedAccessor {
                    Encoding = encoding, Length = length, Start = start
                };
                break;

            case SignedBinaryFormat:
                result = new BinaryAccessor {
                    Encoding = encoding, Length = length, Start = start, Signed = true
                };
                break;

            case BinaryFormat:
                result = new BinaryAccessor {
                    Encoding = encoding, Length = length, Start = start, Signed = false
                };
                break;

            default:
                if (format != null && format.StartsWith(AsciiDecimalFormat))
                {
                    int precision = 0;
                    if (format.Length > 2)
                    {
                        precision = int.Parse(format.Substring(2));
                        result    = new AsciiAcessor {
                            Encoding = encoding, Length = length, Start = start, Precision = precision
                        };
                    }
                    else
                    {
                        throw new ParsingException("Unknown format: " + format);
                    }
                    break;
                }
                else
                {
                    throw new ParsingException("Unknown format: " + format);
                }
            }
            return(result);
        }