From d729b1946dc24946d1de9432d5539b5d3af30452 Mon Sep 17 00:00:00 2001 From: Candy Date: Mon, 12 Oct 2020 17:57:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AD=98=E4=B8=AD=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/Cdy.Tag.Common/Common/DateTimeSpan.cs | 106 ++ Common/Cdy.Tag/His/DataFileSeriserbase.cs | 6 + Common/Cdy.Tag/Interface/IHisQuery.cs | 114 +- .../Cdy.Tag/Interface/IHisQueryFromMemory.cs | 56 + .../Consumer/DBGrpcApiDemo/MainViewModel.cs | 69 ++ .../Consumer/DBGrpcApiDemo/MainWindow.xaml | 19 +- RunTime/DBHisData/HisQuery/DataFileManager.cs | 28 +- RunTime/DBHisData/HisQuery/QuerySerivce.cs | 118 +- .../HisQuery/TimeFile/DataFileInfo.cs | 79 -- .../HisQuery/TimeFile/LogFileInfo.cs | 5 + .../DBInRun/Properties/launchSettings.json | 2 +- .../His/Compress/CompressEnginer2.cs | 1 + .../DBRuntime/His/Compress/CompressMemory2.cs | 2 + .../His/HisDataMemoryQueryService.cs | 1020 +++++++++++++++++ RunTime/DBRuntime/His/HisEnginer2.cs | 61 +- RunTime/DBRuntime/His/LocalFileSeriser.cs | 10 +- .../His/TimerMemoryCacheProcesser2.cs | 2 +- RunTime/DBRuntime/Runner.cs | 6 + .../Properties/launchSettings.json | 2 +- 19 files changed, 1464 insertions(+), 242 deletions(-) create mode 100644 Common/Cdy.Tag.Common/Common/DateTimeSpan.cs create mode 100644 Common/Cdy.Tag/Interface/IHisQueryFromMemory.cs create mode 100644 RunTime/DBRuntime/His/HisDataMemoryQueryService.cs diff --git a/Common/Cdy.Tag.Common/Common/DateTimeSpan.cs b/Common/Cdy.Tag.Common/Common/DateTimeSpan.cs new file mode 100644 index 0000000..e21558f --- /dev/null +++ b/Common/Cdy.Tag.Common/Common/DateTimeSpan.cs @@ -0,0 +1,106 @@ +//============================================================== +// Copyright (C) 2020 Inc. All rights reserved. +// +//============================================================== +// Create by 种道洋 at 2020/10/12 10:06:58. +// Version 1.0 +// 种道洋 +//============================================================== + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Cdy.Tag +{ + /// + /// + /// + public class DateTimeSpan + { + /// + /// + /// + public static DateTimeSpan Empty = new DateTimeSpan() { Start = DateTime.MinValue, End = DateTime.MinValue }; + + /// + /// + /// + public DateTime Start { get; set; } + + /// + /// + /// + public DateTime End { get; set; } + + /// + /// + /// + /// + public bool IsEmpty() + { + return Start == DateTime.MinValue && End == DateTime.MinValue; + } + + /// + /// + /// + /// + public bool IsZore() + { + return (End - Start).TotalSeconds == 0; + } + + /// + /// + /// + /// + /// + public DateTimeSpan Cross(DateTimeSpan target) + { + DateTime stime = Max(target.Start, this.Start); + DateTime etime = Min(target.End, this.End); + if (etime < stime) + { + return Empty; + } + else + { + return new DateTimeSpan() { Start = stime, End = etime }; + } + } + + /// + /// + /// + /// + /// + public bool Contains(DateTime time) + { + return time >= Start & time < End; + } + + /// + /// + /// + /// + /// + /// + public DateTime Min(DateTime time1, DateTime time2) + { + return time1 <= time2 ? time1 : time2; + } + + /// + /// + /// + /// + /// + /// + public DateTime Max(DateTime time1, DateTime time2) + { + return time1 >= time2 ? time1 : time2; + } + + } +} diff --git a/Common/Cdy.Tag/His/DataFileSeriserbase.cs b/Common/Cdy.Tag/His/DataFileSeriserbase.cs index e4642a1..36ec6cc 100644 --- a/Common/Cdy.Tag/His/DataFileSeriserbase.cs +++ b/Common/Cdy.Tag/His/DataFileSeriserbase.cs @@ -66,6 +66,12 @@ namespace Cdy.Tag /// public abstract bool OpenFile(string filename); + /// + /// + /// + /// + public abstract bool IsOpened(); + /// /// /// diff --git a/Common/Cdy.Tag/Interface/IHisQuery.cs b/Common/Cdy.Tag/Interface/IHisQuery.cs index 691bc0c..d73161f 100644 --- a/Common/Cdy.Tag/Interface/IHisQuery.cs +++ b/Common/Cdy.Tag/Interface/IHisQuery.cs @@ -150,118 +150,6 @@ namespace Cdy.Tag /// /// HisQueryResult ReadAllValue(int id, DateTime startTime, DateTime endTime); - - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - ///// - ///// - ///// - ///// - ///// - ///// - ///// - //void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); - - - - + } } diff --git a/Common/Cdy.Tag/Interface/IHisQueryFromMemory.cs b/Common/Cdy.Tag/Interface/IHisQueryFromMemory.cs new file mode 100644 index 0000000..4a21f82 --- /dev/null +++ b/Common/Cdy.Tag/Interface/IHisQueryFromMemory.cs @@ -0,0 +1,56 @@ +//============================================================== +// Copyright (C) 2020 Inc. All rights reserved. +// +//============================================================== +// Create by 种道洋 at 2020/10/12 9:12:46. +// Version 1.0 +// 种道洋 +//============================================================== +using System; +using System.Collections.Generic; +using System.Text; + +namespace Cdy.Tag +{ + /// + /// 从内存中查询数据 + /// + public interface IHisQueryFromMemory + { + /// + /// + /// + /// + /// + /// + bool CheckTime(long id, DateTime time); + /// + /// + /// + /// + /// + DateTime GetStartMemoryTime(long id); + + /// + /// + /// + /// + /// + /// + /// + /// + void ReadValue(int id, List times, QueryValueMatchType type, HisQueryResult result); + + /// + /// + /// + /// + /// + /// + /// + /// + void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult result); + } + + +} diff --git a/Example/Consumer/DBGrpcApiDemo/MainViewModel.cs b/Example/Consumer/DBGrpcApiDemo/MainViewModel.cs index cea18d5..7da71dc 100644 --- a/Example/Consumer/DBGrpcApiDemo/MainViewModel.cs +++ b/Example/Consumer/DBGrpcApiDemo/MainViewModel.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.Diagnostics; using System.Linq; using System.Text; @@ -39,6 +40,13 @@ namespace DBGrpcApiDemo private int mPort = 14333; private ICommand mSetTagValueCommand; + + private ICommand mQueryHisDataCommand; + + private DateTime mStartTime = DateTime.Now.Date; + + private DateTime mEndTime; + #endregion ...Variables... #region ... Events ... @@ -52,6 +60,7 @@ namespace DBGrpcApiDemo public MainViewModel() { Init(); + mEndTime = mStartTime.AddDays(1); } #endregion ...Constructor... @@ -211,6 +220,66 @@ namespace DBGrpcApiDemo } } + /// + /// + /// + public DateTime StartTime + { + get + { + return mStartTime; + } + set + { + if (mStartTime != value) + { + mStartTime = value; + OnPropertyChanged("StartTime"); + } + } + } + + /// + /// + /// + public DateTime EndTime + { + get + { + return mEndTime; + } + set + { + if (mEndTime != value) + { + mEndTime = value; + OnPropertyChanged("EndTime"); + } + } + } + + + public ICommand QueryHisDataCommand + { + get + { + if (mQueryHisDataCommand == null) + { + mQueryHisDataCommand = new RelayCommand(() => + { + var vals = clinet.ReadAllHisValue(new List { "tag2" }, StartTime, EndTime); + if (vals != null&&vals.Count>0) + { + MessageBox.Show("读取历史数据个数:" + vals.First().Value.Count); + } + }); + } + return mQueryHisDataCommand; + } + } + + + #endregion ...Properties... #region ... Methods ... diff --git a/Example/Consumer/DBGrpcApiDemo/MainWindow.xaml b/Example/Consumer/DBGrpcApiDemo/MainWindow.xaml index 5d97606..1a474c7 100644 --- a/Example/Consumer/DBGrpcApiDemo/MainWindow.xaml +++ b/Example/Consumer/DBGrpcApiDemo/MainWindow.xaml @@ -9,8 +9,8 @@ - - + +