Exemple #1
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++;
                }
            }
        }
Exemple #2
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);
        }
Exemple #3
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);
                }
            }
        }
Exemple #4
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);
                 }
             }
         }
     }
 }
Exemple #5
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;
                        }
                    }
                }
            }
        }
Exemple #6
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);
        }