Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
2292a0f3
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,发现更多精彩内容 >>
提交
2292a0f3
编写于
9月 14, 2022
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
删掉旧的 TaskAction
上级
fac95c05
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
0 addition
and
677 deletion
+0
-677
IoTSharp.TaskAction/AlarmPullExcutor.cs
IoTSharp.TaskAction/AlarmPullExcutor.cs
+0
-129
IoTSharp.TaskAction/DeviceActionExcutor.cs
IoTSharp.TaskAction/DeviceActionExcutor.cs
+0
-66
IoTSharp.TaskAction/ITaskAction.cs
IoTSharp.TaskAction/ITaskAction.cs
+0
-86
IoTSharp.TaskAction/IoTSharp.TaskAction.csproj
IoTSharp.TaskAction/IoTSharp.TaskAction.csproj
+0
-20
IoTSharp.TaskAction/MessagePullExcutor.cs
IoTSharp.TaskAction/MessagePullExcutor.cs
+0
-178
IoTSharp.TaskAction/RangerCheckExcutor.cs
IoTSharp.TaskAction/RangerCheckExcutor.cs
+0
-75
IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs
IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs
+0
-123
未找到文件。
IoTSharp.TaskAction/AlarmPullExcutor.cs
已删除
100644 → 0
浏览文件 @
fac95c05
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Net
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Serialization
;
using
RestSharp
;
namespace
IoTSharp.TaskAction
{
[
DisplayName
(
"用于告警推送的执行器"
)]
public
class
AlarmPullExcutor
:
ITaskAction
{
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
{
try
{
return
SendData
(
input
);
}
catch
(
Exception
ex
)
{
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
});
}
}
private
async
Task
<
TaskActionOutput
>
SendData
(
TaskActionInput
input
)
{
try
{
var
config
=
JsonConvert
.
DeserializeObject
<
AlarmPullExcutor
.
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
var
restclient
=
new
RestClient
(
config
.
BaseUrl
);
restclient
.
AddDefaultHeader
(
KnownHeaders
.
Accept
,
"*/*"
);
var
request
=
new
RestRequest
(
config
.
Url
+
(
input
.
DeviceId
==
Guid
.
Empty
?
""
:
"/"
+
input
.
DeviceId
));
request
.
AddHeader
(
"X-Access-Token"
,
config
.
Token
);
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddHeader
(
"Content-Type"
,
"application/json"
);
var
alarm
=
JsonConvert
.
DeserializeObject
<
Alarm
>(
input
.
Input
,
new
JsonSerializerSettings
{
ContractResolver
=
new
CamelCasePropertyNamesContractResolver
()
})
??
new
object
();
request
.
AddJsonBody
(
alarm
);
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
var
result
=
JsonConvert
.
DeserializeObject
<
AlarmPullExcutor
.
MessagePullResult
>(
response
.
Content
);
if
(
result
is
{
success
:
true
})
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
false
};
}
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
}
}
catch
(
Exception
ex
)
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
};
;
}
}
private
class
Alarm
{
public
string
originatorType
{
get
;
set
;
}
public
string
originatorName
{
get
;
set
;
}
public
string
alarmType
{
get
;
set
;
}
public
string
alarmDetail
{
get
;
set
;
}
public
string
serverity
{
get
;
set
;
}
public
string
warnDataId
{
get
;
set
;
}
public
DateTime
createDateTime
{
get
;
set
;
}
}
private
class
ModelExecutorConfig
{
public
string
Url
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
public
string
Method
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
}
private
class
MessagePullResult
{
public
bool
success
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
public
long
timestamp
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
}
}
}
IoTSharp.TaskAction/DeviceActionExcutor.cs
已删除
100644 → 0
浏览文件 @
fac95c05
using
Newtonsoft.Json
;
using
RestSharp
;
using
System
;
using
System.ComponentModel
;
using
System.Net
;
using
System.Threading.Tasks
;
namespace
IoTSharp.TaskAction
{
[
DisplayName
(
"用于设备行为推送的执行器"
)]
public
class
DeviceActionExcutor
:
ITaskAction
{
public
override
async
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
{
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
string
contentType
=
"application/json"
;
var
restclient
=
new
RestClient
(
config
.
BaseUrl
);
restclient
.
AddDefaultHeader
(
KnownHeaders
.
Accept
,
"*/*"
);
var
request
=
new
RestRequest
(
config
.
Url
+
(
input
.
DeviceId
==
Guid
.
Empty
?
""
:
"/"
+
input
.
DeviceId
));
request
.
AddHeader
(
"X-Access-Token"
,
config
.
Token
);
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
AddHeader
(
"Content-Type"
,
contentType
);
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddJsonBody
(
new
{
sosType
=
"1"
,
sosContent
=
input
.
Input
,
usingUserId
=
""
});
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
var
result
=
JsonConvert
.
DeserializeObject
<
DeviceActionResult
>(
response
.
Content
);
if
(
result
is
{
success
:
true
})
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
false
};
;
}
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
;
}
}
private
class
DeviceActionResult
{
public
bool
success
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
public
long
timestamp
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
}
private
class
ModelExecutorConfig
{
public
string
Url
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
public
string
Method
{
get
;
set
;
}
public
string
Passwoid
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
}
}
}
\ No newline at end of file
IoTSharp.TaskAction/ITaskAction.cs
已删除
100644 → 0
浏览文件 @
fac95c05
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Converters
;
using
System
;
using
System.Dynamic
;
using
System.Threading.Tasks
;
namespace
IoTSharp.TaskAction
{
public
abstract
class
ITaskAction
{
public
abstract
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
_input
);
public
IServiceProvider
ServiceProvider
{
get
;
set
;
}
}
public
class
TaskActionOutput
{
private
string
_value
;
private
dynamic
_DynamicOutput
;
private
readonly
ExpandoObjectConverter
expConverter
=
new
();
public
Guid
DeviceId
{
get
;
set
;
}
public
bool
ExecutionStatus
{
get
;
set
;
}
public
string
ExecutionInfo
{
get
;
set
;
}
public
dynamic
DynamicOutput
{
get
{
return
_DynamicOutput
;
}
set
{
_DynamicOutput
=
value
;
_value
=
JsonConvert
.
SerializeObject
(
_DynamicOutput
,
expConverter
);
}
}
public
string
Output
{
get
{
return
_value
;
}
set
{
_value
=
value
;
_DynamicOutput
=
JsonConvert
.
DeserializeObject
<
ExpandoObject
>(
_value
,
expConverter
);
}
}
}
public
class
TaskActionInput
{
private
dynamic
_DynamicOutput
;
private
string
_value
;
private
readonly
ExpandoObjectConverter
expConverter
=
new
();
public
Guid
DeviceId
{
get
;
set
;
}
public
String
ExecutorConfig
{
get
;
set
;
}
public
dynamic
DynamicInput
{
get
{
return
_DynamicOutput
;
}
set
{
_DynamicOutput
=
value
;
_value
=
JsonConvert
.
SerializeObject
(
_DynamicOutput
,
expConverter
);
}
}
public
string
Input
{
get
{
return
_value
;
}
set
{
_value
=
value
;
_DynamicOutput
=
JsonConvert
.
DeserializeObject
<
object
>(
_value
,
expConverter
);
}
}
}
}
\ No newline at end of file
IoTSharp.TaskAction/IoTSharp.TaskAction.csproj
已删除
100644 → 0
浏览文件 @
fac95c05
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<CodeAnalysisRuleSet>..\.sonarlint\iotsharp_iotsharpcsharp.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\.sonarlint\iotsharp_iotsharp\CSharp\SonarLint.xml" Link="SonarLint.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="RestSharp" Version="108.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
</Project>
IoTSharp.TaskAction/MessagePullExcutor.cs
已删除
100644 → 0
浏览文件 @
fac95c05
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
RestSharp
;
using
System
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Net
;
using
System.Threading.Tasks
;
namespace
IoTSharp.TaskAction
{
[
DisplayName
(
"用于消息推送的执行器"
)]
public
class
MessagePullExecutor
:
ITaskAction
{
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
{
try
{
return
SendData
(
input
);
}
catch
(
Exception
ex
)
{
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
});
}
}
private
async
Task
<
TaskActionOutput
>
SendData
(
TaskActionInput
input
)
{
try
{
if
(
input
.
Input
.
Contains
(
"ValueKind"
))
{
JObject
o
=
JsonConvert
.
DeserializeObject
(
input
.
Input
)
as
JObject
;
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
var
dd
=
o
.
Properties
().
Select
(
c
=>
new
ParamObject
{
keyName
=
c
.
Name
.
ToLower
(),
value
=
JPropertyToObject
(
c
.
Value
.
First
as
JProperty
)
}).
ToList
();
var
restclient
=
new
RestClient
(
config
.
BaseUrl
);
restclient
.
AddDefaultHeader
(
KnownHeaders
.
Accept
,
"*/*"
);
var
request
=
new
RestRequest
(
config
.
Url
+
(
input
.
DeviceId
==
Guid
.
Empty
?
""
:
"/"
+
input
.
DeviceId
));
request
.
AddHeader
(
"X-Access-Token"
,
config
.
Token
);
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddHeader
(
"Content-Type"
,
"application/json"
);
request
.
AddJsonBody
(
dd
);
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
var
result
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Content
);
if
(
result
is
{
success
:
true
})
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
false
};
;
}
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
ErrorMessage
,
ExecutionStatus
=
false
};
;
}
}
else
{
JObject
o
=
JsonConvert
.
DeserializeObject
(
input
.
Input
)
as
JObject
;
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
var
dd
=
o
.
Properties
().
Select
(
c
=>
new
ParamObject
{
keyName
=
c
.
Name
.
ToLower
(),
value
=
JPropertyToObject
(
c
)
}).
ToList
();
var
restclient
=
new
RestClient
(
config
.
BaseUrl
);
restclient
.
AddDefaultHeader
(
KnownHeaders
.
Accept
,
"*/*"
);
var
request
=
new
RestRequest
(
config
.
Url
+
(
input
.
DeviceId
==
Guid
.
Empty
?
""
:
"/"
+
input
.
DeviceId
));
request
.
AddHeader
(
"X-Access-Token"
,
config
.
Token
);
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddHeader
(
"Content-Type"
,
"application/json"
);
request
.
AddJsonBody
(
dd
);
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
var
result
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Content
);
if
(
result
is
{
success
:
true
})
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
false
};
;
}
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
;
}
}
}
catch
(
Exception
ex
)
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
};
;
}
}
public
static
object
JPropertyToObject
(
JProperty
property
)
{
object
obj
=
null
;
switch
(
property
.
Value
.
Type
)
{
case
JTokenType
.
Integer
:
obj
=
property
.
Value
.
ToObject
<
int
>();
break
;
case
JTokenType
.
Float
:
obj
=
property
.
Value
.
ToObject
<
float
>();
break
;
case
JTokenType
.
String
:
obj
=
property
.
Value
.
ToObject
<
string
>();
break
;
case
JTokenType
.
Boolean
:
obj
=
property
.
Value
.
ToObject
<
bool
>();
break
;
case
JTokenType
.
Date
:
obj
=
property
.
Value
.
ToObject
<
DateTime
>();
break
;
case
JTokenType
.
Bytes
:
obj
=
property
.
Value
.
ToObject
<
byte
[
]>
();
break
;
case
JTokenType
.
Guid
:
obj
=
property
.
Value
.
ToObject
<
Guid
>();
break
;
case
JTokenType
.
Uri
:
obj
=
property
.
Value
.
ToObject
<
Uri
>();
break
;
case
JTokenType
.
TimeSpan
:
obj
=
property
.
Value
.
ToObject
<
TimeSpan
>();
break
;
default
:
obj
=
property
.
Value
;
break
;
}
return
obj
;
}
private
class
MessagePullResult
{
public
bool
success
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
public
long
timestamp
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
}
public
class
ParamObject
{
public
string
keyName
{
get
;
set
;
}
public
dynamic
value
{
get
;
set
;
}
}
private
class
ModelExecutorConfig
{
public
string
Url
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
public
string
Method
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
}
}
}
\ No newline at end of file
IoTSharp.TaskAction/RangerCheckExcutor.cs
已删除
100644 → 0
浏览文件 @
fac95c05
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
namespace
IoTSharp.TaskAction
{
[
DisplayName
(
"用于增加范围属性的执行器"
)]
public
class
RangerCheckExcutor
:
ITaskAction
{
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
_input
)
{
JObject
o
=
JsonConvert
.
DeserializeObject
(
_input
.
Input
)
as
JObject
;
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
_input
.
ExecutorConfig
);
if
(
o
.
SelectToken
(
config
.
PointX
)
!=
null
&&
o
.
SelectToken
(
config
.
PointY
)
!=
null
)
{
var
point
=
new
Point
();
point
.
X
=
o
.
SelectToken
(
config
.
PointX
).
Value
<
double
>();
point
.
Y
=
o
.
SelectToken
(
config
.
PointY
).
Value
<
double
>();
if
(
PointInFeaces
(
point
,
config
.
Ranger
))
{
o
.
Add
(
"iswithinrange"
,
true
);
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
o
.
ToString
(),
ExecutionStatus
=
true
,
DynamicOutput
=
o
});
;
}
else
{
o
.
Add
(
"iswithinrange"
,
false
);
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
o
.
ToString
(),
ExecutionStatus
=
true
,
DynamicOutput
=
o
});
;
}
}
else
{
o
.
Add
(
"iswithinrange"
,
true
);
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
o
.
ToString
(),
ExecutionStatus
=
true
,
DynamicOutput
=
o
});
;
}
}
public
static
bool
PointInFeaces
(
Point
pnt
,
Point
[]
pntlist
)
{
if
(
pntlist
==
null
)
{
return
false
;
}
int
j
=
0
,
cnt
=
0
;
for
(
int
i
=
0
;
i
<
pntlist
.
Length
;
i
++)
{
j
=
(
i
==
pntlist
.
Length
-
1
)
?
0
:
j
+
1
;
if
((
pntlist
[
i
].
Y
!=
pntlist
[
j
].
Y
)
&&
(((
pnt
.
Y
>=
pntlist
[
i
].
Y
)
&&
(
pnt
.
Y
<
pntlist
[
j
].
Y
))
||
((
pnt
.
Y
>=
pntlist
[
j
].
Y
)
&&
(
pnt
.
Y
<
pntlist
[
i
].
Y
)))
&&
(
pnt
.
X
<
(
pntlist
[
j
].
X
-
pntlist
[
i
].
X
)
*
(
pnt
.
Y
-
pntlist
[
i
].
Y
)
/
(
pntlist
[
j
].
Y
-
pntlist
[
i
].
Y
)
+
pntlist
[
i
].
X
))
cnt
++;
}
return
(
cnt
%
2
>
0
)
?
true
:
false
;
}
private
class
ModelExecutorConfig
{
public
string
PointX
{
get
;
set
;
}
public
string
PointY
{
get
;
set
;
}
public
Point
[]
Ranger
{
get
;
set
;
}
}
public
class
Point
{
public
double
X
{
get
;
set
;
}
public
double
Y
{
get
;
set
;
}
}
}
}
IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs
已删除
100644 → 0
浏览文件 @
fac95c05
using
Newtonsoft.Json
;
using
RestSharp
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Net
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json.Linq
;
using
Newtonsoft.Json.Serialization
;
namespace
IoTSharp.TaskAction
{
[
DisplayName
(
"用于遥测数组推送的执行器"
)]
public
class
TelemetryArrayPullExcutor
:
ITaskAction
{
public
TelemetryArrayPullExcutor
()
{
}
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
{
try
{
return
SendData
(
input
);
}
catch
(
Exception
ex
)
{
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
});
}
}
private
async
Task
<
TaskActionOutput
>
SendData
(
TaskActionInput
input
)
{
try
{
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
var
restclient
=
new
RestClient
(
config
.
BaseUrl
);
restclient
.
AddDefaultHeader
(
KnownHeaders
.
Accept
,
"*/*"
);
var
request
=
new
RestRequest
(
config
.
Url
+
(
input
.
DeviceId
==
Guid
.
Empty
?
""
:
"/"
+
input
.
DeviceId
));
request
.
AddHeader
(
"X-Access-Token"
,
config
.
Token
);
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddHeader
(
"Content-Type"
,
"application/json"
);
request
.
AddJsonBody
(
JsonConvert
.
DeserializeObject
<
List
<
TelemetryData
>>(
input
.
Input
,
new
JsonSerializerSettings
{
ContractResolver
=
new
CamelCasePropertyNamesContractResolver
()
})
??
new
object
()
);
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
var
result
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Content
);
if
(
result
is
{
success
:
true
})
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
false
};
}
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
}
}
catch
(
Exception
ex
)
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
};
;
}
}
public
class
TelemetryData
{
[
JsonProperty
(
"keyName"
)]
public
string
keyName
{
get
;
set
;
}
[
JsonProperty
(
"dateTime"
)]
public
DateTime
dateTime
{
get
;
set
;
}
[
JsonProperty
(
"dataType"
)]
public
Data
.
DataType
dataType
{
get
;
set
;
}
[
JsonProperty
(
"value"
)]
public
object
value
{
get
;
set
;
}
}
private
class
MessagePullResult
{
public
bool
success
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
public
long
timestamp
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
}
private
class
ModelExecutorConfig
{
public
string
Url
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
public
string
Method
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录