Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="offset"></param>
        /// <param name="tagCount"></param>
        /// <param name="fileDuration"></param>
        /// <param name="blockDuration"></param>
        /// <param name="timetick"></param>
        /// <param name="blockPointer"></param>
        /// <param name="time"></param>
        public static void ReadRegionHead(DataFileSeriserbase datafile, long offset, out int tagCount, out int fileDuration, out int blockDuration, out int timetick, out long blockPointer, out DateTime time)
        {
            //文件头部结构:Pre DataRegion(8) + Next DataRegion(8) + Datatime(8)+tagcount(4)+ tagid sum(8) +file duration(4)+ block duration(4)+Time tick duration(4)+ { + tagid1+tagid2+...+tagidn }+ {[tag1 block point1(8) + tag2 block point1+ tag3 block point1+...] + [tag1 block point2(8) + tag2 block point2+ tag3 block point2+...]....}
            var dataoffset = offset + 16;

            //读取时间
            time        = datafile.ReadDateTime(dataoffset);
            dataoffset += 8;

            //读取单个文件的时长
            fileDuration = datafile.ReadInt(dataoffset);
            dataoffset  += 4;
            //读取数据块时长
            blockDuration = datafile.ReadInt(dataoffset);
            dataoffset   += 4;
            //读取时钟周期
            timetick    = datafile.ReadInt(dataoffset);
            dataoffset += 4;

            //读取变量个数
            tagCount    = datafile.ReadInt(dataoffset);
            dataoffset += 4;

            blockPointer = dataoffset - offset;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="startTime"></param>
        /// <param name="tid"></param>
        /// <param name="offset"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        public static IEnumerable <Tuple <MarshalMemoryBlock, DateTime, DateTime, int> > ReadTagDataBlock2(DataFileSeriserbase datafile, int tid, long offset, DateTime start, DateTime end)
        {
            int      fileDuration, blockDuration = 0;
            int      tagCount     = 0;
            long     blockpointer = 0;
            int      timetick     = 0;
            DateTime time;


            ReadRegionHead(datafile, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);

            if (tagCount == 0)
            {
                yield return(null);
            }

            var tagIndex = tid % tagCount;

            int blockcount = fileDuration * 60 / blockDuration;

            //读取文件开始时间
            var startTime = datafile.ReadDateTime(0);

            DateTime sstart = start;
            DateTime send   = end;

            var headdata = GetHeadBlock(datafile, offset + blockpointer, tagCount * blockcount * 8);

            while (sstart < end)
            {
                var ttmp = Math.Round((sstart - startTime).TotalSeconds, 3);
                var vv   = blockDuration * 60 - (ttmp % (blockDuration * 60));
                send = sstart.AddSeconds(vv);

                if (send > end)
                {
                    send = end;
                }
                int blockindex = (int)(ttmp / (blockDuration * 60));

                if (blockindex >= blockcount)
                {
                    break;
                    //throw new Exception("DataPointer index is out of total block number");
                }

                var dataPointer = headdata.ReadInt(tagIndex * 8 + blockindex * tagCount * 8); //读取DataBlock的相对地址

                if (dataPointer > 0)
                {
                    var vmm = GetDataMemory(datafile, dataPointer);
                    if (vmm != null)
                    {
                        yield return(new Tuple <MarshalMemoryBlock, DateTime, DateTime, int>(vmm, sstart, send, timetick));
                    }
                }
                sstart = send;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="tid"></param>
        /// <param name="offset"></param>
        /// <param name="dataTime"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        private static MarshalMemoryBlock ReadTagDataBlock(DataFileSeriserbase datafile, int tid, long offset, DateTime dataTime, out int timetick, out int index)
        {
            int      fileDuration, blockDuration = 0;
            int      tagCount = 0;
            DateTime time;
            long     blockpointer = 0;

            var dindex     = ReadTagIndexInDataPointer(datafile, tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);
            int blockcount = fileDuration * 60 / blockDuration;

            var startTime  = datafile.ReadDateTime(16);
            var ttmp       = (dataTime - startTime).TotalMinutes;
            int blockIndex = (int)(ttmp / blockDuration);

            if (ttmp % blockDuration > 0)
            {
                blockIndex++;
            }

            if (blockIndex > blockcount)
            {
                throw new Exception("DataPointer index is out of total block number");
            }
            index = blockIndex;

            var headdata        = datafile.Read(offset + blockpointer + dindex * blockcount * 12, blockcount * 12);
            var dataPointer     = headdata.ReadInt(blockIndex * 12);      //读取DataBlock的相对地址
            var dataPointerbase = headdata.ReadLong(blockIndex * 12 + 4); //读取DataBlock的基地址

            headdata.Dispose();

            if (dataPointer >= 0)
            {
                return(GetDataMemory(datafile, dataPointerbase, dataPointer));
            }
            else
            {
                var dp       = dataPointerbase + (dataPointer & 0x7FFFFFFF);
                var datasize = datafile.ReadInt(dp);
                return(datafile.Read(dp + 4, datasize));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="tid"></param>
        /// <param name="offset"></param>
        /// <param name="dataTime"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        public static MarshalMemoryBlock ReadTagDataBlock(this DataFileSeriserbase datafile, int tid, long offset, DateTime dataTime, out int timetick, out int index)
        {
            int      fileDuration, blockDuration = 0;
            int      tagCount = 0;
            DateTime time;
            long     blockpointer = 0;

            var dindex     = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);
            int blockcount = fileDuration * 60 / blockDuration;

            var startTime  = datafile.ReadDateTime(16);
            var ttmp       = (dataTime - startTime).TotalMinutes;
            int blockIndex = (int)(ttmp / blockDuration);

            if (ttmp % blockDuration > 0)
            {
                blockIndex++;
            }

            if (blockIndex > blockcount)
            {
                throw new Exception("DataPointer index is out of total block number");
            }
            index = blockIndex;

            var headdata = GetHeadBlock(datafile, offset + blockpointer, tagCount * blockcount * 12);

            ////var dataPointer = datafile.ReadLong(blockIndex * 8 + dindex * tagCount * 8); //读取DataBlock的地址
            //var dataPointer = datafile.ReadInt(offset + blockpointer + dindex * 12 + blockIndex * tagCount * 12); //读取DataBlock的相对地址
            //var dataPointerbase = datafile.ReadLong(offset + blockpointer + dindex * 12 + blockIndex * tagCount * 12 + 4); //读取DataBlock的基地址

            var dataPointer     = headdata.ReadInt(dindex * 12 + blockIndex * tagCount * 12);      //读取DataBlock的相对地址
            var dataPointerbase = headdata.ReadLong(dindex * 12 + blockIndex * tagCount * 12 + 4); //读取DataBlock的基地址


            var vmm = GetDataMemory(datafile, dataPointerbase, dataPointer);

            return(vmm);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="tid"></param>
        /// <param name="offset"></param>
        /// <param name="dataTimes"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        public static Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> > ReadTagDataBlock2(DataFileSeriserbase datafile, int tid, long offset, List <DateTime> dataTimes, out int timetick)
        {
            int      fileDuration, blockDuration = 0;
            int      tagCount     = 0;
            long     blockpointer = 0;
            DateTime time;

            //var tagIndex = datafile.ReadTagIndexInDataPointer(tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);

            ReadRegionHead(datafile, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);
            var tagIndex = tid % tagCount;

            Dictionary <long, MarshalMemoryBlock> rtmp = new Dictionary <long, MarshalMemoryBlock>();

            Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> > re = new Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> >();

            if (tagCount == 0)
            {
                return(re);
            }

            int blockcount = fileDuration * 60 / blockDuration;

            var startTime = datafile.ReadDateTime(0);

            var headdata = GetHeadBlock(datafile, offset + blockpointer, tagCount * blockcount * 12);

            foreach (var vdd in dataTimes)
            {
                var ttmp       = (vdd - startTime).TotalMinutes;
                int blockindex = (int)(ttmp / blockDuration);

                if (blockindex > blockcount)
                {
                    throw new Exception("DataPointer index is out of total block number");
                }

                var dataPointer = headdata.ReadInt(tagIndex * 8 + blockindex * tagCount * 8); //读取DataBlock的相对地址

                if (dataPointer > 0)
                {
                    //var datasize = datafile.ReadInt(dataPointer); //读取DataBlock 的大小
                    var vmm = GetDataMemory(datafile, dataPointer);

                    if (vmm != null)
                    {
                        if (!rtmp.ContainsKey(dataPointer))
                        {
                            //var rmm = datafile.Read(dataPointer + 4, datasize);
                            if (!re.ContainsKey(vmm))
                            {
                                re.Add(vmm, new Tuple <List <DateTime>, int>(new List <DateTime>()
                                {
                                    vdd
                                }, blockindex));
                            }
                            else
                            {
                                re[vmm].Item1.Add(vdd);
                            }
                            rtmp.Add(dataPointer, vmm);
                        }
                        else
                        {
                            //var rmm = rtmp[dataPointer];
                            if (!re.ContainsKey(vmm))
                            {
                                re.Add(vmm, new Tuple <List <DateTime>, int>(new List <DateTime>()
                                {
                                    vdd
                                }, blockindex));
                            }
                            else
                            {
                                re[vmm].Item1.Add(vdd);
                            }
                        }
                    }
                }
            }
            return(re);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 检测数据头部指针区域数据是否被缓存
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="offset"></param>
        /// <param name="fileDuration"></param>
        /// <param name="blockDuration"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        public static Dictionary <int, int> CheckBlockHeadCach(this DataFileSeriserbase datafile, long offset, out int tagCount, out int fileDuration, out int blockDuration, out int timetick, out long blockPointer, out DateTime time)
        {
            //文件头部结构:Pre DataRegion(8) + Next DataRegion(8) + Datatime(8)+tagcount(4)+ tagid sum(8) +file duration(4)+ block duration(4)+Time tick duration(4)+ { + tagid1+tagid2+...+tagidn }+ {[tag1 block point1(8) + tag2 block point1+ tag3 block point1+...] + [tag1 block point2(8) + tag2 block point2+ tag3 block point2+...]....}
            var dataoffset = offset + 16;

            //读取时间
            time        = datafile.ReadDateTime(dataoffset);
            dataoffset += 8;

            //读取变量个数
            int count = datafile.ReadInt(dataoffset);

            dataoffset += 4;

            tagCount = count;

            //读取校验和
            long idsum = datafile.ReadLong(dataoffset);

            dataoffset += 8;

            //读取单个文件的时长
            fileDuration = datafile.ReadInt(dataoffset);
            dataoffset  += 4;
            //读取数据块时长
            blockDuration = datafile.ReadInt(dataoffset);
            dataoffset   += 4;
            //读取时钟周期
            timetick    = datafile.ReadInt(dataoffset);
            dataoffset += 4;

            lock (TagHeadOffsetManager.manager)
            {
                if (!TagHeadOffsetManager.manager.Contains(idsum, count))
                {
                    //Tag id 列表经过压缩,内容格式为:DataSize + Data
                    var dsize = datafile.ReadInt(dataoffset);

                    if (dsize <= 0)
                    {
                        tagCount      = 0;
                        fileDuration  = 0;
                        blockDuration = 0;
                        timetick      = 0;
                        blockPointer  = 0;
                        return(new Dictionary <int, int>());
                    }

                    dataoffset += 4;

                    blockPointer = dataoffset + dsize - offset;
                    var dtmp = new Dictionary <int, int>();
                    using (var dd = datafile.Read(dataoffset, dsize))
                    {
                        MarshalVarintCodeMemory vcm = new MarshalVarintCodeMemory(dd.StartMemory, dsize);
                        var ltmp = vcm.ToIntList();
                        //vcm.Dispose();


                        if (ltmp.Count > 0)
                        {
                            int preid = ltmp[0];
                            dtmp.Add(preid, 0);
                            for (int i = 1; i < ltmp.Count; i++)
                            {
                                var id = ltmp[i] + preid;
                                dtmp.Add(id, i);
                                preid = id;
                            }
                        }
                        TagHeadOffsetManager.manager.Add(idsum, count, dtmp, blockPointer);

                        dd.Dispose();
                    }
                    return(dtmp);
                }
                else
                {
                    var re = TagHeadOffsetManager.manager.Get(idsum, count);
                    blockPointer = re.Item2;
                    return(re.Item1);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="startTime"></param>
        /// <param name="tid"></param>
        /// <param name="offset"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        private static IEnumerable <Tuple <MarshalMemoryBlock, DateTime, DateTime, int> > ReadTagDataBlock2(DataFileSeriserbase datafile, int tid, long offset, DateTime start, DateTime end)
        {
            int      fileDuration, blockDuration = 0;
            int      tagCount     = 0;
            long     blockpointer = 0;
            int      timetick     = 0;
            DateTime time;

            //var tagIndex = ReadTagIndexInDataPointer(datafile,tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);

            ReadRegionHead(datafile, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);

            var tagIndex = tid % tagCount;

            int blockcount = fileDuration * 60 / blockDuration;

            //读取文件开始时间
            var startTime = datafile.ReadDateTime(0);

            DateTime sstart = start;
            DateTime send   = end;

            int buffersize = 1024 * 1024 * 2;
            //分配读缓存
            IntPtr mdataBuffer    = Marshal.AllocHGlobal(buffersize);
            long   mbufferadderss = 0;
            int    bufferLen      = 0;

            //var headdata = GetHeadBlock(datafile, offset + blockpointer, tagCount * blockcount * 12);

            var headdata = datafile.Read(offset + blockpointer + tagIndex * blockcount * 8, blockcount * 8);

            while (sstart < end)
            {
                var ttmp = Math.Round((sstart - startTime).TotalSeconds, 3);
                var vv   = blockDuration * 60 - (ttmp % (blockDuration * 60));
                send = sstart.AddSeconds(vv);

                if (send > end)
                {
                    send = end;
                }
                int blockindex = (int)(ttmp / (blockDuration * 60));

                if (blockindex >= blockcount)
                {
                    break;
                    //throw new Exception("DataPointer index is out of total block number");
                }

                var dataPointer = headdata.ReadInt(blockindex * 8); //读取DataBlock的相对地址

                if (dataPointer > 0)
                {
                    MarshalMemoryBlock vmm = null;
                    //说明数据没有采用Zip压缩,可以直接读取使用
                    var dp       = dataPointer;
                    int datasize = 0;
                    int dataloc  = 0;
                    if (dp >= mbufferadderss && (dp - mbufferadderss + 4) <= bufferLen && (dp - mbufferadderss + 4 + MemoryHelper.ReadInt32(mdataBuffer, dp - mbufferadderss)) <= bufferLen)
                    {
                        datasize = MemoryHelper.ReadInt32(mdataBuffer, dp - mbufferadderss);
                        dataloc  = (int)(dp - mbufferadderss + 4);
                    }
                    else
                    {
                        bufferLen      = datafile.Read(mdataBuffer, dp, buffersize);
                        mbufferadderss = dp;
                        datasize       = MemoryHelper.ReadInt32(mdataBuffer, 0);
                        dataloc        = (int)(dp - mbufferadderss + 4);
                    }

                    if (datasize > 0 && datasize < datafile.Length)
                    {
                        vmm = new MarshalMemoryBlock(datasize, datasize);
                        MemoryHelper.MemoryCopy(mdataBuffer, dataloc, vmm.Buffers[0], 0, datasize);
                    }

                    if (vmm != null)
                    {
                        yield return(new Tuple <MarshalMemoryBlock, DateTime, DateTime, int>(vmm, sstart, send, timetick));
                    }
                }
                sstart = send;
            }

            headdata.Dispose();
            Marshal.FreeHGlobal(mdataBuffer);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="tid"></param>
        /// <param name="offset"></param>
        /// <param name="dataTimes"></param>
        /// <param name="timetick"></param>
        /// <returns></returns>
        private static Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> > ReadTagDataBlock2(DataFileSeriserbase datafile, int tid, long offset, List <DateTime> dataTimes, out int timetick)
        {
            int      fileDuration, blockDuration = 0;
            int      tagCount     = 0;
            long     blockpointer = 0;
            DateTime time;

            //var tagIndex = ReadTagIndexInDataPointer(datafile,tid, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);

            ReadRegionHead(datafile, offset, out tagCount, out fileDuration, out blockDuration, out timetick, out blockpointer, out time);

            var tagIndex = tid % tagCount;

            Dictionary <long, MarshalMemoryBlock> rtmp = new Dictionary <long, MarshalMemoryBlock>();

            Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> > re = new Dictionary <MarshalMemoryBlock, Tuple <List <DateTime>, int> >();

            if (tagCount == 0)
            {
                return(re);
            }

            int blockcount = fileDuration * 60 / blockDuration;

            var startTime = datafile.ReadDateTime(0);

            int buffersize = 1024 * 1024 * 2;
            //分配读缓存
            IntPtr mdataBuffer    = Marshal.AllocHGlobal(buffersize);
            long   mbufferadderss = 0;
            int    bufferLen      = buffersize;


            // var headdata = GetHeadBlock(datafile, offset + blockpointer, tagCount * blockcount * 12);

            var headdata = datafile.Read(offset + blockpointer + tagIndex * blockcount * 8, blockcount * 8);

            long mLastBuffer       = 0;
            int  mLastDataLoc      = 0;
            int  mLastDataSize     = 0;
            MarshalMemoryBlock vmm = null;

            foreach (var vdd in dataTimes)
            {
                var ttmp       = (vdd - startTime).TotalMinutes;
                int blockindex = (int)(ttmp / blockDuration);

                if (blockindex > blockcount)
                {
                    throw new Exception("DataPointer index is out of total block number");
                }

                //var dataPointer = headdata.ReadInt(tagIndex * blockcount * 12 + blockindex * 12); //读取DataBlock的相对地址
                //var dataPointerbase = headdata.ReadLong(tagIndex * blockcount * 12 + blockindex * 12 + 4); //读取DataBlock的基地址

                var dataPointer = headdata.ReadInt(blockindex * 8); //读取DataBlock的相对地址
                //var dataPointerbase = headdata.ReadLong(blockindex * 12 + 4); //读取DataBlock的基地址

                if (dataPointer > 0)
                {
                    ////var datasize = datafile.ReadInt(dataPointer); //读取DataBlock 的大小
                    //var vmm = GetDataMemory(datafile, dataPointerbase, dataPointer);


                    //说明数据没有采用Zip压缩,可以直接读取使用
                    var dp       = dataPointer;
                    int datasize = 0;
                    int dataloc  = 0;
                    if (dp >= mbufferadderss && (dp - mbufferadderss + 4) <= bufferLen && (dp - mbufferadderss + 4 + MemoryHelper.ReadInt32(mdataBuffer, dp - mbufferadderss)) <= bufferLen)
                    {
                        datasize = MemoryHelper.ReadInt32(mdataBuffer, dp - mbufferadderss);
                        dataloc  = (int)(dp - mbufferadderss + 4);
                    }
                    else
                    {
                        bufferLen      = datafile.Read(mdataBuffer, dp, buffersize);
                        mbufferadderss = dp;
                        datasize       = MemoryHelper.ReadInt32(mdataBuffer, 0);
                        dataloc        = (int)(dp - mbufferadderss + 4);
                    }

                    if (datasize > 0 && (mLastBuffer != mbufferadderss || mLastDataLoc != dataloc || mLastDataSize != datasize))
                    {
                        vmm = new MarshalMemoryBlock(datasize, datasize);
                        MemoryHelper.MemoryCopy(mdataBuffer, dataloc, vmm.Buffers[0], 0, datasize);

                        mLastBuffer   = mbufferadderss;
                        mLastDataLoc  = dataloc;
                        mLastDataSize = datasize;
                    }
                    else if (datasize <= 0)
                    {
                        vmm = null;
                    }

                    if (vmm != null)
                    {
                        if (!rtmp.ContainsKey(dataPointer))
                        {
                            //var rmm = datafile.Read(dataPointer + 4, datasize);
                            if (!re.ContainsKey(vmm))
                            {
                                re.Add(vmm, new Tuple <List <DateTime>, int>(new List <DateTime>()
                                {
                                    vdd
                                }, blockindex));
                            }
                            else
                            {
                                re[vmm].Item1.Add(vdd);
                            }
                            rtmp.Add(dataPointer, vmm);
                        }
                        else
                        {
                            //var rmm = rtmp[dataPointer];
                            if (!re.ContainsKey(vmm))
                            {
                                re.Add(vmm, new Tuple <List <DateTime>, int>(new List <DateTime>()
                                {
                                    vdd
                                }, blockindex));
                            }
                            else
                            {
                                re[vmm].Item1.Add(vdd);
                            }
                        }
                    }
                }
            }

            headdata.Dispose();
            Marshal.FreeHGlobal(mdataBuffer);
            return(re);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="valIndex"></param>
        /// <param name="offset"></param>
        /// <param name="valueaddr"></param>
        /// <param name="result"></param>
        private static List <object> ReadValueInner <T>(this DataFileSeriserbase datafile, List <int> valIndex, long offset, long valueaddr, out int datasize)
        {
            List <object> re = new List <object>();

            string tname = typeof(T).Name;

            switch (tname)
            {
            case "Boolean":
                foreach (var vv in valIndex)
                {
                    re.Add(Convert.ToBoolean(datafile.ReadByte(offset + valueaddr + vv)));
                }
                datasize = 1;
                break;

            case "Byte":
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadByte(offset + valueaddr + vv));
                }
                datasize = 1;
                break;

            case "Int16":
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadShort(offset + valueaddr + vv * 2));
                }
                datasize = 2;
                break;

            case "UInt16":
                foreach (var vv in valIndex)
                {
                    re.Add((ushort)datafile.ReadShort(offset + valueaddr + vv * 2));
                }
                datasize = 2;
                break;

            case "Int32":
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadInt(offset + valueaddr + vv * 4));
                }
                datasize = 4;
                break;

            case "UInt32":
                foreach (var vv in valIndex)
                {
                    re.Add((uint)datafile.ReadInt(offset + valueaddr + vv * 4));
                }
                datasize = 4;
                break;

            case "Int64":
                foreach (var vv in valIndex)
                {
                    re.Add((long)datafile.ReadLong(offset + valueaddr + vv * 8));
                }
                datasize = 8;
                break;

            case "UInt64":
                foreach (var vv in valIndex)
                {
                    re.Add((ulong)datafile.ReadLong(offset + valueaddr + vv * 8));
                }
                datasize = 8;
                break;

            case "Double":
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadDouble(offset + valueaddr + vv * 8));
                }
                datasize = 8;
                break;

            case "Single":
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadFloat(offset + valueaddr + vv * 4));
                }
                datasize = 4;
                break;

            case "String":
                foreach (var vv in valIndex)
                {
                    var str = Encoding.Unicode.GetString(datafile.ReadBytes(offset + valueaddr + vv * Const.StringSize, Const.StringSize));
                    re.Add(str);
                }
                datasize = Const.StringSize;
                break;

            case "DateTime":
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadDateTime(offset + valueaddr + vv * 8));
                }
                datasize = 8;
                break;

            case "IntPointData":
                foreach (var vv in valIndex)
                {
                    var x = datafile.ReadInt(offset + valueaddr + vv * 8);
                    var y = datafile.ReadInt(offset + valueaddr + vv * 8 + 4);
                    re.Add(new IntPointData()
                    {
                        X = x, Y = y
                    });
                }
                datasize = 8;
                break;

            case "UIntPointData":
                foreach (var vv in valIndex)
                {
                    var x = (uint)datafile.ReadInt(offset + valueaddr + vv * 8);
                    var y = (uint)datafile.ReadInt(offset + valueaddr + vv * 8 + 4);
                    re.Add(new UIntPointData()
                    {
                        X = x, Y = y
                    });
                }
                datasize = 8;
                break;

            case "LongPointData":
                foreach (var vv in valIndex)
                {
                    var x = (long)datafile.ReadLong(offset + valueaddr + vv * 16);
                    var y = (long)datafile.ReadLong(offset + valueaddr + vv * 16 + 8);
                    re.Add(new LongPointData()
                    {
                        X = x, Y = y
                    });
                }
                datasize = 16;
                break;

            case "ULongPointData":
                foreach (var vv in valIndex)
                {
                    var x = (ulong)datafile.ReadLong(offset + valueaddr + vv * 16);
                    var y = (ulong)datafile.ReadLong(offset + valueaddr + vv * 16 + 8);
                    re.Add(new ULongPointData()
                    {
                        X = x, Y = y
                    });
                }
                datasize = 16;
                break;

            case "IntPoint3Data":
                foreach (var vv in valIndex)
                {
                    var x = datafile.ReadInt(offset + valueaddr + vv * 12);
                    var y = datafile.ReadInt(offset + valueaddr + vv * 12 + 4);
                    var z = datafile.ReadInt(offset + valueaddr + vv * 12 + 8);
                    re.Add(new IntPoint3Data()
                    {
                        X = x, Y = y, Z = z
                    });
                }
                datasize = 12;
                break;

            case "UIntPoint3Data":
                foreach (var vv in valIndex)
                {
                    var x = (uint)datafile.ReadInt(offset + valueaddr + vv * 12);
                    var y = (uint)datafile.ReadInt(offset + valueaddr + vv * 12 + 4);
                    var z = (uint)datafile.ReadInt(offset + valueaddr + vv * 12 + 8);
                    re.Add(new UIntPoint3Data()
                    {
                        X = x, Y = y, Z = z
                    });
                }
                datasize = 12;
                break;

            case "LongPoint3Data":
                foreach (var vv in valIndex)
                {
                    var x = (long)datafile.ReadLong(offset + valueaddr + vv * 24);
                    var y = (long)datafile.ReadLong(offset + valueaddr + vv * 24 + 8);
                    var z = (long)datafile.ReadLong(offset + valueaddr + vv * 24 + 168);
                    re.Add(new LongPoint3Data()
                    {
                        X = x, Y = y, Z = z
                    });
                }
                datasize = 24;
                break;

            case "ULongPoint3Data":
                foreach (var vv in valIndex)
                {
                    var x = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24);
                    var y = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24 + 8);
                    var z = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24 + 168);
                    re.Add(new ULongPoint3Data()
                    {
                        X = x, Y = y, Z = z
                    });
                }
                datasize = 24;
                break;

            default:
                datasize = 0;
                break;
            }
            return(re);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datafile"></param>
        /// <param name="valIndex"></param>
        /// <param name="offset"></param>
        /// <param name="valueaddr"></param>
        /// <param name="result"></param>
        private static List <object> ReadValueInner <T>(this DataFileSeriserbase datafile, List <int> valIndex, long offset, long valueaddr, out int datasize)
        {
            List <object> re = new List <object>();

            if (typeof(T) == typeof(bool))
            {
                foreach (var vv in valIndex)
                {
                    re.Add(Convert.ToBoolean(datafile.ReadByte(offset + valueaddr + vv)));
                }
                datasize = 1;
            }
            else if (typeof(T) == typeof(byte))
            {
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadByte(offset + valueaddr + vv));
                }
                datasize = 1;
            }
            else if (typeof(T) == typeof(short))
            {
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadShort(offset + valueaddr + vv * 2));
                }
                datasize = 2;
            }
            else if (typeof(T) == typeof(ushort))
            {
                foreach (var vv in valIndex)
                {
                    re.Add((ushort)datafile.ReadShort(offset + valueaddr + vv * 2));
                }
                datasize = 2;
            }
            else if (typeof(T) == typeof(int))
            {
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadInt(offset + valueaddr + vv * 4));
                }
                datasize = 4;
            }
            else if (typeof(T) == typeof(uint))
            {
                foreach (var vv in valIndex)
                {
                    re.Add((uint)datafile.ReadInt(offset + valueaddr + vv * 4));
                }
                datasize = 4;
            }
            else if (typeof(T) == typeof(long))
            {
                foreach (var vv in valIndex)
                {
                    re.Add((long)datafile.ReadLong(offset + valueaddr + vv * 8));
                }
                datasize = 8;
            }
            else if (typeof(T) == typeof(ulong))
            {
                foreach (var vv in valIndex)
                {
                    re.Add((ulong)datafile.ReadLong(offset + valueaddr + vv * 8));
                }
                datasize = 8;
            }
            else if (typeof(T) == typeof(double))
            {
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadDouble(offset + valueaddr + vv * 8));
                }
                datasize = 8;
            }
            else if (typeof(T) == typeof(float))
            {
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadFloat(offset + valueaddr + vv * 4));
                }
                datasize = 4;
            }
            else if (typeof(T) == typeof(string))
            {
                foreach (var vv in valIndex)
                {
                    var str = Encoding.Unicode.GetString(datafile.ReadBytes(offset + valueaddr + vv * Const.StringSize, Const.StringSize));
                    re.Add(str);
                }
                datasize = Const.StringSize;
            }
            else if (typeof(T) == typeof(DateTime))
            {
                foreach (var vv in valIndex)
                {
                    re.Add(datafile.ReadDateTime(offset + valueaddr + vv * 8));
                }
                datasize = 8;
            }
            else if (typeof(T) == typeof(IntPointData))
            {
                foreach (var vv in valIndex)
                {
                    var x = datafile.ReadInt(offset + valueaddr + vv * 8);
                    var y = datafile.ReadInt(offset + valueaddr + vv * 8 + 4);
                    re.Add(new IntPointData()
                    {
                        X = x, Y = y
                    });
                }
                datasize = 8;
            }
            else if (typeof(T) == typeof(UIntPointData))
            {
                foreach (var vv in valIndex)
                {
                    var x = (uint)datafile.ReadInt(offset + valueaddr + vv * 8);
                    var y = (uint)datafile.ReadInt(offset + valueaddr + vv * 8 + 4);
                    re.Add(new UIntPointData()
                    {
                        X = x, Y = y
                    });
                }
                datasize = 8;
            }
            else if (typeof(T) == typeof(LongPointData))
            {
                foreach (var vv in valIndex)
                {
                    var x = (long)datafile.ReadLong(offset + valueaddr + vv * 16);
                    var y = (long)datafile.ReadLong(offset + valueaddr + vv * 16 + 8);
                    re.Add(new LongPointData()
                    {
                        X = x, Y = y
                    });
                }
                datasize = 16;
            }
            else if (typeof(T) == typeof(ULongPointData))
            {
                foreach (var vv in valIndex)
                {
                    var x = (ulong)datafile.ReadLong(offset + valueaddr + vv * 16);
                    var y = (ulong)datafile.ReadLong(offset + valueaddr + vv * 16 + 8);
                    re.Add(new ULongPointData()
                    {
                        X = x, Y = y
                    });
                }
                datasize = 16;
            }
            else if (typeof(T) == typeof(IntPoint3Data))
            {
                foreach (var vv in valIndex)
                {
                    var x = datafile.ReadInt(offset + valueaddr + vv * 12);
                    var y = datafile.ReadInt(offset + valueaddr + vv * 12 + 4);
                    var z = datafile.ReadInt(offset + valueaddr + vv * 12 + 8);
                    re.Add(new IntPoint3Data()
                    {
                        X = x, Y = y, Z = z
                    });
                }
                datasize = 12;
            }
            else if (typeof(T) == typeof(UIntPoint3Data))
            {
                foreach (var vv in valIndex)
                {
                    var x = (uint)datafile.ReadInt(offset + valueaddr + vv * 12);
                    var y = (uint)datafile.ReadInt(offset + valueaddr + vv * 12 + 4);
                    var z = (uint)datafile.ReadInt(offset + valueaddr + vv * 12 + 8);
                    re.Add(new UIntPoint3Data()
                    {
                        X = x, Y = y, Z = z
                    });
                }
                datasize = 12;
            }
            else if (typeof(T) == typeof(LongPoint3Data))
            {
                foreach (var vv in valIndex)
                {
                    var x = (long)datafile.ReadLong(offset + valueaddr + vv * 24);
                    var y = (long)datafile.ReadLong(offset + valueaddr + vv * 24 + 8);
                    var z = (long)datafile.ReadLong(offset + valueaddr + vv * 24 + 168);
                    re.Add(new LongPoint3Data()
                    {
                        X = x, Y = y, Z = z
                    });
                }
                datasize = 24;
            }
            else if (typeof(T) == typeof(ULongPoint3Data))
            {
                foreach (var vv in valIndex)
                {
                    var x = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24);
                    var y = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24 + 8);
                    var z = (ulong)datafile.ReadLong(offset + valueaddr + vv * 24 + 168);
                    re.Add(new ULongPoint3Data()
                    {
                        X = x, Y = y, Z = z
                    });
                }
                datasize = 24;
            }
            datasize = 0;
            return(re);
        }