Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
a15d376f
IoTSharp
项目概览
IoTSharp
/
IoTSharp
8 个月 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a15d376f
编写于
8月 17, 2020
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改了设备最新属性的获取和权限判断
上级
849ac9cb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
112 addition
and
60 deletion
+112
-60
IoTSharp.Test/IoTSharp.Test.csproj
IoTSharp.Test/IoTSharp.Test.csproj
+1
-1
IoTSharp/Controllers/DevicesController.cs
IoTSharp/Controllers/DevicesController.cs
+66
-36
IoTSharp/Dtos/AttributeDataDto.cs
IoTSharp/Dtos/AttributeDataDto.cs
+20
-0
IoTSharp/Extensions/DeviceExtension.cs
IoTSharp/Extensions/DeviceExtension.cs
+2
-0
IoTSharp/IoTSharp.csproj
IoTSharp/IoTSharp.csproj
+15
-15
IoTSharp/IoTSharp.xml
IoTSharp/IoTSharp.xml
+8
-8
未找到文件。
IoTSharp.Test/IoTSharp.Test.csproj
浏览文件 @
a15d376f
...
...
@@ -11,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.
6
" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.
7
" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
...
...
IoTSharp/Controllers/DevicesController.cs
浏览文件 @
a15d376f
...
...
@@ -19,6 +19,8 @@ using MQTTnet.Client.Options;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.Extensions.Logging
;
using
IoTSharp.Storage
;
using
k8s.Models
;
using
Newtonsoft.Json.Linq
;
namespace
IoTSharp.Controllers
{
...
...
@@ -104,82 +106,112 @@ namespace IoTSharp.Controllers
[
ProducesResponseType
(
StatusCodes
.
Status200OK
)]
[
ProducesResponseType
(
typeof
(
ApiResult
),
StatusCodes
.
Status404NotFound
)]
[
ProducesDefaultResponseType
]
public
async
Task
<
ActionResult
<
List
<
Attribute
Latest
>>>
GetAttributeLatest
(
Guid
deviceId
)
public
async
Task
<
ActionResult
<
List
<
Attribute
DataDto
>>>
GetAttributeLatest
(
Guid
deviceId
)
{
var
devid
=
from
dev
in
_context
.
AttributeLatest
where
dev
.
DeviceId
==
deviceId
select
dev
;
if
(
!
devid
.
Any
()
)
Device
dev
=
Found
(
deviceId
)
;
if
(
dev
==
null
)
{
return
NotFound
(
new
ApiResult
(
ApiCode
.
NotFoundDeviceIdentity
,
$"Device's Identity not found "
));
}
return
await
devid
.
ToListAsync
();
else
{
var
devid
=
from
t
in
_context
.
AttributeLatest
where
t
.
DeviceId
==
deviceId
select
new
AttributeDataDto
()
{
DataSide
=
t
.
DataSide
,
DateTime
=
t
.
DateTime
,
KeyName
=
t
.
KeyName
,
Value
=
t
.
ToObject
()
};
if
(!
devid
.
Any
())
{
return
NotFound
(
new
ApiResult
(
ApiCode
.
NotFoundDeviceIdentity
,
$"Device's Identity not found "
));
}
return
await
devid
.
ToListAsync
();
}
}
/// <summary>
///
获取指定设备的最新遥测数据
///
获取指定设备指定keys的最新属性
/// </summary>
/// <param name="deviceId"></param>
/// <param name="deviceId">Which device do you read?</param>
/// <param name="keys">Specify key name list , use , or space or ; to split </param>
/// <returns></returns>
[
Authorize
(
Roles
=
nameof
(
UserRole
.
NormalUser
))]
[
HttpGet
(
"{deviceId}/
TelemetryLatest
"
)]
[
HttpGet
(
"{deviceId}/
AttributeLatest/{keys}
"
)]
[
ProducesResponseType
(
StatusCodes
.
Status200OK
)]
[
ProducesResponseType
(
typeof
(
ApiResult
),
StatusCodes
.
Status404NotFound
)]
[
ProducesDefaultResponseType
]
public
async
Task
<
ActionResult
<
List
<
TelemetryDataDto
>>>
GetTelemetryLatest
(
Guid
deviceId
)
public
async
Task
<
ActionResult
<
List
<
AttributeDataDto
>>>
GetAttributeLatest
(
Guid
deviceId
,
string
keys
)
{
var
devid
=
from
dev
in
_context
.
TelemetryLatest
where
dev
.
DeviceId
==
deviceId
select
dev
;
if
(
!
devid
.
Any
()
)
Device
dev
=
Found
(
deviceId
)
;
if
(
dev
==
null
)
{
return
NotFound
(
new
ApiResult
(
ApiCode
.
NotFoundDeviceIdentity
,
$"Device's Identity not found "
));
}
return
await
_storage
.
GetTelemetryLatest
(
deviceId
);
else
{
var
kv
=
from
t
in
_context
.
AttributeLatest
where
t
.
DeviceId
==
t
.
DeviceId
&&
keys
.
Split
(
','
,
' '
,
';'
).
Contains
(
t
.
KeyName
)
select
new
AttributeDataDto
()
{
DataSide
=
t
.
DataSide
,
DateTime
=
t
.
DateTime
,
KeyName
=
t
.
KeyName
,
Value
=
t
.
ToObject
()
};
return
await
kv
.
ToListAsync
();
}
}
private
Device
Found
(
Guid
deviceId
)
{
var
cid
=
User
.
Claims
.
First
(
c
=>
c
.
Type
==
IoTSharpClaimTypes
.
Customer
);
var
dev
=
_context
.
Device
.
Include
(
d
=>
d
.
Customer
).
FirstOrDefault
(
d
=>
d
.
Id
==
deviceId
&&
d
.
Customer
.
Id
.
ToString
()
==
cid
.
Value
);
return
dev
;
}
private
Task
<
Device
>
FoundAsync
(
Guid
deviceId
)
{
var
cid
=
User
.
Claims
.
First
(
c
=>
c
.
Type
==
IoTSharpClaimTypes
.
Customer
);
var
dev
=
_context
.
Device
.
Include
(
d
=>
d
.
Customer
).
FirstOrDefaultAsync
(
d
=>
d
.
Id
==
deviceId
&&
d
.
Customer
.
Id
.
ToString
()
==
cid
.
Value
);
return
dev
;
}
/// <summary>
///
获取指定设备的指定key 的
遥测数据
///
获取指定设备的最新
遥测数据
/// </summary>
/// <param name="deviceId">Which device do you read?</param>
/// <param name="keys">指定键值列表, 使用分号或者逗号分割 。 </param>
/// <param name="deviceId"></param>
/// <returns></returns>
[
Authorize
(
Roles
=
nameof
(
UserRole
.
NormalUser
))]
[
HttpGet
(
"{deviceId}/TelemetryLatest
/{keys}
"
)]
[
HttpGet
(
"{deviceId}/TelemetryLatest"
)]
[
ProducesResponseType
(
StatusCodes
.
Status200OK
)]
[
ProducesResponseType
(
typeof
(
ApiResult
),
StatusCodes
.
Status404NotFound
)]
[
ProducesDefaultResponseType
]
public
async
Task
<
ActionResult
<
List
<
TelemetryDataDto
>>>
GetTelemetryLatest
(
Guid
deviceId
,
string
keys
)
public
async
Task
<
ActionResult
<
List
<
TelemetryDataDto
>>>
GetTelemetryLatest
(
Guid
deviceId
)
{
var
dev
=
_context
.
Device
.
Fi
nd
(
deviceId
);
if
(
dev
==
null
)
Device
dev
=
Fou
nd
(
deviceId
);
if
(
dev
==
null
)
{
return
NotFound
(
new
ApiResult
(
ApiCode
.
NotFoundDeviceIdentity
,
$"Device's Identity not found "
));
}
else
{
return
await
_storage
.
GetTelemetryLatest
(
deviceId
,
keys
);
}
return
await
_storage
.
GetTelemetryLatest
(
deviceId
);
}
/// <summary>
/// 获取指定设备
指定keys的最新属性
/// 获取指定设备
的指定key 的遥测数据
/// </summary>
/// <param name="deviceId">Which device do you read?</param>
/// <param name="keys">
Specify key name list , use , or space or ; to split
</param>
/// <param name="keys">
指定键值列表, 使用分号或者逗号分割 。
</param>
/// <returns></returns>
[
Authorize
(
Roles
=
nameof
(
UserRole
.
NormalUser
))]
[
HttpGet
(
"{deviceId}/
Attribute
Latest/{keys}"
)]
[
HttpGet
(
"{deviceId}/
Telemetry
Latest/{keys}"
)]
[
ProducesResponseType
(
StatusCodes
.
Status200OK
)]
[
ProducesResponseType
(
typeof
(
ApiResult
),
StatusCodes
.
Status404NotFound
)]
[
ProducesDefaultResponseType
]
public
async
Task
<
ActionResult
<
object
>>
GetAttributeLatest
(
Guid
deviceId
,
string
keys
)
public
async
Task
<
ActionResult
<
List
<
TelemetryDataDto
>>>
GetTelemetryLatest
(
Guid
deviceId
,
string
keys
)
{
var
dev
=
_context
.
Device
.
Fi
nd
(
deviceId
);
Device
dev
=
Fou
nd
(
deviceId
);
if
(
dev
==
null
)
{
return
NotFound
(
new
ApiResult
(
ApiCode
.
NotFoundDeviceIdentity
,
$"Device's Identity not found "
));
}
else
{
var
kv
=
from
t
in
_context
.
AttributeLatest
where
t
.
DeviceId
==
dev
.
Id
&&
keys
.
Split
(
','
,
' '
,
';'
).
Contains
(
t
.
KeyName
)
select
t
;
return
(
await
kv
.
FirstOrDefaultAsync
())?.
ToObject
();
return
await
_storage
.
GetTelemetryLatest
(
deviceId
,
keys
);
}
}
/// <summary>
/// 获取指定设备和指定时间, 指定key的数据
...
...
@@ -195,7 +227,7 @@ namespace IoTSharp.Controllers
[
ProducesDefaultResponseType
]
public
async
Task
<
ActionResult
<
List
<
TelemetryDataDto
>>>
GetTelemetryData
(
Guid
deviceId
,
string
keys
,
DateTime
begin
)
{
var
dev
=
_context
.
Device
.
Fi
nd
(
deviceId
);
Device
dev
=
Fou
nd
(
deviceId
);
if
(
dev
==
null
)
{
return
NotFound
(
new
ApiResult
(
ApiCode
.
NotFoundDeviceIdentity
,
$"Device's Identity not found "
));
...
...
@@ -221,7 +253,7 @@ namespace IoTSharp.Controllers
[
ProducesDefaultResponseType
]
public
async
Task
<
ActionResult
<
List
<
TelemetryDataDto
>>>
GetTelemetryData
(
Guid
deviceId
,
string
keys
,
DateTime
begin
,
DateTime
end
)
{
var
dev
=
_context
.
Device
.
Fi
nd
(
deviceId
);
Device
dev
=
Fou
nd
(
deviceId
);
if
(
dev
==
null
)
{
return
NotFound
(
new
ApiResult
(
ApiCode
.
NotFoundDeviceIdentity
,
$"Device's Identity not found "
));
...
...
@@ -249,13 +281,11 @@ namespace IoTSharp.Controllers
[
ProducesDefaultResponseType
]
public
async
Task
<
ActionResult
<
Device
>>
GetDevice
(
Guid
id
)
{
var
device
=
await
_context
.
Device
.
FindAsync
(
id
);
Device
device
=
await
FoundAsync
(
id
);
if
(
device
==
null
)
{
return
NotFound
(
new
ApiResult
<
Guid
>(
ApiCode
.
NotFoundDevice
,
$"Device
{
id
}
not found "
,
id
));
}
return
device
;
}
...
...
@@ -353,7 +383,7 @@ namespace IoTSharp.Controllers
[
ProducesDefaultResponseType
]
public
async
Task
<
ActionResult
<
Device
>>
DeleteDevice
(
Guid
id
)
{
var
device
=
await
_context
.
Device
.
FindAsync
(
id
);
Device
device
=
Found
(
id
);
if
(
device
==
null
)
{
return
NotFound
(
new
ApiResult
<
Guid
>(
ApiCode
.
NotFoundDevice
,
$"Device
{
id
}
not found "
,
id
));
...
...
IoTSharp/Dtos/AttributeDataDto.cs
0 → 100644
浏览文件 @
a15d376f
using
IoTSharp.Data
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Dtos
{
public
class
AttributeDataDto
{
public
string
KeyName
{
get
;
set
;
}
public
DataSide
DataSide
{
get
;
set
;
}
public
DateTime
DateTime
{
get
;
set
;
}
public
object
Value
{
get
;
set
;
}
}
}
IoTSharp/Extensions/DeviceExtension.cs
浏览文件 @
a15d376f
using
IoTSharp.Data
;
using
Microsoft.AspNetCore.Mvc
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
...
...
@@ -8,6 +9,7 @@ namespace IoTSharp.Extensions
{
public
static
class
DeviceExtension
{
/// <summary>
/// When creating a device, all the things that need to be done here are done
/// </summary>
...
...
IoTSharp/IoTSharp.csproj
浏览文件 @
a15d376f
...
...
@@ -41,18 +41,18 @@
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="3.1.2" />
<PackageReference Include="AspNetCore.HealthChecks.Network" Version="3.1.1" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="3.1.1" />
<PackageReference Include="EFCore.Sharding" Version="3.1.6.
8
" />
<PackageReference Include="EFCore.Sharding.PostgreSql" Version="3.1.6.
8
" />
<PackageReference Include="EFCore.Sharding" Version="3.1.6.
9
" />
<PackageReference Include="EFCore.Sharding.PostgreSql" Version="3.1.6.
9
" />
<PackageReference Include="IoTSharp.CoAP.NET" Version="2.0.8" />
<PackageReference Include="IoTSharp.X509Extensions" Version="1.4.9" />
<PackageReference Include="kimbus" Version="2.0.1" />
<PackageReference Include="LiteDB" Version="5.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.
6
" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.
6
">
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.
7
" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.
7
">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.
6
" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.
7
" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="MQTTnet" Version="3.0.12" />
...
...
@@ -60,7 +60,7 @@
<PackageReference Include="MQTTnet.Extensions.Rpc" Version="3.0.12" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="NSwag.AspNetCore" Version="13.7.0" />
<PackageReference Include="OptimizedPriorityQueue" Version="
4.2
.0" />
<PackageReference Include="OptimizedPriorityQueue" Version="
5.0
.0" />
<PackageReference Include="ProxyKit" Version="2.3.3" />
<PackageReference Include="Silkier" Version="1.0.121" />
<PackageReference Include="Silkier.AspNetCore" Version="1.0.121" />
...
...
@@ -68,15 +68,15 @@
<PackageReference Include="SilkierQuartz" Version="1.0.46" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.7.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.
6
" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.
6
" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="3.1.
6
" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.
6
" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="3.1.
6
" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.
6
" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.
6
" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.
6
" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="3.1.
6
" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.
7
" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.
7
" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="3.1.
7
" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.
7
" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="3.1.
7
" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.
7
" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.
7
" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.
7
" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="3.1.
7
" />
<PackageReference Include="MQTTnet.AspNetCoreEx" Version="3.0.11" />
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="3.0.12" />
</ItemGroup>
...
...
IoTSharp/IoTSharp.xml
浏览文件 @
a15d376f
...
...
@@ -176,6 +176,14 @@
<param
name=
"deviceId"
></param>
<returns></returns>
</member>
<member
name=
"M:IoTSharp.Controllers.DevicesController.GetAttributeLatest(System.Guid,System.String)"
>
<summary>
获取指定设备指定keys的最新属性
</summary>
<param
name=
"deviceId"
>
Which device do you read?
</param>
<param
name=
"keys"
>
Specify key name list , use , or space or ; to split
</param>
<returns></returns>
</member>
<member
name=
"M:IoTSharp.Controllers.DevicesController.GetTelemetryLatest(System.Guid)"
>
<summary>
获取指定设备的最新遥测数据
...
...
@@ -191,14 +199,6 @@
<param
name=
"keys"
>
指定键值列表, 使用分号或者逗号分割 。
</param>
<returns></returns>
</member>
<member
name=
"M:IoTSharp.Controllers.DevicesController.GetAttributeLatest(System.Guid,System.String)"
>
<summary>
获取指定设备指定keys的最新属性
</summary>
<param
name=
"deviceId"
>
Which device do you read?
</param>
<param
name=
"keys"
>
Specify key name list , use , or space or ; to split
</param>
<returns></returns>
</member>
<member
name=
"M:IoTSharp.Controllers.DevicesController.GetTelemetryData(System.Guid,System.String,System.DateTime)"
>
<summary>
获取指定设备和指定时间, 指定key的数据
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录