Пример #1
0
            internal string Encode(IDictionary <string, object> values, Scales scales)
            {
                StringBuilder builder = new StringBuilder(this.input.Size);

                if ((values == null) || (values.Count == 0))
                {
                    return(builder.Append(' ', this.input.Size).ToString());
                }
                int scale = 0;

                if (this.Params.HasSecCode)
                {
                    object obj2 = null;
                    if (values.TryGetValue(this.Params.fldSecCode.Name, out obj2))
                    {
                        object obj3 = null;
                        if (this.Params.HasSecBoard)
                        {
                            values.TryGetValue(this.Params.fldSecBoard.Name, out obj3);
                        }
                        if (obj3 == null)
                        {
                            scales.Find(obj2.ToString(), out scale);
                        }
                        else
                        {
                            scales.Find(obj3.ToString(), obj2.ToString(), out scale);
                        }
                    }
                }
                int num2 = 0;

                for (int i = 0; i < this.Params.varBlockCount; i++)
                {
                    Meta.Field field = this.Params[i + this.Params.varBlockFirst];
                    if ((field.flags & 8) != 0)
                    {
                        if (num2 == 0)
                        {
                            num2 = 1;
                        }
                        object obj4 = null;
                        if ((values.TryGetValue(field.Name, out obj4) && (obj4 != null)) && obj4.GetType().IsArray)
                        {
                            Array array = obj4 as Array;
                            num2 = Math.Max(num2, array.Length);
                        }
                    }
                }
                int num4          = (this.Params.varBlockFirst + this.Params.varBlockCount) - 1;
                int num5          = 0;
                int varBlockFirst = 0;

                while (varBlockFirst < this.Params.Count)
                {
                    Meta.Field field2 = this.Params[varBlockFirst];
                    object     obj5   = null;
                    if (values.TryGetValue(field2.Name, out obj5))
                    {
                        if (obj5 == null)
                        {
                            builder.Append(' ', field2.Size);
                        }
                        else
                        {
                            System.Type type = obj5.GetType();
                            if (((field2.flags & 8) != 0) && type.IsArray)
                            {
                                Array array2 = obj5 as Array;
                                if (num5 < array2.Length)
                                {
                                    field2.Encode(builder, array2.GetValue(new int[] { num5 }), scale);
                                }
                                else
                                {
                                    builder.Append(' ', field2.Size);
                                }
                            }
                            else
                            {
                                field2.Encode(builder, obj5, scale);
                            }
                        }
                    }
                    else if (string.IsNullOrEmpty(field2.Defaults))
                    {
                        builder.Append(' ', field2.Size);
                    }
                    else
                    {
                        builder.Append(field2.Defaults);
                    }
                    if (varBlockFirst == num4)
                    {
                        if (++num5 < num2)
                        {
                            varBlockFirst = this.Params.varBlockFirst;
                        }
                        else
                        {
                            varBlockFirst++;
                        }
                    }
                    else
                    {
                        varBlockFirst++;
                    }
                }
                return(builder.ToString());
            }
Пример #2
0
        protected int ParseKeys(BinaryReader reader, Meta.Message source, ITarget target)
        {
            int num = -1;

            Reset(ref this.currentTickerBoard, ref this.currentTickerPaper);
            int count = source.Output.Keys.Count;

            if (source.Output.HasDecimals)
            {
                count++;
            }
            if (source.Output.HasSecBoard)
            {
                count++;
            }
            if (source.Output.HasSecCode)
            {
                count++;
            }
            if (source.Output.HasMarketID)
            {
                count++;
            }
            long position = reader.BaseStream.Position;

            try
            {
                for (int i = 0; (i < this.fldCount) && (count > 0); i++)
                {
                    int num5 = this.fldIndex[i];
                    if (num5 > source.maxEssentialIndex)
                    {
                        return(num);
                    }
                    Meta.Field field = source.Output[num5];
                    bool       isKey = field.IsKey;
                    int        size  = field.Size;
                    object     obj2  = null;
                    if (isKey)
                    {
                        count--;
                        obj2 = this.ParseData(reader, source, field, target);
                        size = 0;
                    }
                    else if (field.CanEscape && (reader.PeekChar() == 0x23))
                    {
                        reader.ReadChar();
                        size = 0;
                    }
                    switch ((field.Flags & 0xff02))
                    {
                    case 2:
                        count--;
                        this.currentTickerPaper = Convert.ToString(isKey ? obj2 : Read(reader, size));
                        break;

                    case 0x100:
                        count--;
                        num = Convert.ToInt32(isKey ? obj2 : SToI(reader, size));
                        break;

                    case 0x200:
                        count--;
                        this.currentTickerBoard = Convert.ToString(isKey ? obj2 : Read(reader, size));
                        break;

                    case 0x400:
                        count--;
                        if (!isKey)
                        {
                            Stream baseStream = reader.BaseStream;
                            baseStream.Position += size;
                        }
                        break;

                    default:
                    {
                        Stream stream2 = reader.BaseStream;
                        stream2.Position += size;
                        break;
                    }
                    }
                }
            }
            finally
            {
                reader.BaseStream.Position = position;
            }
            return(num);
        }
