예제 #1
0
        /// <summary>
        /// Returns the base-data value.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>The base-data value.</returns>
        private BaseData GetBaseDataValue(Stream stream)
        {
            Byte[] buffer = new Byte[12];
            stream.Read(buffer, 0, 12);

            Int32 numberOfRows    = EndianBitConverter.ToInt32(buffer, ByteOrder.LittleEndian);
            Int32 numberOfColumns = EndianBitConverter.ToInt32(buffer, 4, ByteOrder.LittleEndian);
            Int32 itemTypeIndex   = EndianBitConverter.ToUInt16(buffer, 8, ByteOrder.LittleEndian);
            Int32 objectType      = EndianBitConverter.ToUInt16(buffer, 10, ByteOrder.LittleEndian);

            ItemType itemType = ItemTypeInfo.ItemTypeFromIndex(itemTypeIndex);

            Object[,] values = new Object[numberOfRows, numberOfColumns];
            Int32 rowIndex = 0, columnIndex = 0;

            while (rowIndex < numberOfRows)
            {
                Object value = ReadValue(stream, ItemTypeInfo.TypeByteCount(itemType), itemType);
                IEnumerable <Object> enumerableValue = value as IEnumerable <Object>;

                if (enumerableValue != null)
                {
                    foreach (Object item in enumerableValue)
                    {
                        values[rowIndex, columnIndex] = item;
                        columnIndex++;

                        if (columnIndex == numberOfColumns)
                        {
                            columnIndex = 0;
                            rowIndex++;
                        }
                    }
                }
                else
                {
                    values[rowIndex, columnIndex] = value;
                    columnIndex++;

                    if (columnIndex == numberOfColumns)
                    {
                        columnIndex = 0;
                        rowIndex++;
                    }
                }
            }

            return(new BaseData(itemType, values));
        }
예제 #2
0
        /// <summary>
        /// Reads the contents of the <see cref="EhfaObject" /> from the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        public virtual void Read(Stream stream)
        {
            Int32 size = ItemTypeInfo.TypeByteCount(Type.ItemType);

            if (Type.DataPlacement == DataPlacement.Internal)
            {
                if (Type.ItemType == ItemType.UChar || Type.ItemType == ItemType.Char)
                {
                    size = _type.ItemNumber;
                }

                Value = ReadValue(stream, size, Type.ItemType);
            }
            else
            {
                Byte[] temp = new Byte[8];
                stream.Read(temp, 0, temp.Length);
                Int32 repeatCount = (Int32)EndianBitConverter.ToUInt32(temp, ByteOrder.LittleEndian);

                if (repeatCount <= 0)
                {
                    return;
                }

                if (Type.ItemType == ItemType.UChar || Type.ItemType == ItemType.Char)
                {
                    size        = repeatCount;
                    repeatCount = 1;
                }

                if (repeatCount > 1)
                {
                    Value = ReadValues(stream, size, repeatCount, Type.ItemType);
                }
                else
                {
                    Value = ReadValue(stream, size, Type.ItemType);
                }
            }
        }