Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
IoTSharp
提交
d9ef6363
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,发现更多精彩内容 >>
提交
d9ef6363
编写于
9月 17, 2022
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
调整所有Data的扩展 移动到跟数据上下文一起。
上级
8df3cb04
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
247 addition
and
13 deletion
+247
-13
IoTSharp.Data/Alarm.cs
IoTSharp.Data/Alarm.cs
+2
-1
IoTSharp.Data/ApplicationDbContext.cs
IoTSharp.Data/ApplicationDbContext.cs
+1
-0
IoTSharp.Data/AssetRelation.cs
IoTSharp.Data/AssetRelation.cs
+2
-1
IoTSharp.Data/AuditLog.cs
IoTSharp.Data/AuditLog.cs
+2
-1
IoTSharp.Data/BaseEvent.cs
IoTSharp.Data/BaseEvent.cs
+2
-1
IoTSharp.Data/Configurations/DataStorageConfiguration.cs
IoTSharp.Data/Configurations/DataStorageConfiguration.cs
+2
-1
IoTSharp.Data/DataStorage.cs
IoTSharp.Data/DataStorage.cs
+5
-3
IoTSharp.Data/Device.cs
IoTSharp.Data/Device.cs
+2
-1
IoTSharp.Data/DeviceIdentity.cs
IoTSharp.Data/DeviceIdentity.cs
+2
-1
IoTSharp.Data/Extensions/AlarmExtension.cs
IoTSharp.Data/Extensions/AlarmExtension.cs
+136
-0
IoTSharp.Data/Extensions/DeviceExtension.cs
IoTSharp.Data/Extensions/DeviceExtension.cs
+83
-0
IoTSharp.Data/FlowRule.cs
IoTSharp.Data/FlowRule.cs
+1
-0
IoTSharp.Data/PlayloadData.cs
IoTSharp.Data/PlayloadData.cs
+2
-1
IoTSharp.Data/Produce.cs
IoTSharp.Data/Produce.cs
+2
-1
IoTSharp.Data/TelemetryData.cs
IoTSharp.Data/TelemetryData.cs
+3
-1
未找到文件。
IoTSharp.Data/Alarm.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
using
System.ComponentModel.DataAnnotations
;
namespace
IoTSharp.Data
...
...
IoTSharp.Data/ApplicationDbContext.cs
浏览文件 @
d9ef6363
...
...
@@ -7,6 +7,7 @@ using System.Linq;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.Extensions.DependencyInjection
;
using
IoTSharp.Data.Configurations
;
using
IoTSharp.Contracts
;
namespace
IoTSharp.Data
{
...
...
IoTSharp.Data/AssetRelation.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
...
...
IoTSharp.Data/AuditLog.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
...
...
IoTSharp.Data/BaseEvent.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.ComponentModel.DataAnnotations.Schema
;
...
...
IoTSharp.Data/Configurations/DataStorageConfiguration.cs
浏览文件 @
d9ef6363
using
Microsoft.EntityFrameworkCore
;
using
IoTSharp.Contracts
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Metadata.Builders
;
using
System
;
using
System.Collections.Generic
;
...
...
IoTSharp.Data/DataStorage.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
using
System.ComponentModel.DataAnnotations
;
using
System.ComponentModel.DataAnnotations.Schema
;
using
DataType
=
IoTSharp
.
Contracts
.
DataType
;
namespace
IoTSharp.Data
{
...
...
@@ -44,8 +46,8 @@ namespace IoTSharp.Data
public
DataSide
DataSide
{
get
;
set
;
}
=
DataSide
.
AnySide
;
[
Column
(
Order
=
5
)]
[
EnumDataType
(
typeof
(
DataType
))]
public
DataType
Type
{
get
;
set
;
}
[
EnumDataType
(
typeof
(
Contracts
.
DataType
))]
public
Contracts
.
DataType
Type
{
get
;
set
;
}
public
bool
?
Value_Boolean
{
get
;
set
;
}
public
string
Value_String
{
get
;
set
;
}
...
...
IoTSharp.Data/Device.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
namespace
IoTSharp.Data
{
...
...
IoTSharp.Data/DeviceIdentity.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
...
...
IoTSharp.Data/Extensions/AlarmExtension.cs
0 → 100644
浏览文件 @
d9ef6363
using
IoTSharp.Contracts
;
using
IoTSharp.Data
;
using
Microsoft.EntityFrameworkCore
;
using
System
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Data.Extensions
{
public
static
class
AlarmExtension
{
public
static
async
Task
<
ApiResult
<
Alarm
>>
OccurredAlarm
(
this
ApplicationDbContext
_context
,
CreateAlarmDto
cad
)
{
Guid
OriginatorId
=
Guid
.
Empty
;
OriginatorType
originatorType
=
cad
.
OriginatorType
;
if
(
cad
.
OriginatorType
==
OriginatorType
.
Device
||
cad
.
OriginatorType
==
OriginatorType
.
Gateway
||
cad
.
OriginatorType
==
OriginatorType
.
Unknow
)
{
var
dev
=
_context
.
Device
.
Include
(
d
=>
d
.
Tenant
).
Include
(
d
=>
d
.
Customer
).
FirstOrDefault
(
d
=>
d
.
Id
.
ToString
()
==
cad
.
OriginatorName
||
d
.
Name
==
cad
.
OriginatorName
);
if
(
dev
!=
null
)
{
if
(
dev
.
DeviceType
==
DeviceType
.
Gateway
)
{
if
(
dev
.
Id
.
ToString
()
!=
cad
.
OriginatorName
&&
dev
.
Name
!=
cad
.
OriginatorName
)
{
var
subdev
=
from
g
in
_context
.
Device
.
Include
(
d
=>
d
.
Tenant
).
Include
(
d
=>
d
.
Customer
).
Include
(
g
=>
g
.
Owner
)
where
g
.
Owner
==
dev
&&
g
.
Name
==
cad
.
OriginatorName
select
g
;
var
orig
=
await
subdev
.
FirstOrDefaultAsync
();
OriginatorId
=
orig
.
Id
;
originatorType
=
OriginatorType
.
Device
;
}
else
{
originatorType
=
OriginatorType
.
Gateway
;
OriginatorId
=
dev
.
Id
;
}
}
else
if
(
dev
.
DeviceType
==
DeviceType
.
Device
)
{
originatorType
=
OriginatorType
.
Device
;
OriginatorId
=
dev
.
Id
;
}
return
await
_context
.
OccurredAlarm
(
cad
,
_alarm
=>
{
_alarm
.
OriginatorType
=
originatorType
;
_alarm
.
OriginatorId
=
OriginatorId
;
_alarm
.
Tenant
=
dev
.
Tenant
;
_alarm
.
Customer
=
dev
.
Customer
;
});
}
else
return
new
ApiResult
<
Alarm
>(
ApiCode
.
NotFoundDevice
,
"Originator name not a device!"
,
null
);
}
else
if
(
cad
.
OriginatorType
==
OriginatorType
.
Asset
)
{
var
ass
=
_context
.
Assets
.
Include
(
a
=>
a
.
Tenant
).
Include
(
a
=>
a
.
Customer
).
FirstOrDefault
(
d
=>
d
.
Id
.
ToString
()
==
cad
.
OriginatorName
||
d
.
Name
==
cad
.
OriginatorName
);
if
(
ass
!=
null
)
{
originatorType
=
OriginatorType
.
Asset
;
OriginatorId
=
ass
.
Id
;
return
await
_context
.
OccurredAlarm
(
cad
,
_alarm
=>
{
_alarm
.
OriginatorType
=
originatorType
;
_alarm
.
OriginatorId
=
OriginatorId
;
_alarm
.
Tenant
=
ass
.
Tenant
;
_alarm
.
Customer
=
ass
.
Customer
;
});
}
else
return
new
ApiResult
<
Alarm
>(
ApiCode
.
NotFoundDevice
,
"Originator name not a asset"
,
null
);
}
else
return
new
ApiResult
<
Alarm
>(
ApiCode
.
NotFoundDevice
,
"Originator name not a asset"
,
null
);
}
public
static
async
Task
<
ApiResult
<
Alarm
>>
OccurredAlarm
(
this
ApplicationDbContext
_context
,
CreateAlarmDto
dto
,
Action
<
Alarm
>
action
)
{
var
result
=
new
ApiResult
<
Alarm
>(
ApiCode
.
InValidData
,
""
,
null
);
try
{
var
alarm
=
new
Alarm
{
Id
=
Guid
.
NewGuid
(),
AckDateTime
=
DateTime
.
Now
,
AlarmDetail
=
dto
.
AlarmDetail
,
AlarmStatus
=
AlarmStatus
.
Active_UnAck
,
AlarmType
=
dto
.
AlarmType
,
ClearDateTime
=
new
DateTime
(
1970
,
1
,
1
),
EndDateTime
=
new
DateTime
(
1970
,
1
,
1
),
Propagate
=
true
,
Serverity
=
dto
.
Serverity
,
StartDateTime
=
DateTime
.
Now
,
};
action
?.
Invoke
(
alarm
);
var
isone
=
from
a
in
_context
.
Alarms
where
a
.
OriginatorId
==
alarm
.
OriginatorId
&&
a
.
AlarmType
==
alarm
.
AlarmType
&&
(
a
.
AlarmStatus
==
AlarmStatus
.
Cleared_UnAck
||
a
.
AlarmStatus
==
AlarmStatus
.
Active_UnAck
)
select
a
;
if
(
isone
.
Any
())
{
var
old
=
isone
.
First
();
old
.
AlarmDetail
=
alarm
.
AlarmDetail
;
if
(
old
.
Serverity
!=
dto
.
Serverity
)
{
if
(
old
.
Serverity
==
ServerityLevel
.
Indeterminate
&&
dto
.
Serverity
!=
ServerityLevel
.
Indeterminate
)
{
old
.
StartDateTime
=
DateTime
.
Now
;
alarm
.
Propagate
=
true
;
}
else
if
(
old
.
Serverity
!=
ServerityLevel
.
Indeterminate
&&
dto
.
Serverity
==
ServerityLevel
.
Indeterminate
)
{
old
.
EndDateTime
=
DateTime
.
Now
;
if
(
old
.
ClearDateTime
.
Year
==
1970
)
{
old
.
ClearDateTime
=
DateTime
.
Now
;
}
alarm
.
Propagate
=
true
;
}
else
{
alarm
.
Propagate
=
false
;
}
old
.
Serverity
=
dto
.
Serverity
;
}
}
else
{
_context
.
Alarms
.
Add
(
alarm
);
}
int
ret
=
await
_context
.
SaveChangesAsync
();
result
=
new
ApiResult
<
Alarm
>(
ret
>
0
?
ApiCode
.
Success
:
ApiCode
.
NothingToDo
,
ret
>
0
?
"OK"
:
"No data"
,
alarm
);
}
catch
(
Exception
ex
)
{
result
=
new
ApiResult
<
Alarm
>(
ApiCode
.
Exception
,
ex
.
Message
,
null
);
}
return
result
;
}
}
}
\ No newline at end of file
IoTSharp.Data/Extensions/DeviceExtension.cs
0 → 100644
浏览文件 @
d9ef6363
using
IoTSharp.Contracts
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Data.Extensions
{
public
static
class
DeviceExtension
{
/// <summary>
/// When creating a device, all the things that need to be done here are done
/// </summary>
/// <param name="_context"></param>
/// <param name="device"></param>
public
static
void
AfterCreateDevice
(
this
ApplicationDbContext
_context
,
Device
device
)
{
if
(
device
.
Customer
==
null
||
device
.
Tenant
==
null
||
string
.
IsNullOrEmpty
(
device
.
Name
))
{
throw
new
Exception
(
$"Customer(
{
device
.
Customer
?.
Id
}
) or Tenant(
{
device
.
Tenant
?.
Id
}
) or Name(
{
device
.
Name
}
) is null or empty!"
);
}
else
{
_context
.
DeviceIdentities
.
Add
(
new
DeviceIdentity
()
{
Device
=
device
,
IdentityType
=
IdentityType
.
AccessToken
,
IdentityId
=
Guid
.
NewGuid
().
ToString
().
Replace
(
"-"
,
""
)
});
Dictionary
<
string
,
object
>
pairs
=
new
Dictionary
<
string
,
object
>();
pairs
.
Add
(
"CreateDateTime"
,
DateTime
.
Now
);
_context
.
PreparingData
<
AttributeLatest
>(
pairs
,
device
.
Id
,
DataSide
.
ServerSide
);
}
}
public
static
void
AfterCreateDevice
(
this
ApplicationDbContext
_context
,
Device
device
,
string
username
,
string
password
)
{
if
(
device
.
Customer
==
null
||
device
.
Tenant
==
null
||
string
.
IsNullOrEmpty
(
device
.
Name
))
{
throw
new
Exception
(
$"Customer(
{
device
.
Customer
?.
Id
}
) or Tenant(
{
device
.
Tenant
?.
Id
}
) or Name(
{
device
.
Name
}
) is null or empty!"
);
}
else
{
_context
.
DeviceIdentities
.
Add
(
new
DeviceIdentity
()
{
Device
=
device
,
IdentityType
=
IdentityType
.
DevicePassword
,
IdentityId
=
username
,
IdentityValue
=
password
})
;
Dictionary
<
string
,
object
>
pairs
=
new
Dictionary
<
string
,
object
>();
pairs
.
Add
(
"CreateDateTime"
,
DateTime
.
Now
);
_context
.
PreparingData
<
AttributeLatest
>(
pairs
,
device
.
Id
,
DataSide
.
ServerSide
);
}
}
public
static
async
Task
<
DeviceRule
[
]>
GerDeviceRulesList
(
this
ApplicationDbContext
_dbContext
,
Guid
devid
,
MountType
mountType
)
{
DeviceRule
[]
lst
=
null
;
var
r
=
from
dr
in
_dbContext
.
DeviceRules
.
Include
(
d
=>
d
.
Device
).
Include
(
d
=>
d
.
FlowRule
)
where
dr
.
Device
.
Id
==
devid
&&
dr
.
FlowRule
.
MountType
==
mountType
select
dr
;
if
(
r
.
Any
())
{
lst
=
await
r
.
ToArrayAsync
();
}
return
lst
;
}
public
static
async
Task
<
Guid
>
GerDeviceRpcRulesList
(
this
ApplicationDbContext
_dbContext
,
Guid
devid
,
MountType
mountType
,
string
method
)
{
var
rules
=
await
GerDeviceRulesList
(
_dbContext
,
devid
,
mountType
);
var
g
=
(
rules
.
FirstOrDefault
(
r
=>
r
.
FlowRule
.
Name
==
method
)?.
FlowRule
.
RuleId
);
return
g
.
GetValueOrDefault
();
}
public
static
async
Task
<
Guid
[
]>
GerDeviceRulesIdList
(
this
ApplicationDbContext
_dbContext
,
Guid
devid
,
MountType
mountType
)
{
var
rules
=
await
GerDeviceRulesList
(
_dbContext
,
devid
,
mountType
);
return
rules
?.
Select
(
xc
=>
xc
.
FlowRule
.
RuleId
).
ToArray
();
}
}
}
IoTSharp.Data/FlowRule.cs
浏览文件 @
d9ef6363
...
...
@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using
System.ComponentModel.DataAnnotations.Schema
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
IoTSharp.Contracts
;
using
Microsoft.EntityFrameworkCore.Storage
;
namespace
IoTSharp.Data
...
...
IoTSharp.Data/PlayloadData.cs
浏览文件 @
d9ef6363
using
Newtonsoft.Json.Converters
;
using
IoTSharp.Contracts
;
using
Newtonsoft.Json.Converters
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
...
...
IoTSharp.Data/Produce.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
...
...
IoTSharp.Data/TelemetryData.cs
浏览文件 @
d9ef6363
using
System
;
using
IoTSharp.Contracts
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.ComponentModel.DataAnnotations.Schema
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
DataType
=
IoTSharp
.
Contracts
.
DataType
;
namespace
IoTSharp.Data
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录