提交 d729b194 编写于 作者: cdy816's avatar cdy816

内存中查询数据

上级 28dd7768
//==============================================================
// 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
{
/// <summary>
///
/// </summary>
public class DateTimeSpan
{
/// <summary>
///
/// </summary>
public static DateTimeSpan Empty = new DateTimeSpan() { Start = DateTime.MinValue, End = DateTime.MinValue };
/// <summary>
///
/// </summary>
public DateTime Start { get; set; }
/// <summary>
///
/// </summary>
public DateTime End { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool IsEmpty()
{
return Start == DateTime.MinValue && End == DateTime.MinValue;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool IsZore()
{
return (End - Start).TotalSeconds == 0;
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
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 };
}
}
/// <summary>
///
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public bool Contains(DateTime time)
{
return time >= Start & time < End;
}
/// <summary>
///
/// </summary>
/// <param name="time1"></param>
/// <param name="time2"></param>
/// <returns></returns>
public DateTime Min(DateTime time1, DateTime time2)
{
return time1 <= time2 ? time1 : time2;
}
/// <summary>
///
/// </summary>
/// <param name="time1"></param>
/// <param name="time2"></param>
/// <returns></returns>
public DateTime Max(DateTime time1, DateTime time2)
{
return time1 >= time2 ? time1 : time2;
}
}
}
......@@ -66,6 +66,12 @@ namespace Cdy.Tag
/// <returns></returns>
public abstract bool OpenFile(string filename);
/// <summary>
///
/// </summary>
/// <returns></returns>
public abstract bool IsOpened();
/// <summary>
///
/// </summary>
......
......@@ -150,118 +150,6 @@ namespace Cdy.Tag
/// <param name="endTime"></param>
/// <returns></returns>
HisQueryResult<T> ReadAllValue<T>(int id, DateTime startTime, DateTime endTime);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<bool> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<byte> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<short> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<ushort> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<int> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<uint> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<long> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<ulong> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<float> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<double> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<DateTime> result);
///// <summary>
/////
///// </summary>
///// <param name="id"></param>
///// <param name="startTime"></param>
///// <param name="endTime"></param>
///// <param name="result"></param>
//void ReadAllValue(int id, DateTime startTime, DateTime endTime, HisQueryResult<string> result);
}
}
//==============================================================
// 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
{
/// <summary>
/// 从内存中查询数据
/// </summary>
public interface IHisQueryFromMemory
{
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="time"></param>
/// <returns></returns>
bool CheckTime(long id, DateTime time);
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
DateTime GetStartMemoryTime(long id);
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="id"></param>
/// <param name="times"></param>
/// <param name="type"></param>
/// <param name="result"></param>
void ReadValue<T>(int id, List<DateTime> times, QueryValueMatchType type, HisQueryResult<T> result);
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="id"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="result"></param>
void ReadAllValue<T>(int id, DateTime startTime, DateTime endTime, HisQueryResult<T> result);
}
}
......@@ -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
}
}
/// <summary>
///
/// </summary>
public DateTime StartTime
{
get
{
return mStartTime;
}
set
{
if (mStartTime != value)
{
mStartTime = value;
OnPropertyChanged("StartTime");
}
}
}
/// <summary>
///
/// </summary>
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<string> { "tag2" }, StartTime, EndTime);
if (vals != null&&vals.Count>0)
{
MessageBox.Show("读取历史数据个数:" + vals.First().Value.Count);
}
});
}
return mQueryHisDataCommand;
}
}
#endregion ...Properties...
#region ... Methods ...
......
......@@ -9,8 +9,8 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="382*"/>
<RowDefinition Height="32"/>
<RowDefinition Height="*"/>
<RowDefinition Height="64"/>
</Grid.RowDefinitions>
<Label Content="Server:" HorizontalAlignment="Left" Margin="11,0,0,0" VerticalAlignment="Center"/>
<TextBox x:Name="ServerIp" HorizontalAlignment="Left" Margin="67,0,0,0" Text="{Binding Ip,Mode=TwoWay,UpdateSourceTrigger=LostFocus}" TextWrapping="Wrap" VerticalAlignment="Center" Width="196"/>
......@@ -32,11 +32,16 @@
</DataGrid.Columns>
</DataGrid>
<Label Content="变量ID:" HorizontalAlignment="Left" Margin="10,0,0,0" Grid.Row="2" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Margin="70,0,0,0" Grid.Row="2" Text="{Binding Id,Mode=TwoWay}" TextWrapping="Wrap" VerticalAlignment="Center" Width="100"/>
<TextBox HorizontalAlignment="Left" Margin="259,0,0,0" Grid.Row="2" Text="{Binding Value,Mode=TwoWay}" TextWrapping="Wrap" VerticalAlignment="Center" Width="100"/>
<Button Content="变量下发" HorizontalAlignment="Left" Margin="398,0,0,0" Grid.Row="2" VerticalAlignment="Center" Width="76" Command="{Binding SetTagValueCommand}"/>
<Label Content="变量值:" HorizontalAlignment="Left" Margin="206,0,0,0" Grid.Row="2" VerticalAlignment="Center"/>
<Label Content="变量ID:" HorizontalAlignment="Left" Margin="10,4,0,0" Grid.Row="2" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Margin="70,9,0,0" Grid.Row="2" Text="{Binding Id,Mode=TwoWay}" TextWrapping="Wrap" VerticalAlignment="Top" Width="100"/>
<TextBox HorizontalAlignment="Left" Margin="282,9,0,0" Grid.Row="2" Text="{Binding Value,Mode=TwoWay}" TextWrapping="Wrap" VerticalAlignment="Top" Width="100"/>
<Button Content="变量下发" HorizontalAlignment="Left" Margin="458,8,0,0" Grid.Row="2" VerticalAlignment="Top" Width="76" Command="{Binding SetTagValueCommand}"/>
<Label Content="变量值:" HorizontalAlignment="Left" Margin="229,5,0,0" Grid.Row="2" VerticalAlignment="Top"/>
<Label Content="开始时间:" HorizontalAlignment="Left" Margin="4,33,0,0" Grid.Row="2" VerticalAlignment="Top"/>
<DatePicker SelectedDate="{Binding StartTime,Mode=TwoWay}" HorizontalAlignment="Left" Margin="70,35,0,0" Grid.Row="2" VerticalAlignment="Top" Width="132"/>
<Button x:Name="hisqB" Content="读取历史" HorizontalAlignment="Left" Margin="458,37,0,0" Grid.Row="2" VerticalAlignment="Top" Width="76" Command="{Binding QueryHisDataCommand}"/>
<Label Content="结束时间:" HorizontalAlignment="Left" Margin="211,33,0,0" Grid.Row="2" VerticalAlignment="Top"/>
<DatePicker SelectedDate="{Binding EndTime,Mode=TwoWay}" HorizontalAlignment="Left" Margin="277,35,0,0" Grid.Row="2" VerticalAlignment="Top" Width="132"/>
</Grid>
</Window>
......@@ -65,7 +65,7 @@ namespace Cdy.Tag
private ManualResetEvent mResetEvent = new ManualResetEvent(false);
private bool mIsClosed = false;
private Dictionary<string, WatcherChangeTypes> mFileCach = new Dictionary<string, WatcherChangeTypes>();
private Dictionary<string, WatcherChangeTypes> mLogFileCach = new Dictionary<string, WatcherChangeTypes>();
private Dictionary<string, WatcherChangeTypes> mHisFileCach = new Dictionary<string, WatcherChangeTypes>();
......@@ -160,13 +160,17 @@ namespace Cdy.Tag
hisDataWatcher.EnableRaisingEvents = true;
}
string logpath = GetPrimaryLogDataPath();
ScanLogFile(logpath);
if (System.IO.Directory.Exists(logpath))
//只有在不支持内存查询的情况,才需要监视日志文件
if (ServiceLocator.Locator.Resolve<IHisQueryFromMemory>() != null)
{
logDataWatcher = new System.IO.FileSystemWatcher(logpath);
logDataWatcher.Changed += LogDataWatcher_Changed;
logDataWatcher.EnableRaisingEvents = true;
string logpath = GetPrimaryLogDataPath();
ScanLogFile(logpath);
if (System.IO.Directory.Exists(logpath))
{
logDataWatcher = new System.IO.FileSystemWatcher(logpath);
logDataWatcher.Changed += LogDataWatcher_Changed;
logDataWatcher.EnableRaisingEvents = true;
}
}
foreach (var vv in this.mTimeFileMaps)
......@@ -222,13 +226,13 @@ namespace Cdy.Tag
mResetCount++;
}
if(mFileCach.Count>0)
if(mLogFileCach.Count>0)
{
lock(mLocker)
{
ltmp = mFileCach.ToList();
mFileCach.Clear();
ltmp = mLogFileCach.ToList();
mLogFileCach.Clear();
}
foreach(var vv in ltmp)
......@@ -294,9 +298,9 @@ namespace Cdy.Tag
{
lock (mLocker)
{
if (!mFileCach.ContainsKey(e.FullPath))
if (!mLogFileCach.ContainsKey(e.FullPath))
{
mFileCach.Add(e.FullPath, e.ChangeType);
mLogFileCach.Add(e.FullPath, e.ChangeType);
}
}
}
......
......@@ -17,23 +17,24 @@ namespace Cdy.Tag
/// </summary>
public class QuerySerivce: IHisQuery
{
IHisQueryFromMemory mMemoryService;
/// <summary>
///
/// </summary>
public QuerySerivce()
{
mMemoryService = ServiceLocator.Locator.Resolve<IHisQueryFromMemory>() as IHisQueryFromMemory;
}
/// <summary>
///
/// </summary>
/// <param name="databaseName"></param>
public QuerySerivce(string databaseName)
public QuerySerivce(string databaseName) : this()
{
Database = databaseName;
}
public string Database { get; set; }
......@@ -47,6 +48,15 @@ namespace Cdy.Tag
return HisQueryManager.Instance.GetFileManager(Database);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private bool IsCanQueryFromMemory()
{
return mMemoryService != null;
}
/// <summary>
///
/// </summary>
......@@ -57,13 +67,36 @@ namespace Cdy.Tag
/// <param name="result"></param>
public void ReadValue<T>(int id, List<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(times, mLogTimes, id);
var vfiles = GetFileManager().GetDataFiles(ltmp, mLogTimes, id);
DataFileInfo mPreFile = null;
List<DateTime> mtime = new List<DateTime>();
//从历史文件中读取数据
foreach (var vv in vfiles)
{
if (vv.Value == null)
......@@ -96,9 +129,24 @@ namespace Cdy.Tag
mPreFile.Read<T>(id, mtime, type, result);
}
//从日志文件中读取数据
ReadLogFile(id, mLogTimes, type, result);
//从内存中读取数据
ReadFromMemory(id, mMemoryTimes, type, result);
}
/// <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);
}
/// <summary>
///
......@@ -170,6 +218,19 @@ namespace Cdy.Tag
});
}
/// <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);
}
/// <summary>
///
/// </summary>
......@@ -182,19 +243,50 @@ namespace Cdy.Tag
{
try
{
Tuple<DateTime, DateTime> mLogFileTimes;
var vfiles = GetFileManager().GetDataFiles(startTime, endTime, out mLogFileTimes, id);
vfiles.ForEach(e =>
DateTime etime = endTime,stime = startTime;
DateTime memoryTime = DateTime.MaxValue;
if(IsCanQueryFromMemory())
{
DateTime sstart = e.StartTime > startTime ? e.StartTime : startTime;
DateTime eend = e.EndTime > endTime ? endTime : endTime;
e.ReadAllValue(id, sstart, eend, result);
});
memoryTime = mMemoryService.GetStartMemoryTime(id);
}
if (mLogFileTimes.Item1 <mLogFileTimes.Item2)
if(startTime>=memoryTime)
{
ReadLogFileAllValue(id, mLogFileTimes.Item1, mLogFileTimes.Item2, result);
ReadAllValueFromMemory(id, startTime, endTime, result);
}
else
{
if(endTime>memoryTime)
{
etime = memoryTime;
}
Tuple<DateTime, DateTime> mLogFileTimes;
var vfiles = GetFileManager().GetDataFiles(stime, etime, 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 < mLogFileTimes.Item2)
{
ReadLogFileAllValue(id, mLogFileTimes.Item1, mLogFileTimes.Item2, result);
}
//从内存中读取数据
if(endTime>memoryTime)
{
ReadAllValueFromMemory(id, memoryTime, endTime, result);
}
}
}
catch(Exception ex)
{
......
......@@ -348,86 +348,7 @@ namespace Cdy.Tag
#endregion ...Interfaces...
}
/// <summary>
///
/// </summary>
public class DateTimeSpan
{
/// <summary>
///
/// </summary>
public DateTimeSpan Empty = new DateTimeSpan() { Start = DateTime.MinValue, End = DateTime.MinValue };
/// <summary>
///
/// </summary>
public DateTime Start { get; set; }
/// <summary>
///
/// </summary>
public DateTime End { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool IsEmpty()
{
return Start == DateTime.MinValue && End == DateTime.MinValue;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool IsZore()
{
return (End - Start).TotalSeconds == 0;
}
/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
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 };
}
}
/// <summary>
///
/// </summary>
/// <param name="time1"></param>
/// <param name="time2"></param>
/// <returns></returns>
public DateTime Min(DateTime time1, DateTime time2)
{
return time1 <= time2 ? time1 : time2;
}
/// <summary>
///
/// </summary>
/// <param name="time1"></param>
/// <param name="time2"></param>
/// <returns></returns>
public DateTime Max(DateTime time1, DateTime time2)
{
return time1 >= time2 ? time1 : time2;
}
}
public static class DataFileInfoExtend
......
......@@ -443,6 +443,9 @@ namespace Cdy.Tag
long addroffset = 0;
short len = 0;
int datasize = 0;
if (!datafile.IsOpened()) return;
var aid = datafile.ReadTagIndex(tid,out addroffset,out len);
if(aid!=null)
{
......@@ -658,6 +661,8 @@ namespace Cdy.Tag
long addroffset = 0;
short len = 0;
int datasize = 0;
if (!datafile.IsOpened()) return;
var aid = datafile.ReadTagIndex(tid, out addroffset, out len);
if(aid!=null)
{
......
......@@ -2,7 +2,7 @@
"profiles": {
"DBInRun": {
"commandName": "Executable",
"executablePath": "C:\\Users\\cdy81\\source\\repos\\mars\\Output\\DBInRun.exe"
"executablePath": "C:\\Users\\chongdaoyang\\source\\repos\\mars\\Output\\DBInRun.exe"
}
}
}
\ No newline at end of file
......@@ -300,6 +300,7 @@ namespace Cdy.Tag
mm.Value.Compress(sm);
});
HisDataMemoryQueryService.Service.ClearMemoryTime(sm.CurrentDatetime);
sm.Clear();
sm.MakeMemoryNoBusy();
......
......@@ -194,6 +194,8 @@ namespace Cdy.Tag
cdata.MakeMemoryBusy();
ServiceLocator.Locator.Resolve<IDataSerialize2>().ManualRequestToSeriseFile(cdata);
data.MakeMemoryNoBusy();
HisDataMemoryQueryService.Service.ClearManualMemoryTime(data.Id, data.Time);
ManualHisDataMemoryBlockPool.Pool.Release(data);
}
......
此差异已折叠。
......@@ -147,7 +147,7 @@ namespace Cdy.Tag
private int mStartMergeCount = 0;
private Dictionary<long,Dictionary<DateTime, ManualHisDataMemoryBlock>> mManualHisDataCach = new Dictionary<long, Dictionary<DateTime, ManualHisDataMemoryBlock>>();
private Dictionary<long,SortedDictionary<DateTime, ManualHisDataMemoryBlock>> mManualHisDataCach = new Dictionary<long, SortedDictionary<DateTime, ManualHisDataMemoryBlock>>();
#endregion ...Variables...
......@@ -179,7 +179,7 @@ namespace Cdy.Tag
#region ... Properties ...
/// <summary>
/// 当前工作的内存区域
......@@ -198,6 +198,29 @@ namespace Cdy.Tag
}
}
/// <summary>
/// 当前正在使用的内存
/// </summary>
public HisDataMemoryBlockCollection CurrentMergeMemory
{
get
{
return mCurrentMergeMemory;
}
}
/// <summary>
///
/// </summary>
public Cdy.Tag.HisDatabase HisTagManager
{
get
{
return mManager;
}
}
/// <summary>
///
/// </summary>
......@@ -853,6 +876,8 @@ namespace Cdy.Tag
CurrentMemory = mCachMemory1;
CurrentMemory.CurrentDatetime = mLastProcessTime;
HisDataMemoryQueryService.Service.RegistorMemory(CurrentMemory.CurrentDatetime, mLastProcessTime.AddSeconds(CachMemoryTime), CurrentMemory);
mCurrentMergeMemory = mMergeMemory1;
mCurrentMergeMemory.CurrentDatetime = CurrentMemory.CurrentDatetime;
......@@ -925,6 +950,9 @@ namespace Cdy.Tag
//mMergeMemory.Dump();
mCurrentMergeMemory.EndDateTime = mSnapAllTagTime;
HisDataMemoryQueryService.Service.RegistorMemory(mCurrentMergeMemory.CurrentDatetime, mCurrentMergeMemory.EndDateTime, mCurrentMergeMemory);
mCurrentMergeMemory.MakeMemoryBusy();
//提交到数据压缩流程
ServiceLocator.Locator.Resolve<IDataCompress2>().RequestToCompress(mCurrentMergeMemory);
......@@ -971,7 +999,6 @@ namespace Cdy.Tag
Stopwatch sw = new Stopwatch();
sw.Start();
//System.Threading.Tasks.Parallel.ForEach(mHisTags, (tag) => {
foreach (var tag in mHisTags)
{
var taddrs = mCurrentMergeMemory.TagAddress[tag.Value.Id];
......@@ -999,13 +1026,11 @@ namespace Cdy.Tag
vtimeaddr = taddrs.QualityAddress + dlen * count + 1;
saddrs.CopyTo(taddrs, saddrs.QualityAddress, vtimeaddr, dlen);
}
//});
//mCurrentMergeMemory.Dump();
//mcc.Dump();
HisDataMemoryQueryService.Service.ClearMemoryTime(mcc.CurrentDatetime);
HisDataMemoryQueryService.Service.RegistorMemory(mCurrentMergeMemory.CurrentDatetime, mcc.EndDateTime, mCurrentMergeMemory);
mcc.MakeMemoryNoBusy();
//ClearMemoryHisData(mcc);
sw.Stop();
LoggerService.Service.Info("Record", "合并完成 " + mcc.Name+" 次数:"+(count+1)+" 耗时:"+sw.ElapsedMilliseconds);
}
......@@ -1039,6 +1064,8 @@ namespace Cdy.Tag
CurrentMemory.CurrentDatetime = dateTime;
HisDataMemoryQueryService.Service.RegistorMemory(CurrentMemory.CurrentDatetime,dateTime.AddSeconds(CachMemoryTime), CurrentMemory);
if (mMergeCount==0)
{
mNeedSnapAllTag = true;
......@@ -1354,7 +1381,7 @@ namespace Cdy.Tag
DateTime mLastTime = DateTime.MinValue;
Dictionary<DateTime, ManualHisDataMemoryBlock> datacach;
SortedDictionary<DateTime, ManualHisDataMemoryBlock> datacach;
if (mHisTags.ContainsKey(id) && mHisTags[id].Type == RecordType.Manual)
{
......@@ -1364,7 +1391,7 @@ namespace Cdy.Tag
}
else
{
datacach = new Dictionary<DateTime, ManualHisDataMemoryBlock>();
datacach = new SortedDictionary<DateTime, ManualHisDataMemoryBlock>();
mManualHisDataCach.Add(id, datacach);
}
......@@ -1381,6 +1408,8 @@ namespace Cdy.Tag
}
else
{
if(hb!=null)
HisDataMemoryQueryService.Service.RegistorManual(id, hb.Time, hb.EndTime, hb);
var css = CalCachDatablockSize(tag.TagType, 0, MergeMemoryTime * 1000 / timeUnit, out valueOffset, out qulityOffset);
hb = ManualHisDataMemoryBlockPool.Pool.Get(css);
hb.Time = time;
......@@ -1391,8 +1420,9 @@ namespace Cdy.Tag
hb.ValueAddress = valueOffset;
hb.QualityAddress = qulityOffset;
hb.Id = (int)id;
HisDataMemoryQueryService.Service.RegistorManual(id, hb.Time, time, hb);
datacach.Add(time, hb);
}
mLastTime = time;
......@@ -1492,6 +1522,8 @@ namespace Cdy.Tag
hb.Relase();
}
}
if (hb != null)
HisDataMemoryQueryService.Service.RegistorManual(id, hb.Time, hb.EndTime, hb);
bool isNeedSubmite = false;
......@@ -1533,7 +1565,7 @@ namespace Cdy.Tag
DateTime mLastTime = DateTime.MinValue;
Dictionary<DateTime, ManualHisDataMemoryBlock> datacach;
SortedDictionary<DateTime, ManualHisDataMemoryBlock> datacach;
if (mHisTags.ContainsKey(id) && mHisTags[id].Type == RecordType.Manual)
{
......@@ -1543,7 +1575,7 @@ namespace Cdy.Tag
}
else
{
datacach = new Dictionary<DateTime, ManualHisDataMemoryBlock>();
datacach = new SortedDictionary<DateTime, ManualHisDataMemoryBlock>();
mManualHisDataCach.Add(id, datacach);
}
......@@ -1669,6 +1701,9 @@ namespace Cdy.Tag
hb.EndTime = value.Time;
hb.CurrentCount++;
hb.Relase();
HisDataMemoryQueryService.Service.RegistorManual(id, hb.Time, hb.EndTime, hb);
}
bool isNeedSubmite = false;
......
......@@ -616,7 +616,13 @@ namespace Cdy.Tag
return this;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override bool IsOpened()
{
return mStream != null;
}
}
}
......@@ -225,7 +225,7 @@ namespace Cdy.Tag
/// <param name="tags"></param>
private void ProcessTags(List<HisRunTag> tags)
{
int tim = (int)((mLastUpdateTime - HisRunTag.StartTime).TotalMilliseconds / HisEnginer.MemoryTimeTick);
int tim = (int)((mLastUpdateTime - HisRunTag.StartTime).TotalMilliseconds / HisEnginer2.MemoryTimeTick);
foreach (var vv in tags)
{
vv.UpdateValue2(tim);
......
......@@ -8,6 +8,7 @@
//==============================================================
using Cdy.Tag.Driver;
using DBRuntime;
using DBRuntime.His;
using System;
using System.Collections.Generic;
using System.Diagnostics;
......@@ -306,6 +307,11 @@ namespace Cdy.Tag
ServiceLocator.Locator.Registor<IHisEngine2>(hisEnginer);
ServiceLocator.Locator.Registor<ITagHisValueProduct>(hisEnginer);
//初始化从内存中查询数据的服务
HisDataMemoryQueryService.Service.HisEnginer = hisEnginer;
ServiceLocator.Locator.Registor<IHisQueryFromMemory>(HisDataMemoryQueryService.Service);
compressEnginer = new CompressEnginer2();
compressEnginer.TagCountOneFile = mHisDatabase.Setting.TagCountOneFile;
compressEnginer.Init();
......
......@@ -2,7 +2,7 @@
"profiles": {
"HisDataTools": {
"commandName": "Executable",
"executablePath": "C:\\Users\\cdy81\\source\\repos\\mars\\Output\\HisDataTools.exe"
"executablePath": "C:\\Users\\chongdaoyang\\source\\repos\\mars\\Output\\HisDataTools.exe"
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册