Пример #3
0
        protected void ParseRow(BinaryReader reader, Meta.Message source, string filter, ITarget target)
        {
            int num4;

            this.fldCount = reader.ReadByte();
            int num = reader.ReadInt32();

            if (this.fldCount == 0)
            {
                this.fldCount = source.Output.Count;
                this.fldIndex = everything;
            }
            else
            {
                this.fldIndex = this.projection;
                for (int i = 0; i < this.fldCount; i++)
                {
                    this.fldIndex[i] = reader.ReadByte();
                }
            }
            this.isPartialOrderbook = source.IsOrderbook && (this.fldIndex[0] != 0);
            this.parseKeyPhase      = true;
            try
            {
                if ((source.maxEssentialIndex < 0) || this.isPartialOrderbook)
                {
                    this.hasDecimals = false;
                    this.rowDecimals = 0;
                }
                else
                {
                    int num3 = this.ParseKeys(reader, source, target);
                    this.hasDecimals = num3 >= 0;
                    this.rowDecimals = this.hasDecimals ? num3 : 0;
                }
            }
            finally
            {
                this.parseKeyPhase = false;
            }
            if (((source.IsOrderbook && this.IsEmptyOrderbook(source, filter, target)) || ((source.Output.IsSecNoBoard && (this.currentTickerPaper.Length > 0)) && !this.client.Scales.Find(this.currentTickerPaper, out num4))) || (num == 0))
            {
                Stream baseStream = reader.BaseStream;
                baseStream.Position += num;
            }
            else
            {
                this.isNewRow = ((target == null) || target.InitRecordUpdate(source, filter)) || source.IsOrderbook;
                try
                {
                    int num7;
                    if (this.hasDecimals)
                    {
                        if (source.Output.HasSecCode)
                        {
                            this.client.Scales.Add(this.currentTickerBoard, this.currentTickerPaper, this.rowDecimals);
                        }
                        if ((target != null) && this.isNewRow)
                        {
                            target.SetRecordDecimals(this.rowDecimals);
                        }
                    }
                    else if (this.isNewRow)
                    {
                        this.GetRowDecimals(source, target);
                    }
                    if (source.IsOrderbook)
                    {
                        if (this.isPartialOrderbook)
                        {
                            long position = reader.BaseStream.Position;
                            try
                            {
                                reader.BaseStream.Position = this.orderbookHeadPos;
                                for (int j = 0; j < this.fldIndex[0]; j++)
                                {
                                    Meta.Field field = source.Output[j];
                                    this.ParseData(reader, source, field, target);
                                }
                                goto Label_0251;
                            }
                            finally
                            {
                                reader.BaseStream.Position = position;
                            }
                        }
                        this.orderbookHeadPos = reader.BaseStream.Position;
                    }
Label_0251:
                    num7 = 0;
                    while (num7 < this.fldCount)
                    {
                        Meta.Field field2 = source.Output[this.fldIndex[num7]];
                        this.ParseData(reader, source, field2, target);
                        num7++;
                    }
                }
                finally
                {
                    if (target != null)
                    {
                        target.DoneRecordUpdate(source, filter);
                    }
                }
            }
        }
Пример #4
0
        protected object ParseData(BinaryReader reader, Meta.Message source, Meta.Field field, ITarget target)
        {
            object obj2;

            if (field.IsOneChar)
            {
                obj2 = reader.ReadChar();
            }
            else if (field.CanEscape && (reader.PeekChar() == 0x23))
            {
                obj2 = null;
                reader.ReadChar();
            }
            else
            {
                int size = field.Size;
                switch (field.Type)
                {
                case Meta.FieldType.Char:
                    obj2 = Read(reader, size);
                    break;

                case Meta.FieldType.Integer:
                    Int64?nullable = null;   //KAA
                    obj2 = SToL(reader, size);

                    /*
                     * if (size <= 9)
                     * {
                     *    nullable = SToI(reader, size);
                     * }
                     * //KAA
                     * obj2 = (nullable.HasValue ? SToL(reader, size) : null);
                     * //obj2 = nullable.HasValue ? nullable. : null;
                     * //obj2 = nullable.GetValueOrDefault();
                     */
                    break;

                case Meta.FieldType.Fixed:
                    obj2 = SToF(reader, size, (byte)field.Decimals);
                    break;

                case Meta.FieldType.Float:
                    obj2 = SToF(reader, size, (byte)this.GetRowDecimals(source, target));
                    break;

                case Meta.FieldType.Date:
                    obj2 = SToI(reader, size);
                    break;

                case Meta.FieldType.Time:
                    obj2 = SToI(reader, size);
                    break;

                case Meta.FieldType.FloatPoint:
                {
                    char[] chArray = reader.ReadChars(size);
                    int    length  = chArray.Length;
                    while ((length > 0) && (chArray[length - 1] == ' '))
                    {
                        length--;
                    }
                    while ((length > 0) && (chArray[length - 1] == '0'))
                    {
                        length--;
                    }
                    if (length == 0)
                    {
                        obj2 = null;
                    }
                    else
                    {
                        decimal num3;
                        if (decimal.TryParse(new string(chArray, 0, length), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out num3))
                        {
                            obj2 = num3;
                        }
                        else
                        {
                            obj2 = null;
                        }
                    }
                    break;
                }

                default:
                    obj2 = null;
                    break;
                }
            }
            if (target != null)
            {
                if (this.parseKeyPhase)
                {
                    target.SetKeyValue(field, obj2);
                    return(obj2);
                }
                target.SetFieldValue(field, obj2);
            }
            return(obj2);
        }