Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
IoTSharp
提交
6fa70f3d
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,发现更多精彩内容 >>
提交
6fa70f3d
编写于
10月 25, 2020
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
镜像内加入工具
上级
58bf9aa3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
9 deletion
+37
-9
IoTSharp/Dockerfile
IoTSharp/Dockerfile
+6
-0
IoTSharp/Handlers/MQTTServerHandler.cs
IoTSharp/Handlers/MQTTServerHandler.cs
+3
-3
IoTSharp/Startup.cs
IoTSharp/Startup.cs
+6
-1
IoTSharp/Storage/TaosStorage.cs
IoTSharp/Storage/TaosStorage.cs
+22
-5
未找到文件。
IoTSharp/Dockerfile
浏览文件 @
6fa70f3d
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM
mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
RUN
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free"
>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free"
>>
/etc/apt/sources.list
&&
\
apt-get
-y
-q
update
&&
apt-get
install
-y
-q
apt-utils libgdiplus libc6-dev lsof net-tools wget sqlite3 python3 bashtop
&&
\
apt-get autoremove
-y
&&
apt-get clean
&&
apt-get autoclean
&&
rm
/var/cache/apt/
*
-rf
&&
ln
-sf
/usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN
curl
-o
TDengine-client.tar.gz https://www.taosdata.com/download/download-gettingStarted.php?pkg
=
tdengine_linux
&&
\
tar
-xzvf
TDengine-client.tar.gz
&&
rm
TDengine-client.tar.gz
-f
&&
cd
$(
ls
TDengine-client
*
-d
)
&&
./install_client.sh
&&
\
rm
$(
pwd
)
-rf
...
...
IoTSharp/Handlers/MQTTServerHandler.cs
浏览文件 @
6fa70f3d
...
...
@@ -253,9 +253,9 @@ namespace IoTSharp.Handlers
{
try
{
var
_xdev
=
_device
.
Get
<
Device
>(
args
.
ClientId
);
if
(
_xdev
.
HasValue
)
if
(
_device
.
Exists
(
args
.
ClientId
))
{
var
_xdev
=
_device
.
Get
<
Device
>(
args
.
ClientId
);
var
dev
=
_xdev
.
Value
;
using
(
var
scope
=
_scopeFactor
.
CreateScope
())
using
(
var
_dbContext
=
scope
.
ServiceProvider
.
GetRequiredService
<
ApplicationDbContext
>())
...
...
@@ -269,7 +269,7 @@ namespace IoTSharp.Handlers
}
else
{
_logger
.
Log
Error
(
$"Server_ClientDisconnected ClientId:
{
args
.
ClientId
}
DisconnectType:
{
args
.
DisconnectType
}
, 未能在缓存中找到"
);
_logger
.
Log
Warning
(
$"Server_ClientDisconnected ClientId:
{
args
.
ClientId
}
DisconnectType:
{
args
.
DisconnectType
}
, 未能在缓存中找到"
);
}
}
catch
(
Exception
ex
)
...
...
IoTSharp/Startup.cs
浏览文件 @
6fa70f3d
...
...
@@ -60,7 +60,12 @@ namespace IoTSharp
// This method gets called by the runtime. Use this method to add services to the container.
public
void
ConfigureServices
(
IServiceCollection
services
)
{
var
settings
=
Configuration
.
Get
<
AppSettings
>();
var
settings
=
Configuration
.
Get
<
AppSettings
>();
services
.
Configure
((
Action
<
AppSettings
>)(
setting
=>
{
Configuration
.
Bind
(
setting
);
}));
services
.
AddDbContextPool
<
ApplicationDbContext
>(
options
=>
options
.
UseNpgsql
(
Configuration
.
GetConnectionString
(
"IoTSharp"
)),
poolSize
:
settings
.
DbContextPoolSize
);
services
.
AddIdentity
<
IdentityUser
,
IdentityRole
>()
.
AddRoles
<
IdentityRole
>()
...
...
IoTSharp/Storage/TaosStorage.cs
浏览文件 @
6fa70f3d
...
...
@@ -62,8 +62,10 @@ namespace IoTSharp.Storage
{
using
(
TaosConnection
db
=
new
TaosConnection
(
_taosBuilder
.
ConnectionString
))
{
db
.
Open
();
string
sql
=
$"select last_row(*) from telemetrydata where deviceid='
{
deviceId
:
N
}
' group by deviceid,keyname"
;
List
<
TelemetryDataDto
>
dt
=
SqlToTDD
(
db
,
sql
,
"last_row("
,
")"
,
string
.
Empty
);
db
.
Close
();
return
Task
.
FromResult
(
dt
);
}
}
...
...
@@ -119,10 +121,12 @@ namespace IoTSharp.Storage
{
using
(
TaosConnection
db
=
new
TaosConnection
(
_taosBuilder
.
ConnectionString
))
{
db
.
Open
();
IEnumerable
<
string
>
kvs
=
from
k
in
keys
select
$" keyname = '
{
k
}
' "
;
string
sql
=
$"select last_row(*) from telemetrydata where deviceid='
{
deviceId
:
N
}
' and (
{
string
.
Join
(
"or"
,
kvs
)
}
) group by deviceid,keyname"
;
List
<
TelemetryDataDto
>
dt
=
SqlToTDD
(
db
,
sql
,
"last_row("
,
")"
,
string
.
Empty
);
db
.
Close
();
return
Task
.
FromResult
(
dt
);
}
}
...
...
@@ -148,10 +152,12 @@ namespace IoTSharp.Storage
{
using
(
TaosConnection
db
=
new
TaosConnection
(
_taosBuilder
.
ConnectionString
))
{
db
.
Open
();
IEnumerable
<
string
>
kvs
=
from
k
in
keys
select
$" keyname = '
{
k
}
' "
;
string
sql
=
$"select tbname,keyname from telemetrydata where deviceid='
{
deviceId
:
N
}
' and (
{
string
.
Join
(
"or"
,
kvs
)
}
) "
;
List
<
TelemetryDataDto
>
dt
=
SQLToDTByDate
(
begin
,
end
,
db
,
sql
);
db
.
Close
();
return
Task
.
FromResult
(
dt
);
}
}
...
...
@@ -165,8 +171,10 @@ namespace IoTSharp.Storage
{
using
(
TaosConnection
db
=
new
TaosConnection
(
_taosBuilder
.
ConnectionString
))
{
db
.
Open
();
string
sql
=
$"select tbname,keyname from telemetrydata where deviceid='
{
deviceId
:
N
}
'"
;
List
<
TelemetryDataDto
>
dt
=
SQLToDTByDate
(
begin
,
end
,
db
,
sql
);
db
.
Close
();
return
Task
.
FromResult
(
dt
);
}
}
...
...
@@ -230,18 +238,27 @@ namespace IoTSharp.Storage
lst
.
Add
(
vals
);
}
});
await
Retry
.
RetryOnAny
(
10
,
async
f
=>
try
{
db
.
Open
();
var
cmd
=
db
.
CreateCommand
(
$"INSERT INTO
{
string
.
Join
(
"\r\n"
,
lst
)}
"
);
_logger
.
LogInformation
(
cmd
.
CommandText
);
int
dt
=
await
cmd
.
ExecuteNonQueryAsync
();
db
.
Close
();
_logger
.
LogInformation
(
$"数据入库完成,共数据
{
lst
.
Count
}
条,写入
{
dt
}
条"
);
},
ef
=>
{
_logger
.
LogError
(
ef
.
ex
,
$"
{
msg
.
DeviceId
}
数据处理第
{
ef
.
current
}
次失败
{
ef
.
ex
.
Message
}
{
ef
.
ex
.
InnerException
?.
Message
}
"
);
});
}
catch
(
Exception
ex
)
{
_logger
.
LogError
(
ex
,
$"
{
msg
.
DeviceId
}
数据处理失败
{
ex
.
Message
}
{
ex
.
InnerException
?.
Message
}
"
);
}
finally
{
db
.
Dispose
();
}
}
}
catch
(
TaosException
ex
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录