Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
6ebb3006
IoTSharp
项目概览
IoTSharp
/
IoTSharp
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
6ebb3006
编写于
3月 18, 2022
作者:
W
wq1234wq
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/IoTSharp/IoTSharp
上级
3b6a4a58
d69d73b3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
104 addition
and
57 deletion
+104
-57
IoTSharp/Controllers/DevicesController.cs
IoTSharp/Controllers/DevicesController.cs
+97
-50
IoTSharp/Dockerfile
IoTSharp/Dockerfile
+2
-2
IoTSharp/Extensions/DeviceExtension.cs
IoTSharp/Extensions/DeviceExtension.cs
+2
-2
README.md
README.md
+3
-3
未找到文件。
IoTSharp/Controllers/DevicesController.cs
浏览文件 @
6ebb3006
...
@@ -50,7 +50,10 @@ namespace IoTSharp.Controllers
...
@@ -50,7 +50,10 @@ namespace IoTSharp.Controllers
private
const
string
_map_to_attribute_
=
"_map_to_attribute_"
;
private
const
string
_map_to_attribute_
=
"_map_to_attribute_"
;
private
const
string
_map_to_devname
=
"_map_to_devname"
;
private
const
string
_map_to_devname
=
"_map_to_devname"
;
private
const
string
_map_to_jsontext_in_json
=
"_map_to_jsontext_in_json"
;
private
const
string
_map_to_jsontext_in_json
=
"_map_to_jsontext_in_json"
;
private
const
string
_map_to_data_in_array
=
"_map_to_data_in_array"
;
private
const
string
_map_to_subdevname
=
"_map_to_subdevname"
;
private
const
string
_map_var_devname
=
"$devname"
;
private
const
string
_map_var_devname
=
"$devname"
;
private
const
string
_map_var_subdevname
=
"$subdevname"
;
private
const
string
_map_to_devname_format
=
"_map_to_devname_format"
;
private
const
string
_map_to_devname_format
=
"_map_to_devname_format"
;
private
const
string
_map_to_
=
"_map_to_"
;
private
const
string
_map_to_
=
"_map_to_"
;
private
readonly
ApplicationDbContext
_context
;
private
readonly
ApplicationDbContext
_context
;
...
@@ -878,70 +881,44 @@ namespace IoTSharp.Controllers
...
@@ -878,70 +881,44 @@ namespace IoTSharp.Controllers
doc
.
LoadXml
(
body
);
doc
.
LoadXml
(
body
);
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeXmlNode
(
doc
);
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeXmlNode
(
doc
);
}
}
var
atts
=
await
_caching
.
GetAsync
(
$"_map_
{
_dev
.
Id
}
"
,
async
()
=>
var
atts
_cach
=
await
_caching
.
GetAsync
(
$"_map_
{
_dev
.
Id
}
"
,
async
()
=>
{
{
var
guids
=
from
al
in
_context
.
AttributeLatest
where
al
.
DeviceId
==
_dev
.
Id
&&
al
.
KeyName
.
StartsWith
(
_map_to_
)
select
al
;
var
guids
=
from
al
in
_context
.
AttributeLatest
where
al
.
DeviceId
==
_dev
.
Id
&&
al
.
KeyName
.
StartsWith
(
_map_to_
)
select
al
;
return
await
guids
.
ToArrayAsync
();
return
await
guids
.
ToArrayAsync
();
}
}
,
TimeSpan
.
FromSeconds
(
_setting
.
RuleCachingExpiration
));
,
TimeSpan
.
FromSeconds
(
_setting
.
RuleCachingExpiration
));
if
(
atts
.
HasValue
)
if
(
atts
_cach
.
HasValue
)
{
{
try
try
{
{
var
jroot
=
JToken
.
Parse
(
json
);
var
jt
=
JToken
.
Parse
(
json
);
JToken
jt
=
null
;
var
pathx
=
atts
.
Value
.
FirstOrDefault
(
al
=>
al
.
KeyName
==
_map_to_jsontext_in_json
)?.
Value_String
;
var
atts
=
atts_cach
.
Value
;
var
pathx
=
atts
.
FirstOrDefault
(
al
=>
al
.
KeyName
==
_map_to_jsontext_in_json
)?.
Value_String
;
if
(
pathx
!=
null
)
if
(
pathx
!=
null
)
{
{
jt
=
JToken
.
Parse
(
jt
.
SelectToken
(
pathx
).
ToObject
<
string
>());
jt
=
JToken
.
Parse
(
j
roo
t
.
SelectToken
(
pathx
).
ToObject
<
string
>());
}
}
var
devnamekey
=
atts
.
Value
.
FirstOrDefault
(
g
=>
g
.
KeyName
==
_map_to_devname
);
else
if
(
devnamekey
!=
null
)
{
{
var
devnameformatkey
=
atts
.
Value
.
FirstOrDefault
(
g
=>
g
.
KeyName
==
_map_to_devname_format
)?.
Value_String
;
jt
=
jroot
;
var
devname
=
(
jt
.
SelectToken
(
devnamekey
.
Value_String
)
as
JValue
)?.
ToObject
<
string
>()
;
}
if
(
devname
!=
null
&&
!
string
.
IsNullOrEmpty
(
devname
))
var
data_in_array
=
atts
.
FirstOrDefault
(
al
=>
al
.
KeyName
==
_map_to_data_in_array
)?.
Value_String
;
{
if
(!
string
.
IsNullOrEmpty
(
data_in_array
))
var
_devname
=
(
devnameformatkey
??
_map_var_devname
).
Replace
(
_map_var_devname
,
devname
);
{
if
(!
string
.
IsNullOrEmpty
(
_devname
))
var
subdevname
=
atts
.
FirstOrDefault
(
al
=>
al
.
KeyName
==
_map_to_subdevname
)?.
Value_String
;
{
var
jary
=
jt
.
SelectToken
(
data_in_array
)
as
JArray
;
var
device
=
_dev
.
JudgeOrCreateNewDevice
(
_devname
,
_scopeFactor
,
_logger
);
jary
.
Children
().
ForEach
(
jo
=>
var
pairs_att
=
new
Dictionary
<
string
,
object
>();
var
pairs_tel
=
new
Dictionary
<
string
,
object
>();
atts
.
Value
?.
ToList
().
ForEach
(
g
=>
{
var
value
=(
jt
.
SelectToken
(
g
.
Value_String
)
as
JValue
)?.
JValueToObject
();
if
(
value
!=
null
&&
g
.
KeyName
?.
Length
>
0
)
{
if
(
g
.
KeyName
.
StartsWith
(
_map_to_attribute_
)
&&
g
.
KeyName
.
Length
>
_map_to_attribute_
.
Length
)
{
pairs_att
.
Add
(
g
.
KeyName
.
Substring
(
_map_to_attribute_
.
Length
),
value
);
}
else
if
(
g
.
KeyName
.
StartsWith
(
_map_to_telemety_
)
&&
g
.
KeyName
.
Length
>
_map_to_telemety_
.
Length
)
{
pairs_tel
.
Add
(
g
.
KeyName
.
Substring
(
_map_to_telemety_
.
Length
),
value
);
}
}
});
if
(
pairs_tel
.
Any
())
{
_queue
.
PublishTelemetryData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
MsgBody
=
pairs_tel
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
TelemetryData
});
}
if
(
pairs_att
.
Any
())
{
_queue
.
PublishAttributeData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
MsgBody
=
pairs_att
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
AttributeData
});
}
_queue
.
PublishDeviceStatus
(
device
.
Id
,
true
);
_queue
.
PublishDeviceStatus
(
_dev
.
Id
,
true
);
}
}
else
{
{
_logger
.
LogInformation
(
$"数据"
);
string
_devname
=
buid_dev_name
(
atts
,
jt
,
jo
);
}
push_one_device_data_with_json
(
jo
,
jt
,
_dev
,
_devname
,
atts
);
});
}
else
{
string
_devname
=
buid_dev_name
(
atts
,
jt
,
null
);
push_one_device_data_with_json
(
jt
,
jroot
,
_dev
,
_devname
,
atts
);
}
}
return
Ok
(
new
ApiResult
(
ApiCode
.
Success
,
"OK"
));
return
Ok
(
new
ApiResult
(
ApiCode
.
Success
,
"OK"
));
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
...
@@ -957,6 +934,76 @@ namespace IoTSharp.Controllers
...
@@ -957,6 +934,76 @@ namespace IoTSharp.Controllers
}
}
}
}
private
string
buid_dev_name
(
AttributeLatest
[]
atts
,
JToken
jt
,
JToken
jc
)
{
string
_result
=
string
.
Empty
;
var
devnamekey
=
atts
.
FirstOrDefault
(
g
=>
g
.
KeyName
==
_map_to_devname
);
var
subdevnamekey
=
atts
.
FirstOrDefault
(
g
=>
g
.
KeyName
==
_map_to_subdevname
);
if
(
devnamekey
!=
null
)
{
var
devnameformatkey
=
atts
.
FirstOrDefault
(
g
=>
g
.
KeyName
==
_map_to_devname_format
)?.
Value_String
??
_map_var_devname
;
var
devname
=
(
jt
.
SelectToken
(
devnamekey
.
Value_String
)
as
JValue
)?.
ToObject
<
string
>();
var
subdevname
=
(
jc
!=
null
)?(
jc
.
SelectToken
(
subdevnamekey
.
Value_String
)
as
JValue
)?.
ToObject
<
string
>():
string
.
Empty
;
if
(!
string
.
IsNullOrEmpty
(
devnameformatkey
))
{
_result
=
devnameformatkey
;
if
(!
string
.
IsNullOrEmpty
(
devname
))
_result
=
_result
.
Replace
(
_map_var_devname
,
devname
);
if
(!
string
.
IsNullOrEmpty
(
subdevname
))
_result
=
_result
.
Replace
(
_map_var_subdevname
,
subdevname
);
}
else
{
_result
=
$"
{
devname
}{
subdevname
}
"
;
}
}
return
_result
;
}
private
void
push_one_device_data_with_json
(
JToken
jt
,
JToken
jroot
,
Device
_dev
,
string
_devname
,
AttributeLatest
[]
atts
)
{
var
device
=
_dev
.
JudgeOrCreateNewDevice
(
_devname
,
_scopeFactor
,
_logger
);
var
pairs_att
=
new
Dictionary
<
string
,
object
>();
var
pairs_tel
=
new
Dictionary
<
string
,
object
>();
atts
?.
ToList
().
ForEach
(
g
=>
{
JValue
jv
=
null
;
if
(
g
.
Value_String
.
StartsWith
(
"@"
))
//如果是@开头, 则从父节点取
{
jv
=
jroot
.
SelectToken
(
g
.
Value_String
.
Substring
(
1
))
as
JValue
;
}
else
{
jv
=
jt
.
SelectToken
(
g
.
Value_String
)
as
JValue
;
}
var
value
=
(
jv
)?.
JValueToObject
();
if
(
value
!=
null
&&
g
.
KeyName
?.
Length
>
0
)
{
if
(
g
.
KeyName
.
StartsWith
(
_map_to_attribute_
)
&&
g
.
KeyName
.
Length
>
_map_to_attribute_
.
Length
)
{
pairs_att
.
Add
(
g
.
KeyName
.
Substring
(
_map_to_attribute_
.
Length
),
value
);
}
else
if
(
g
.
KeyName
.
StartsWith
(
_map_to_telemety_
)
&&
g
.
KeyName
.
Length
>
_map_to_telemety_
.
Length
)
{
pairs_tel
.
Add
(
g
.
KeyName
.
Substring
(
_map_to_telemety_
.
Length
),
value
);
}
}
});
if
(
pairs_tel
.
Any
())
{
_queue
.
PublishTelemetryData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
MsgBody
=
pairs_tel
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
TelemetryData
});
}
if
(
pairs_att
.
Any
())
{
_queue
.
PublishAttributeData
(
new
RawMsg
()
{
DeviceId
=
device
.
Id
,
MsgBody
=
pairs_att
,
DataSide
=
DataSide
.
ClientSide
,
DataCatalog
=
DataCatalog
.
AttributeData
});
}
_queue
.
PublishDeviceStatus
(
device
.
Id
,
true
);
_queue
.
PublishDeviceStatus
(
_dev
.
Id
,
true
);
}
/// <summary>
/// <summary>
/// 上传原始Json或者xml 通过规则链进行解析。
/// 上传原始Json或者xml 通过规则链进行解析。
/// </summary>
/// </summary>
...
...
IoTSharp/Dockerfile
浏览文件 @
6ebb3006
...
@@ -6,7 +6,7 @@ RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib
...
@@ -6,7 +6,7 @@ RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian-security jessie/updates main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian-security jessie/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 iputils-ping inetutils-tools
libssl-dev libssl1.0.0
curl libfontconfig1
&&
\
apt-get
-y
-q
update
&&
apt-get
install
-y
-q
apt-utils libgdiplus libc6-dev lsof net-tools wget sqlite3 python3 iputils-ping inetutils-tools curl libfontconfig1
&&
\
apt-get autoremove
-y
&&
apt-get clean
&&
apt-get autoclean
&&
rm
/var/cache/apt/
*
-rf
&&
\
apt-get autoremove
-y
&&
apt-get clean
&&
apt-get autoclean
&&
rm
/var/cache/apt/
*
-rf
&&
\
ln
-sf
/usr/share/zoneinfo/Asia/Shanghai /etc/localtime
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&pkgName=TDengine-client-2.0.12.0-Linux-x64.tar.gz" && \
#RUN curl -o TDengine-client.tar.gz "https://www.taosdata.com/download/download-gettingStarted.php?pkg=tdengine_linux&pkgName=TDengine-client-2.0.12.0-Linux-x64.tar.gz" && \
...
@@ -31,7 +31,7 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build
...
@@ -31,7 +31,7 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build
RUN
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free"
>
/etc/apt/sources.list
&&
\
RUN
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free"
>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free"
>>
/etc/apt/sources.list
&&
\
echo
"deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free"
>>
/etc/apt/sources.list
&&
\
apt-get
-y
-q
update
&&
apt-get
install
-y
-q
git
libssl-dev
curl gnupg libcurl4 gcc g++ make gnupg2 build-essential wget
&&
\
apt-get
-y
-q
update
&&
apt-get
install
-y
-q
git curl gnupg libcurl4 gcc g++ make gnupg2 build-essential wget
&&
\
apt-get autoremove
-y
&&
apt-get clean
&&
apt-get autoclean
&&
rm
/var/cache/apt/
*
-rf
apt-get autoremove
-y
&&
apt-get clean
&&
apt-get autoclean
&&
rm
/var/cache/apt/
*
-rf
...
...
IoTSharp/Extensions/DeviceExtension.cs
浏览文件 @
6ebb3006
...
@@ -20,7 +20,7 @@ namespace IoTSharp.Extensions
...
@@ -20,7 +20,7 @@ namespace IoTSharp.Extensions
{
{
if
(
device
.
Customer
==
null
||
device
.
Tenant
==
null
||
string
.
IsNullOrEmpty
(
device
.
Name
))
if
(
device
.
Customer
==
null
||
device
.
Tenant
==
null
||
string
.
IsNullOrEmpty
(
device
.
Name
))
{
{
throw
new
Exception
(
"Customer or Tenant or Name
is null or empty!"
);
throw
new
Exception
(
$"Customer(
{
device
.
Customer
?.
Id
}
) or Tenant(
{
device
.
Tenant
?.
Id
}
) or Name(
{
device
.
Name
}
)
is null or empty!"
);
}
}
else
else
{
{
...
@@ -39,7 +39,7 @@ namespace IoTSharp.Extensions
...
@@ -39,7 +39,7 @@ namespace IoTSharp.Extensions
{
{
if
(
device
.
Customer
==
null
||
device
.
Tenant
==
null
||
string
.
IsNullOrEmpty
(
device
.
Name
))
if
(
device
.
Customer
==
null
||
device
.
Tenant
==
null
||
string
.
IsNullOrEmpty
(
device
.
Name
))
{
{
throw
new
Exception
(
"Customer or Tenant or Name
is null or empty!"
);
throw
new
Exception
(
$"Customer(
{
device
.
Customer
?.
Id
}
) or Tenant(
{
device
.
Tenant
?.
Id
}
) or Name(
{
device
.
Name
}
)
is null or empty!"
);
}
}
else
else
{
{
...
...
README.md
浏览文件 @
6ebb3006
...
@@ -30,15 +30,15 @@ IoTSharp is an open-source IoT platform for data collection, processing, visuali
...
@@ -30,15 +30,15 @@ IoTSharp is an open-source IoT platform for data collection, processing, visuali
*
[
SQLServer
](
IoTSharp/appsettings.SQLServer.json
)
Microsoft SQL Server 2016 (RTM-GDR) (KB4019088) - 13.0.1742.0 (X64) ,Support for sharding
*
[
SQLServer
](
IoTSharp/appsettings.SQLServer.json
)
Microsoft SQL Server 2016 (RTM-GDR) (KB4019088) - 13.0.1742.0 (X64) ,Support for sharding
*
[
Sqlite
](
IoTSharp/appsettings.Sqlite.json
)
Support for sharding
*
[
Sqlite
](
IoTSharp/appsettings.Sqlite.json
)
Support for sharding
##
Demo
##
IoTSharp online
http
://139.9.232.10:2927
http
s://cloud.iotsharp.net/
## doc
## doc
https://docs.iotsharp.net/
https://docs.iotsharp.net/
## How to install IoTSharp using docker ?
## How to install IoTSharp using docker ?
-
docker pull
maikebing
/iotsharp
-
docker pull
iotsharp
/iotsharp
## How to install using Linux daemon ?
## How to install using Linux daemon ?
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录