Пример #1
0
        static void SetValue(object obj, DBClientHelper helper, DB6BinaryReader reader, int field)
        {
            switch (Type.GetTypeCode(helper.RealType))
            {
            case TypeCode.SByte:
                helper.SetValue(obj, reader.ReadSByte());
                break;

            case TypeCode.Byte:
                helper.SetValue(obj, reader.ReadByte());
                break;

            case TypeCode.Int16:
                helper.SetValue(obj, reader.ReadInt16());
                break;

            case TypeCode.UInt16:
                helper.SetValue(obj, reader.ReadUInt16());
                break;

            case TypeCode.Int32:
                helper.SetValue(obj, reader.GetInt32(_header.GetFieldBytes(field)));
                break;

            case TypeCode.UInt32:
                helper.SetValue(obj, reader.GetUInt32(_header.GetFieldBytes(field)));
                break;

            case TypeCode.Single:
                helper.SetValue(obj, reader.ReadSingle());
                break;

            case TypeCode.String:
                string str = GetString(reader, field);
                helper.SetValue(obj, str);
                break;
            }
        }
Пример #2
0
        static void SetArrayValue(Array array, int arrayIndex, DBClientHelper helper, DB6BinaryReader reader, int field)
        {
            switch (Type.GetTypeCode(helper.RealType))
            {
            case TypeCode.SByte:
                helper.SetValue(array, reader.ReadSByte(), arrayIndex);
                break;

            case TypeCode.Byte:
                helper.SetValue(array, reader.ReadByte(), arrayIndex);
                break;

            case TypeCode.Int16:
                helper.SetValue(array, reader.ReadInt16(), arrayIndex);
                break;

            case TypeCode.UInt16:
                helper.SetValue(array, reader.ReadUInt16(), arrayIndex);
                break;

            case TypeCode.Int32:
                helper.SetValue(array, reader.GetInt32(_header.GetFieldBytes(field)), arrayIndex);
                break;

            case TypeCode.UInt32:
                helper.SetValue(array, reader.GetUInt32(_header.GetFieldBytes(field)), arrayIndex);
                break;

            case TypeCode.Single:
                helper.SetValue(array, reader.ReadSingle(), arrayIndex);
                break;

            case TypeCode.String:
                helper.SetValue(array, GetString(reader, field), arrayIndex);
                break;
            }
        }
Пример #3
0
        internal static Dictionary <uint, T> Read <T>(MemoryStream memoryStream, DB6Meta meta) where T : new()
        {
            Dictionary <uint, T> storage = new Dictionary <uint, T>();

            //First lets load field Info
            var fields = typeof(T).GetFields();

            DBClientHelper[] fieldsInfo = new DBClientHelper[fields.Length];
            for (var i = 0; i < fields.Length; ++i)
            {
                fieldsInfo[i] = new DBClientHelper(fields[i]);
            }

            using (var fileReader = new BinaryReader(memoryStream))
            {
                _header = ReadHeader(fileReader);
                var data = LoadData(fileReader);

                int commonDataFieldIndex = 0;
                foreach (var pair in data)
                {
                    var dataReader = new DB6BinaryReader(pair.Value);
                    var obj        = new T();

                    int fieldIndex = 0;
                    for (var x = 0; x < _header.FieldCount; ++x)
                    {
                        int arrayLength = meta.ArraySizes[x];
                        if (arrayLength > 1)
                        {
                            for (var z = 0; z < arrayLength; ++z)
                            {
                                var fieldInfo = fieldsInfo[fieldIndex++];
                                if (fieldInfo.IsArray)
                                {
                                    //Field is Array
                                    Array array = (Array)fieldInfo.Getter(obj);
                                    for (var y = 0; y < array.Length; ++y)
                                    {
                                        SetArrayValue(array, y, fieldInfo, dataReader, x);
                                    }

                                    arrayLength -= array.Length;
                                }
                                else
                                {
                                    SetValue(obj, fieldInfo, dataReader, x);
                                }
                            }
                        }
                        else
                        {
                            var fieldInfo = fieldsInfo[fieldIndex++];
                            if (fieldInfo.IsArray)
                            {
                                Array array = (Array)fieldInfo.Getter(obj);
                                for (var y = 0; y < array.Length; ++y)
                                {
                                    SetArrayValue(array, y, fieldInfo, dataReader, x + y);
                                }

                                x += array.Length - 1;
                            }
                            else
                            {
                                SetValue(obj, fieldInfo, dataReader, x);
                            }
                        }
                    }

                    commonDataFieldIndex = fieldIndex;

                    storage.Add((uint)pair.Key, obj);
                }

                //Get DB field Index
                uint index = 0;
                for (uint i = 0; i < _header.FieldCount && i < _header.IndexField; ++i)
                {
                    index += meta.ArraySizes[i];
                }

                ReadCommonData(commonDataFieldIndex, storage, meta, fieldsInfo);
            }

            return(storage);
        }