Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
IoTSharp
提交
1de6d838
I
IoTSharp
项目概览
jobily
/
IoTSharp
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1de6d838
编写于
10月 06, 2022
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
定时检查活动状态, 如果超过 Timeout 设置的时间, 则认为非活动状态。
上级
eafa682f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
22 deletion
+41
-22
IoTSharp.Contracts/Constants.cs
IoTSharp.Contracts/Constants.cs
+17
-0
IoTSharp.EventBus/EventBusSubscriber.cs
IoTSharp.EventBus/EventBusSubscriber.cs
+4
-3
IoTSharp/Jobs/CheckDevices.cs
IoTSharp/Jobs/CheckDevices.cs
+20
-19
未找到文件。
IoTSharp.Contracts/Constants.cs
0 → 100644
浏览文件 @
1de6d838
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Contracts
{
public
static
class
Constants
{
public
const
string
_Active
=
"Active"
;
public
const
string
_LastActivityDateTime
=
"LastActivityDateTime"
;
public
const
string
_InactivityAlarmDateTime
=
"InactivityAlarmDateTime "
;
public
const
string
_LastConnectDateTime
=
"LastConnectDateTime"
;
public
const
string
_LastDisconnectDateTime
=
"LastDisconnectDateTime"
;
}
}
IoTSharp.EventBus/EventBusSubscriber.cs
浏览文件 @
1de6d838
...
...
@@ -17,6 +17,7 @@ namespace IoTSharp.EventBus
public
class
EventBusSubscriber
{
private
readonly
ILogger
_logger
;
private
readonly
IServiceScopeFactory
_scopeFactor
;
private
readonly
IStorage
_storage
;
...
...
@@ -176,8 +177,8 @@ namespace IoTSharp.EventBus
msg
.
DataCatalog
=
DataCatalog
.
AttributeData
;
msg
.
DataSide
=
DataSide
.
ServerSide
;
msg
.
MsgBody
=
new
Dictionary
<
string
,
object
>();
msg
.
MsgBody
.
Add
(
activity
==
ActivityStatus
.
Activity
?
"LastActivityDateTime"
:
"InactivityAlarmDateTime "
,
DateTime
.
Now
);
msg
.
MsgBody
.
Add
(
"Active"
,
activity
==
ActivityStatus
.
Activity
);
msg
.
MsgBody
.
Add
(
activity
==
ActivityStatus
.
Activity
?
Constants
.
_LastActivityDateTime
:
Constants
.
_InactivityAlarmDateTime
,
DateTime
.
Now
);
msg
.
MsgBody
.
Add
(
Constants
.
_Active
,
activity
==
ActivityStatus
.
Activity
);
await
StoreAttributeData
(
msg
,
activity
==
ActivityStatus
.
Activity
?
MountType
.
Activity
:
MountType
.
Inactivity
);
}
...
...
@@ -188,7 +189,7 @@ namespace IoTSharp.EventBus
msg
.
DataCatalog
=
DataCatalog
.
AttributeData
;
msg
.
DataSide
=
DataSide
.
ServerSide
;
msg
.
MsgBody
=
new
Dictionary
<
string
,
object
>();
msg
.
MsgBody
.
Add
(
devicestatus
==
ConnectStatus
.
Connected
?
"LastConnectDateTime"
:
"LastDisconnectDateTime"
,
DateTime
.
Now
);
msg
.
MsgBody
.
Add
(
devicestatus
==
ConnectStatus
.
Connected
?
Constants
.
_LastConnectDateTime
:
Constants
.
_LastDisconnectDateTime
,
DateTime
.
Now
);
await
StoreAttributeData
(
msg
,
devicestatus
==
ConnectStatus
.
Connected
?
MountType
.
Connected
:
MountType
.
Disconnected
);
}
...
...
IoTSharp/Jobs/CheckDevices.cs
浏览文件 @
1de6d838
...
...
@@ -42,27 +42,28 @@ namespace IoTSharp.Jobs
using
(
var
scope
=
_scopeFactor
.
CreateScope
())
using
(
var
_dbContext
=
scope
.
ServiceProvider
.
GetRequiredService
<
ApplicationDbContext
>())
{
var
clientstatus
=
await
_serverEx
.
GetClientsAsync
();
var
onlinedev
=
from
client
in
clientstatus
select
client
.
Session
.
Items
[
nameof
(
Device
)]
as
Device
;
//把超时时间小于1的都设置为300秒
var
tfx
=
from
d
in
_dbContext
.
Device
where
d
.
Timeout
<
1
select
d
;
tfx
.
ToList
().
ForEach
(
d
=>
d
.
Timeout
=
300
);
//所有在线且活跃时间超时的设备如果不在已连接客户端内, 则认为是离线。
//这里的自身我们认为是 有链接的设备, 而不是无连接的。
try
{
var
sf
=
from
d
in
_dbContext
.
Device
.
Include
(
d
=>
d
.
Owner
)
where
d
.
Owner
==
null
&&
!
d
.
Deleted
select
d
;
await
sf
.
LoadAsync
();
sf
.
ToList
().
ForEach
(
d
=>
{
//if (!onlinedev.Any(dev => dev.Id != d.Id) && DateTime.Now.Subtract(d.LastActive).TotalSeconds >d.Timeout )
//{
//}
});
var
saveresult
=
await
_dbContext
.
SaveChangesAsync
();
_logger
.
LogInformation
(
$"设备检查程序已经处理
{
saveresult
}
调数据"
);
var
sf
=
from
d
in
_dbContext
.
AttributeLatest
where
(
d
.
KeyName
==
Constants
.
_Active
&&
d
.
Value_Boolean
==
true
)
select
d
.
DeviceId
;
if
(
sf
.
Any
())
{
var
devids
=
await
sf
.
ToListAsync
();
foreach
(
var
id
in
devids
)
{
var
dev
=
await
_dbContext
.
Device
.
FirstOrDefaultAsync
(
d
=>
d
.
Id
==
id
);
var
ladt
=
from
d
in
_dbContext
.
AttributeLatest
where
d
.
DeviceId
==
id
&&
d
.
DataSide
==
DataSide
.
ServerSide
&&
d
.
KeyName
==
Constants
.
_LastActivityDateTime
select
d
.
Value_DateTime
;
var
__LastActivityDateTime
=
await
ladt
.
FirstOrDefaultAsync
();
if
(
dev
!=
null
&&
__LastActivityDateTime
!=
null
)
{
if
(
DateTime
.
Now
.
Subtract
(
__LastActivityDateTime
.
GetValueOrDefault
()).
TotalSeconds
>
dev
.
Timeout
)
{
_logger
.
LogInformation
(
$"设备
{
dev
.
Name
}
(
{
dev
.
Id
}
)现在置非活跃状态,上次活跃时间为
{
__LastActivityDateTime
}
,超时时间
{
dev
.
Timeout
}
秒"
);
await
_queue
.
PublishActive
(
id
,
ActivityStatus
.
Inactivity
);
}
}
}
}
}
catch
(
Exception
ex
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录