Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
cdy816
Mars
提交
d729b194
Mars
项目概览
cdy816
/
Mars
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d729b194
编写于
10月 12, 2020
作者:
cdy816
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
内存中查询数据
上级
28dd7768
变更
19
展开全部
隐藏空白更改
内联
并排
Showing
19 changed file
with
1464 addition
and
242 deletion
+1464
-242
Common/Cdy.Tag.Common/Common/DateTimeSpan.cs
Common/Cdy.Tag.Common/Common/DateTimeSpan.cs
+106
-0
Common/Cdy.Tag/His/DataFileSeriserbase.cs
Common/Cdy.Tag/His/DataFileSeriserbase.cs
+6
-0
Common/Cdy.Tag/Interface/IHisQuery.cs
Common/Cdy.Tag/Interface/IHisQuery.cs
+1
-113
Common/Cdy.Tag/Interface/IHisQueryFromMemory.cs
Common/Cdy.Tag/Interface/IHisQueryFromMemory.cs
+56
-0
Example/Consumer/DBGrpcApiDemo/MainViewModel.cs
Example/Consumer/DBGrpcApiDemo/MainViewModel.cs
+69
-0
Example/Consumer/DBGrpcApiDemo/MainWindow.xaml
Example/Consumer/DBGrpcApiDemo/MainWindow.xaml
+12
-7
RunTime/DBHisData/HisQuery/DataFileManager.cs
RunTime/DBHisData/HisQuery/DataFileManager.cs
+16
-12
RunTime/DBHisData/HisQuery/QuerySerivce.cs
RunTime/DBHisData/HisQuery/QuerySerivce.cs
+105
-13
RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs
RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs
+0
-79
RunTime/DBHisData/HisQuery/TimeFile/LogFileInfo.cs
RunTime/DBHisData/HisQuery/TimeFile/LogFileInfo.cs
+5
-0
RunTime/DBInRun/Properties/launchSettings.json
RunTime/DBInRun/Properties/launchSettings.json
+1
-1
RunTime/DBRuntime/His/Compress/CompressEnginer2.cs
RunTime/DBRuntime/His/Compress/CompressEnginer2.cs
+1
-0
RunTime/DBRuntime/His/Compress/CompressMemory2.cs
RunTime/DBRuntime/His/Compress/CompressMemory2.cs
+2
-0
RunTime/DBRuntime/His/HisDataMemoryQueryService.cs
RunTime/DBRuntime/His/HisDataMemoryQueryService.cs
+1020
-0
RunTime/DBRuntime/His/HisEnginer2.cs
RunTime/DBRuntime/His/HisEnginer2.cs
+48
-13
RunTime/DBRuntime/His/LocalFileSeriser.cs
RunTime/DBRuntime/His/LocalFileSeriser.cs
+8
-2
RunTime/DBRuntime/His/TimerMemoryCacheProcesser2.cs
RunTime/DBRuntime/His/TimerMemoryCacheProcesser2.cs
+1
-1
RunTime/DBRuntime/Runner.cs
RunTime/DBRuntime/Runner.cs
+6
-0
Tools/HisDataTools/Properties/launchSettings.json
Tools/HisDataTools/Properties/launchSettings.json
+1
-1
未找到文件。
Common/Cdy.Tag.Common/Common/DateTimeSpan.cs
0 → 100644
浏览文件 @
d729b194
//==============================================================
// 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
;
}
}
}
Common/Cdy.Tag/His/DataFileSeriserbase.cs
浏览文件 @
d729b194
...
...
@@ -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>
...
...
Common/Cdy.Tag/Interface/IHisQuery.cs
浏览文件 @
d729b194
...
...
@@ -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);
}
}
Common/Cdy.Tag/Interface/IHisQueryFromMemory.cs
0 → 100644
浏览文件 @
d729b194
//==============================================================
// 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
);
}
}
Example/Consumer/DBGrpcApiDemo/MainViewModel.cs
浏览文件 @
d729b194
...
...
@@ -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
...
...
...
Example/Consumer/DBGrpcApiDemo/MainWindow.xaml
浏览文件 @
d729b194
...
...
@@ -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>
RunTime/DBHisData/HisQuery/DataFileManager.cs
浏览文件 @
d729b194
...
...
@@ -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
>
m
Log
FileCach
=
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
(
m
Log
FileCach
.
Count
>
0
)
{
lock
(
mLocker
)
{
ltmp
=
mFileCach
.
ToList
();
mFileCach
.
Clear
();
ltmp
=
m
Log
FileCach
.
ToList
();
m
Log
FileCach
.
Clear
();
}
foreach
(
var
vv
in
ltmp
)
...
...
@@ -294,9 +298,9 @@ namespace Cdy.Tag
{
lock
(
mLocker
)
{
if
(!
mFileCach
.
ContainsKey
(
e
.
FullPath
))
if
(!
m
Log
FileCach
.
ContainsKey
(
e
.
FullPath
))
{
mFileCach
.
Add
(
e
.
FullPath
,
e
.
ChangeType
);
m
Log
FileCach
.
Add
(
e
.
FullPath
,
e
.
ChangeType
);
}
}
}
...
...
RunTime/DBHisData/HisQuery/QuerySerivce.cs
浏览文件 @
d729b194
...
...
@@ -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
)
{
Read
LogFileAllValue
(
id
,
mLogFileTimes
.
Item1
,
mLogFileTimes
.
Item2
,
result
);
Read
AllValueFromMemory
(
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
)
{
...
...
RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs
浏览文件 @
d729b194
...
...
@@ -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
...
...
RunTime/DBHisData/HisQuery/TimeFile/LogFileInfo.cs
浏览文件 @
d729b194
...
...
@@ -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
)
{
...
...
RunTime/DBInRun/Properties/launchSettings.json
浏览文件 @
d729b194
...
...
@@ -2,7 +2,7 @@
"profiles"
:
{
"DBInRun"
:
{
"commandName"
:
"Executable"
,
"executablePath"
:
"C:
\\
Users
\\
c
dy81
\\
source
\\
repos
\\
mars
\\
Output
\\
DBInRun.exe"
"executablePath"
:
"C:
\\
Users
\\
c
hongdaoyang
\\
source
\\
repos
\\
mars
\\
Output
\\
DBInRun.exe"
}
}
}
\ No newline at end of file
RunTime/DBRuntime/His/Compress/CompressEnginer2.cs
浏览文件 @
d729b194
...
...
@@ -300,6 +300,7 @@ namespace Cdy.Tag
mm
.
Value
.
Compress
(
sm
);
});
HisDataMemoryQueryService
.
Service
.
ClearMemoryTime
(
sm
.
CurrentDatetime
);
sm
.
Clear
();
sm
.
MakeMemoryNoBusy
();
...
...
RunTime/DBRuntime/His/Compress/CompressMemory2.cs
浏览文件 @
d729b194
...
...
@@ -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
);
}
...
...
RunTime/DBRuntime/His/HisDataMemoryQueryService.cs
0 → 100644
浏览文件 @
d729b194
此差异已折叠。
点击以展开。
RunTime/DBRuntime/His/HisEnginer2.cs
浏览文件 @
d729b194
...
...
@@ -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
,
Sorted
Dictionary
<
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
;
Sorted
Dictionary
<
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
Sorted
Dictionary
<
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
;
Sorted
Dictionary
<
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
Sorted
Dictionary
<
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
;
...
...
RunTime/DBRuntime/His/LocalFileSeriser.cs
浏览文件 @
d729b194
...
...
@@ -616,7 +616,13 @@ namespace Cdy.Tag
return
this
;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public
override
bool
IsOpened
()
{
return
mStream
!=
null
;
}
}
}
RunTime/DBRuntime/His/TimerMemoryCacheProcesser2.cs
浏览文件 @
d729b194
...
...
@@ -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
/
HisEnginer
2
.
MemoryTimeTick
);
foreach
(
var
vv
in
tags
)
{
vv
.
UpdateValue2
(
tim
);
...
...
RunTime/DBRuntime/Runner.cs
浏览文件 @
d729b194
...
...
@@ -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
();
...
...
Tools/HisDataTools/Properties/launchSettings.json
浏览文件 @
d729b194
...
...
@@ -2,7 +2,7 @@
"profiles"
:
{
"HisDataTools"
:
{
"commandName"
:
"Executable"
,
"executablePath"
:
"C:
\\
Users
\\
c
dy81
\\
source
\\
repos
\\
mars
\\
Output
\\
HisDataTools.exe"
"executablePath"
:
"C:
\\
Users
\\
c
hongdaoyang
\\
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录