Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="file"></param>
        /// <param name="tid"></param>
        /// <param name="times"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static HisQueryResult <T> Read <T>(this DataFileInfo4 file, int tid, List <DateTime> times, QueryValueMatchType type)
        {
            HisQueryResult <T> re = new HisQueryResult <T>(times.Count);

            Read <T>(file, tid, times, type, re);
            return(re);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public HisQueryResult <T> ReadAllValue <T>(int id, DateTime startTime, DateTime endTime)
        {
            int valueCount = (int)(endTime - startTime).TotalSeconds;
            var result     = new HisQueryResult <T>(valueCount);

            ReadAllValue(id, startTime, endTime, result);
            return(result as HisQueryResult <T>);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="times"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public HisQueryResult <T> ReadValue <T>(int id, List <DateTime> times, QueryValueMatchType type)
        {
            int valueCount = times.Count;

            var result = new HisQueryResult <T>(valueCount);

            ReadValue(id, times, type, result);
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="times"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public HisQueryResult <T> ReadValueByUTCTime <T>(int id, IEnumerable <DateTime> times, QueryValueMatchType type)
        {
            int valueCount = times.Count();

            var result = new HisQueryResult <T>(valueCount);

            ReadValueByUTCTime(id, times, type, result);
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public HisQueryResult <T> Contracts()
        {
            HisQueryResult <T> re = new HisQueryResult <T>(this.Count);

            Buffer.MemoryCopy((void *)this.handle, (void *)re.handle, re.Size, mDataSize * Count);
            Buffer.MemoryCopy((void *)(this.handle + mTimeAddr), (void *)(re.handle + re.mTimeAddr), re.Size, 8 * Count);
            Buffer.MemoryCopy((void *)(this.handle + mQulityAddr), (void *)(re.handle + re.mQulityAddr), re.Size, Count);
            re.mCount = this.mCount;
            return(re);
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        public void CloneTo(HisQueryResult <T> target)
        {
            if (target.mLimite < this.mLimite)
            {
                target.Resize(this.mLimite);
            }

            Buffer.MemoryCopy((void *)handle, (void *)target.handle, mLimite, this.mSize);
            target.mCount    = this.mCount;
            target.mPosition = this.mPosition;
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="result"></param>
        public void ReadAllValue <T>(int id, DateTime startTime, DateTime endTime, HisQueryResult <T> result)
        {
            Tuple <DateTime, DateTime> mLogFileTimes;
            var vfiles = GetFileManager().GetDataFiles(startTime, endTime, out mLogFileTimes, id);

            vfiles.ForEach(e => {
                DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime;
                DateTime eend   = e.EndTime > endTime ? endTime : endTime;
                e.ReadAllValue(id, sstart, eend, result);
            });

            if (mLogFileTimes.Item1 != DateTime.MinValue)
            {
                ReadLogFileAllValue(id, mLogFileTimes.Item1, mLogFileTimes.Item2, result);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datafile"></param>
        /// <param name="tid"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="time"></param>
        /// <param name="result"></param>
        public static void ReadAllValue <T>(this DataFileSeriserbase datafile, int tid, DateTime startTime, DateTime endTime, DateTime time, HisQueryResult <T> result)
        {
            long  addroffset = 0;
            short len        = 0;
            int   datasize   = 0;

            if (!datafile.IsOpened())
            {
                return;
            }

            var aid = datafile.ReadTagIndex(tid, out addroffset, out len);

            if (!aid.IsEmpty())
            {
                int tagcount = len * 60;
                var tindex   = ReadTimeIndex(datafile, 0, aid.Address, startTime, endTime, time, tagcount);
                var vals     = ReadValueInner <T>(datafile, tindex.Keys.ToList(), 0, aid.Address + tagcount * 2, out datasize);
                var qus      = datafile.ReadBytes(aid.Address + 0 + tagcount * (2 + datasize), tagcount);
                int i        = 0;
                foreach (var vv in tindex)
                {
                    if (qus[vv.Key] < 100)
                    {
                        result.Add(vals[i], vv.Value, qus[vv.Key]);
                    }
                    i++;
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="file"></param>
 /// <param name="tid"></param>
 /// <param name="times"></param>
 /// <param name="type"></param>
 /// <param name="result"></param>
 public static void Read <T>(this LogFileInfo file, int tid, List <DateTime> times, QueryValueMatchType type, HisQueryResult <T> result)
 {
     file.GetFileSeriser().Read(tid, times, type, file.StartTime, result);
 }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="file"></param>
 /// <param name="tid"></param>
 /// <param name="startTime"></param>
 /// <param name="endTime"></param>
 /// <param name="result"></param>
 public static void ReadAllValue <T>(this LogFileInfo file, int tid, DateTime startTime, DateTime endTime, HisQueryResult <T> result)
 {
     file.GetFileSeriser().ReadAllValue(tid, startTime, endTime, file.StartTime, result);
 }
Exemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datafile"></param>
        /// <param name="offset"></param>
        /// <param name="tid"></param>
        /// <param name="dataTimes"></param>
        /// <param name="type"></param>
        /// <param name="res"></param>
        public static void Read <T>(DataFileSeriserbase datafile, long offset, int tid, List <DateTime> dataTimes, QueryValueMatchType type, HisQueryResult <T> res)
        {
            int timetick = 0;
            var data     = ReadTagDataBlock2(datafile, tid, offset, dataTimes, out timetick);

            foreach (var vv in data)
            {
                var index = vv.Value.Item2;
                DeCompressDataBlockValue <T>(vv.Key, vv.Value.Item1, timetick, type, res, new Func <byte, object>((tp) => {
                    object oval = null;
                    int ttick   = 0;
                    int dindex  = index;
                    if (tp == 0)
                    {
                        //往前读最后一个有效值
                        do
                        {
                            dindex--;
                            if (dindex < 0)
                            {
                                return(TagHisValue <T> .Empty);
                            }
                            var datas = ReadTagDataBlock(datafile, tid, offset, dindex, out ttick);
                            if (datas == null)
                            {
                                return(null);
                            }
                            oval = DeCompressDataBlockRawValue <T>(datas, 0);
                        }while (oval == null);
                    }
                    else
                    {
                        //往后读第一个有效值
                        do
                        {
                            dindex++;

                            if (dindex > 47)
                            {
                                return(TagHisValue <T> .Empty);
                            }

                            var datas = ReadTagDataBlock(datafile, tid, offset, dindex, out ttick);
                            if (datas == null)
                            {
                                return(null);
                            }
                            oval = DeCompressDataBlockRawValue <T>(datas, 1);
                        }while (oval == null);
                    }
                    return(oval);
                }));
            }
            foreach (var vv in data)
            {
                vv.Key.Dispose();
            }
            data.Clear();
        }
Exemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="id"></param>
 /// <param name="startTime"></param>
 /// <param name="endTime"></param>
 /// <param name="result"></param>
 public void ReadAllValue <T>(int id, DateTime startTime, DateTime endTime, HisQueryResult <T> result)
 {
     ReadAllValueByUTCTime <T>(id, startTime.ToUniversalTime(), endTime.ToUniversalTime(), result);
     result.ConvertUTCTimeToLocal();
 }
Exemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="sourceAddr"></param>
 /// <param name="time"></param>
 /// <param name="timeTick"></param>
 /// <param name="type"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public abstract int DeCompressValue <T>(MarshalMemoryBlock source, int sourceAddr, List <DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult <T> result);
Exemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="result"></param>
        private void ReadLogFileAllValue <T>(int id, DateTime startTime, DateTime endTime, HisQueryResult <T> result)
        {
            var vfiles = GetFileManager().GetLogDataFiles(startTime, endTime);

            vfiles.ForEach(e => {
                DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime;
                DateTime eend   = e.EndTime > endTime ? endTime : endTime;
                e.ReadAllValue <T>(id, sstart, eend, result);
            });
        }
Exemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="mLogTimes"></param>
        /// <param name="result"></param>
        private void ReadLogFile <T>(int id, List <DateTime> mLogTimes, QueryValueMatchType type, HisQueryResult <T> result)
        {
            if (mLogTimes.Count > 0)
            {
                List <DateTime> mtime  = new List <DateTime>();
                var             lfiles = GetFileManager().GetLogDataFiles(mLogTimes);

                LogFileInfo mPlFile = null;

                foreach (var vv in lfiles)
                {
                    if (vv.Value == null)
                    {
                        if (mPlFile != null)
                        {
                            mPlFile.Read <T>(id, mtime, type, result);
                            mPlFile = null;
                            mtime.Clear();
                        }
                        result.Add(default(T), vv.Key, (byte)QualityConst.Null);
                    }
                    else if (vv.Value != mPlFile)
                    {
                        if (mPlFile != null)
                        {
                            mPlFile.Read <T>(id, mtime, type, result);
                        }
                        mPlFile = vv.Value;
                        mtime.Clear();
                        mtime.Add(vv.Key);
                    }
                    else
                    {
                        mtime.Add(vv.Key);
                    }
                }
                if (mPlFile != null)
                {
                    mPlFile.Read <T>(id, mtime, type, result);
                }
            }
        }
Exemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="sourceAddr"></param>
 /// <param name="time"></param>
 /// <param name="timeTick"></param>
 /// <param name="type"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public abstract int DeCompressValue <T>(MarshalMemoryBlock source, int sourceAddr, List <DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult <T> result, Func <byte, object> ReadOtherDatablockAction);
Exemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="times"></param>
        /// <param name="type"></param>
        /// <param name="result"></param>
        public void ReadValueByUTCTime <T>(int id, IEnumerable <DateTime> times, QueryValueMatchType type, HisQueryResult <T> result)
        {
            List <DateTime> ltmp         = new List <DateTime>();
            List <DateTime> mMemoryTimes = new List <DateTime>();

            //判断数据是否在内存中
            if (IsCanQueryFromMemory())
            {
                foreach (var vv in times)
                {
                    if (!mMemoryService.CheckTime(id, vv))
                    {
                        ltmp.Add(vv);
                    }
                    else
                    {
                        mMemoryTimes.Add(vv);
                    }
                }
            }
            else
            {
                ltmp.AddRange(times);
            }

            List <DateTime> mLogTimes = new List <DateTime>();
            var             vfiles    = GetFileManager().GetDataFiles(ltmp, mLogTimes, id);

            DataFileInfo4 mPreFile = null;

            List <DateTime> mtime = new List <DateTime>();

            //从历史文件中读取数据
            foreach (var vv in vfiles)
            {
                if (vv.Value == null)
                {
                    if (mPreFile != null)
                    {
                        if (mPreFile is HisDataFileInfo4)
                        {
                            (mPreFile as HisDataFileInfo4).Read(id, mtime, type, result);
                        }
                        else
                        {
                            mPreFile.Read <T>(id, mtime, type, result);
                        }
                        mPreFile = null;
                        mtime.Clear();
                    }
                    result.Add(default(T), vv.Key, (byte)QualityConst.Null);
                }
                else if (vv.Value != mPreFile)
                {
                    if (mPreFile != null)
                    {
                        if (mPreFile is HisDataFileInfo4)
                        {
                            (mPreFile as HisDataFileInfo4).Read(id, mtime, type, result);
                        }
                        else
                        {
                            mPreFile.Read <T>(id, mtime, type, result);
                        }
                    }
                    mPreFile = vv.Value;
                    mtime.Clear();
                    mtime.Add(vv.Key);
                }
                else
                {
                    mtime.Add(vv.Key);
                }
            }
            if (mPreFile != null)
            {
                if (mPreFile is HisDataFileInfo4)
                {
                    (mPreFile as HisDataFileInfo4).Read(id, mtime, type, result);
                }
                else
                {
                    mPreFile.Read <T>(id, mtime, type, result);
                }
            }

            //从日志文件中读取数据
            ReadLogFile(id, mLogTimes, type, result);

            //从内存中读取数据
            ReadFromMemory(id, mMemoryTimes, type, result);
        }
Exemplo n.º 18
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="id"></param>
 /// <param name="times"></param>
 /// <param name="type"></param>
 /// <param name="result"></param>
 public void ReadValue <T>(int id, IEnumerable <DateTime> times, QueryValueMatchType type, HisQueryResult <T> result)
 {
     ReadValueByUTCTime <T>(id, times.Select(e => e.ToUniversalTime()), type, result);
     result.ConvertUTCTimeToLocal();
 }
Exemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="file"></param>
        /// <param name="tid"></param>
        /// <param name="times"></param>
        /// <param name="type"></param>
        /// <param name="startTime"></param>
        /// <param name="result"></param>
        public static void Read <T>(this DataFileSeriserbase datafile, int tid, List <DateTime> times, QueryValueMatchType type, DateTime startTime, HisQueryResult <T> result)
        {
            long  addroffset = 0;
            short len        = 0;
            int   datasize   = 0;

            if (!datafile.IsOpened())
            {
                return;
            }

            var aid = datafile.ReadTagIndex(tid, out addroffset, out len);

            if (!aid.IsEmpty())
            {
                int tagcount = len * 60;
                var qs       = ReadTimeIndex(datafile, 0, aid.Address, startTime, tagcount);

                var vals = ReadValueInner <T>(datafile, qs.Keys.ToList(), 0, aid.Address + tagcount * 2, out datasize);
                var qq   = datafile.ReadBytes(aid.Address + 0 + tagcount * (datasize + 2), tagcount);

                var vv = qs.ToArray();
                //long valaddr = addroffset + tagcount * 2;
                int count = 0;
                foreach (var time1 in times)
                {
                    for (int i = 0; i < vv.Length - 1; i++)
                    {
                        var skey = vv[i];

                        var snext = vv[i + 1];

                        if (time1 == skey.Value.Item1)
                        {
                            result.Add(vals[i], time1, qq[skey.Key]);
                            count++;
                            break;
                        }
                        else if (time1 > skey.Value.Item1 && time1 < snext.Value.Item1)
                        {
                            switch (type)
                            {
                            case QueryValueMatchType.Previous:
                                result.Add(vals[i], time1, qq[skey.Key]);
                                count++;
                                break;

                            case QueryValueMatchType.After:
                                result.Add(vals[i + 1], time1, qq[snext.Key]);
                                count++;
                                break;

                            case QueryValueMatchType.Linear:
                                if (typeof(T) == typeof(bool) || typeof(T) == typeof(string) || typeof(T) == typeof(DateTime))
                                {
                                    var ppval = (time1 - skey.Value.Item1).TotalMilliseconds;
                                    var ffval = (snext.Value.Item1 - time1).TotalMilliseconds;

                                    if (ppval < ffval)
                                    {
                                        result.Add(vals[i], time1, qq[skey.Key]);
                                    }
                                    else
                                    {
                                        result.Add(vals[i + 1], time1, qq[snext.Key]);
                                    }
                                    count++;
                                }
                                else
                                {
                                    if (qq[skey.Key] < 20 && qq[snext.Key] < 20)
                                    {
                                        if (CheckTypeIsPointData(typeof(T)))
                                        {
                                            result.Add(LinerValue(skey.Value.Item1, snext.Value.Item1, time1, vals[i], vals[i + 1]), time1, 0);
                                        }
                                        else
                                        {
                                            var pval1 = (time1 - skey.Value.Item1).TotalMilliseconds;
                                            var tval1 = (snext.Value.Item1 - skey.Value.Item1).TotalMilliseconds;
                                            var sval1 = (double)vals[i];
                                            var sval2 = (double)vals[i + 1];
                                            var val1  = pval1 / tval1 * (sval2 - sval1) + sval1;
                                            result.Add((object)val1, time1, 0);
                                        }
                                    }
                                    else if (qq[skey.Key] < 20)
                                    {
                                        result.Add(vals[i], time1, qq[skey.Key]);
                                    }
                                    else if (qq[snext.Key] < 20)
                                    {
                                        result.Add(vals[i + 1], time1, qq[snext.Key]);
                                    }
                                    else
                                    {
                                        result.Add(default(T), time1, (byte)QualityConst.Null);
                                    }
                                }
                                count++;
                                break;

                            case QueryValueMatchType.Closed:
                                var pval = (time1 - skey.Value.Item1).TotalMilliseconds;
                                var fval = (snext.Value.Item1 - time1).TotalMilliseconds;

                                if (pval < fval)
                                {
                                    result.Add(vals[i], time1, qq[skey.Key]);
                                }
                                else
                                {
                                    result.Add(vals[i + 1], time1, qq[snext.Key]);
                                }
                                count++;
                                break;
                            }

                            break;
                        }
                        else if (time1 == snext.Value.Item1)
                        {
                            result.Add(vals[i + 1], time1, qq[snext.Key]);
                            count++;
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <param name="timeTick"></param>
        ///// <returns></returns>
        //public abstract bool? DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr,DateTime time,int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressBoolValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<bool> result);

        ///// <summary>
        ///// 解压缩某个事件段内所有值
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime,DateTime endTime, int timeTick, HisQueryResult<bool> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract byte? DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressByteValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<byte> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<byte> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract short? DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressShortValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<short> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<short> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract ushort? DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressUShortValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<ushort> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<ushort> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int? DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressIntValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<int> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<int> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract uint? DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressUIntValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<uint> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<uint> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract long? DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressLongValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<long> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<long> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract ulong? DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressULongValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<ulong> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<ulong> result);



        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <param name="timeTick"></param>
        ///// <returns></returns>
        //public abstract float? DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <param name="timeTick"></param>
        ///// <returns></returns>
        //public abstract int DeCompressFloatValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<float> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<float> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <param name="timeTick"></param>
        ///// <returns></returns>
        //public abstract double? DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <param name="timeTick"></param>
        ///// <returns></returns>
        //public abstract int DeCompressDoubleValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<double> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<double> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract DateTime? DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressDateTimeValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<DateTime> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<DateTime> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract string DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, DateTime time, int timeTick, QueryValueMatchType type);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="time"></param>
        ///// <returns></returns>
        //public abstract int DeCompressStringValue(MarshalMemoryBlock source, int sourceAddr, List<DateTime> time, int timeTick, QueryValueMatchType type, HisQueryResult<string> result);

        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="source"></param>
        ///// <param name="sourceAddr"></param>
        ///// <param name="startTime"></param>
        ///// <param name="endTime"></param>
        ///// <param name="timeTick"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public abstract int DeCompressAllValue(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult<string> result);


        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="sourceAddr"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="timeTick"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public abstract int DeCompressAllValue <T>(MarshalMemoryBlock source, int sourceAddr, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult <T> result);
Exemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="memory"></param>
        /// <param name="datatime"></param>
        /// <param name="timeTick"></param>
        /// <param name="type"></param>
        /// <param name="result"></param>
        private static void DeCompressDataBlockValue <T>(MarshalMemoryBlock memory, List <DateTime> datatime, int timeTick, QueryValueMatchType type, HisQueryResult <T> result, Func <byte, object> ReadOtherDatablockAction)
        {
            //MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length);
            //读取压缩类型
            var ctype = memory.ReadByte();
            var tp    = CompressUnitManager2.Manager.GetCompress(ctype);

            if (tp != null)
            {
                tp.DeCompressValue <T>(memory, 1, datatime, timeTick, type, result, ReadOtherDatablockAction);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// 读取某时间段内的所有bool值
        /// </summary>
        /// <param name="file"></param>
        /// <param name="tid"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="result"></param>
        public static void ReadAllValue <T>(this DataFileInfo4 file, int tid, DateTime startTime, DateTime endTime, HisQueryResult <T> result)
        {
            //long ltmp = 0, ltmp1 = 0;
            //Stopwatch sw = new Stopwatch();
            //sw.Start();
            var offset = file.GetFileOffsets(startTime, endTime);

            var vff = file.GetFileSeriser();

            //ltmp = sw.ElapsedMilliseconds;

            foreach (var vv in offset)
            {
                DateTime stime = vv.Key > startTime ? vv.Key : startTime;
                DateTime etime = vv.Key + vv.Value.Item1 > endTime ? endTime : vv.Key + vv.Value.Item1;
                ReadAllValue(vff, vv.Value.Item2, tid, stime, etime, result);
            }

            //ltmp1 = sw.ElapsedMilliseconds;
            //vff.Close();
            vff.Dispose();

            //sw.Stop();
            //Debug.WriteLine("ReadAllValue:" + ltmp + " ," + (ltmp1 - ltmp) + "," + (sw.ElapsedMilliseconds - ltmp1));
        }
Exemplo n.º 23
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="id"></param>
 /// <param name="starttime"></param>
 /// <param name="endTime"></param>
 /// <param name="result"></param>
 private void ReadAllValueFromMemory <T>(int id, DateTime starttime, DateTime endTime, HisQueryResult <T> result)
 {
     mMemoryService?.ReadAllValue(id, starttime, endTime, result);
 }
Exemplo n.º 24
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="file"></param>
 /// <param name="tid"></param>
 /// <param name="times"></param>
 /// <param name="type"></param>
 /// <param name="result"></param>
 public static void Read <T>(this DataFileInfo4 file, int tid, List <DateTime> times, QueryValueMatchType type, HisQueryResult <T> result)
 {
     using (var vff = file.GetFileSeriser())
     {
         Dictionary <long, List <DateTime> > moffs = new Dictionary <long, List <DateTime> >();
         foreach (var vv in times)
         {
             var ff = file.GetFileOffsets(vv);
             if (moffs.ContainsKey(ff))
             {
                 moffs[ff].Add(vv);
             }
             else
             {
                 moffs.Add(ff, new List <DateTime>()
                 {
                     vv
                 });
             }
         }
         foreach (var vf in moffs)
         {
             if (vf.Key > -1)
             {
                 Read <T>(vff, vf.Key, tid, vf.Value, type, result);
             }
             else
             {
                 foreach (var vv in vf.Value)
                 {
                     result.Add(default(T), vv, (byte)QualityConst.Null);
                 }
             }
         }
     }
 }
Exemplo n.º 25
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="times"></param>
        /// <param name="type"></param>
        /// <param name="result"></param>
        public void ReadValue <T>(int id, List <DateTime> times, QueryValueMatchType type, HisQueryResult <T> result)
        {
            List <DateTime> mLogTimes = new List <DateTime>();
            var             vfiles    = GetFileManager().GetDataFiles(times, mLogTimes, id);

            DataFileInfo mPreFile = null;

            List <DateTime> mtime = new List <DateTime>();

            foreach (var vv in vfiles)
            {
                if (vv.Value == null)
                {
                    if (mPreFile != null)
                    {
                        mPreFile.Read <T>(id, mtime, type, result);
                        mPreFile = null;
                        mtime.Clear();
                    }
                    result.Add(false, vv.Key, (byte)QualityConst.Null);
                }
                else if (vv.Value != mPreFile)
                {
                    if (mPreFile != null)
                    {
                        mPreFile.Read <T>(id, mtime, type, result);
                    }
                    mPreFile = vv.Value;
                    mtime.Clear();
                    mtime.Add(vv.Key);
                }
                else
                {
                    mtime.Add(vv.Key);
                }
            }
            if (mPreFile != null)
            {
                mPreFile.Read <T>(id, mtime, type, result);
            }

            ReadLogFile(id, mLogTimes, type, result);
        }
Exemplo n.º 26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="datafile"></param>
 /// <param name="offset"></param>
 /// <param name="tid"></param>
 /// <param name="startTime"></param>
 /// <param name="endTime"></param>
 /// <param name="result"></param>
 public static void ReadAllValue <T>(DataFileSeriserbase datafile, long offset, int tid, DateTime startTime, DateTime endTime, HisQueryResult <T> result)
 {
     //Stopwatch sw = new Stopwatch();
     //sw.Start();
     foreach (var vv in ReadTagDataBlock2(datafile, tid, offset, startTime, endTime))
     {
         if (vv != null)
         {
             DeCompressDataBlockAllValue(vv.Item1, vv.Item2, vv.Item3, vv.Item4, result);
             vv.Item1.Dispose();
         }
     }
     //sw.Stop();
     //Debug.WriteLine("Read all value:" + sw.ElapsedMilliseconds + " file:" + datafile.FileName);
 }
Exemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="result"></param>
        public void ReadAllValueByUTCTime <T>(int id, DateTime startTime, DateTime endTime, HisQueryResult <T> result)
        {
            try
            {
                DateTime etime = endTime, stime = startTime;
                DateTime memoryTime = DateTime.MaxValue;
                if (IsCanQueryFromMemory())
                {
                    memoryTime = mMemoryService.GetStartMemoryTime(id);
                }

                if (startTime >= memoryTime)
                {
                    ReadAllValueFromMemory(id, startTime, endTime, result);
                }
                else
                {
                    var fileMananger = GetFileManager();

                    ////优先从日志中读取历史记录
                    //memoryTime = fileMananger.LastLogTime > memoryTime ? fileMananger.LastLogTime : memoryTime;

                    if (endTime > memoryTime)
                    {
                        etime = memoryTime;
                    }

                    Tuple <DateTime, DateTime> mLogFileTimes;
                    var vfiles = fileMananger.GetDataFiles(stime, etime, out mLogFileTimes, id);
                    //ltmp0 = sw.ElapsedMilliseconds;
                    //从历史记录中读取数据
                    foreach (var e in vfiles)
                    {
                        DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime;
                        DateTime eend   = e.EndTime > endTime ? endTime : e.EndTime;
                        if (e is HisDataFileInfo4)
                        {
                            (e as HisDataFileInfo4).ReadAllValue(id, startTime, endTime, result);
                        }
                        else
                        {
                            e.ReadAllValue(id, sstart, eend, result);
                        }
                    }

                    //从日志文件中读取数据
                    if (mLogFileTimes.Item1 < mLogFileTimes.Item2)
                    {
                        ReadLogFileAllValue(id, mLogFileTimes.Item1, mLogFileTimes.Item2, result);
                    }

                    //从内存中读取数据
                    if (endTime > memoryTime)
                    {
                        ReadAllValueFromMemory(id, memoryTime, endTime, result);
                    }
                    //ltmp2 = sw.ElapsedMilliseconds;
                }

                //sw.Stop();

                //Debug.Print("ReadAllValueByUTCTime "+ ltmp0 +" , " +(ltmp1-ltmp0)+" , "+(ltmp2-ltmp1));
            }
            catch (Exception ex)
            {
                LoggerService.Service.Erro("QueryService", ex.StackTrace);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="memory"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="timeTick"></param>
        /// <param name="result"></param>
        private static void DeCompressDataBlockAllValue <T>(MarshalMemoryBlock memory, DateTime startTime, DateTime endTime, int timeTick, HisQueryResult <T> result)
        {
            //MarshalMemoryBlock target = new MarshalMemoryBlock(memory.Length);
            //读取压缩类型
            var ctype = memory.ReadByte();
            var tp    = CompressUnitManager2.Manager.GetCompress(ctype);

            if (tp != null)
            {
                tp.DeCompressAllValue(memory, 1, startTime, endTime, timeTick, result);
            }
        }
Exemplo n.º 29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <param name="times"></param>
 /// <param name="type"></param>
 /// <param name="result"></param>
 private void ReadFromMemory <T>(int id, List <DateTime> times, QueryValueMatchType type, HisQueryResult <T> result)
 {
     mMemoryService?.ReadValue(id, times, type, result);
 }