Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
59818722
IoTSharp
项目概览
IoTSharp
/
IoTSharp
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
59818722
编写于
3月 29, 2022
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
删除不必要的代码
上级
5866a8ad
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
81 addition
and
280 deletion
+81
-280
IoTSharp.TaskAction/Air720Sx.cs
IoTSharp.TaskAction/Air720Sx.cs
+0
-30
IoTSharp.TaskAction/DeviceActionExcutor.cs
IoTSharp.TaskAction/DeviceActionExcutor.cs
+9
-24
IoTSharp.TaskAction/ITaskAction.cs
IoTSharp.TaskAction/ITaskAction.cs
+4
-3
IoTSharp.TaskAction/MessagePullExcutor.cs
IoTSharp.TaskAction/MessagePullExcutor.cs
+24
-84
IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs
IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs
+44
-139
未找到文件。
IoTSharp.TaskAction/Air720Sx.cs
已删除
100644 → 0
浏览文件 @
5866a8ad
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Dynamic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
IoTSharp.Data
;
using
IoTSharp.TaskAction
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
namespace
IoTSharp.TaskAction
{
[
DisplayName
(
"Air720S解析器"
)]
public
class
Air720Sx
:
ITaskAction
{
public
Air720Sx
()
{
}
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
_input
)
{
var
msg
=
_input
.
DynamicInput
;
var
playload
=
System
.
Text
.
Encoding
.
Default
.
GetString
(
Convert
.
FromBase64String
(
msg
.
Payload
));
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
Output
=
playload
,
DeviceId
=
_input
.
DeviceId
});
}
}
}
IoTSharp.TaskAction/DeviceActionExcutor.cs
浏览文件 @
59818722
using
System
;
using
Newtonsoft.Json
;
using
System.Collections.Generic
;
using
RestSharp
;
using
System
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Net
;
using
System.Net
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
RestSharp
;
namespace
IoTSharp.TaskAction
namespace
IoTSharp.TaskAction
{
{
[
DisplayName
(
"用于设备行为推送的执行器"
)]
[
DisplayName
(
"用于设备行为推送的执行器"
)]
public
class
DeviceActionExcutor
:
ITaskAction
public
class
DeviceActionExcutor
:
ITaskAction
{
{
public
DeviceActionExcutor
()
{
}
public
override
async
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
public
override
async
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
{
{
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
...
@@ -32,12 +22,12 @@ namespace IoTSharp.TaskAction
...
@@ -32,12 +22,12 @@ namespace IoTSharp.TaskAction
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
AddHeader
(
"Content-Type"
,
contentType
);
request
.
AddHeader
(
"Content-Type"
,
contentType
);
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddJsonBody
(
new
{
sosType
=
"1"
,
sosContent
=
input
.
Input
,
usingUserId
=
""
});
request
.
AddJsonBody
(
new
{
sosType
=
"1"
,
sosContent
=
input
.
Input
,
usingUserId
=
""
});
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
{
var
result
=
JsonConvert
.
DeserializeObject
<
DeviceActionResult
>(
response
.
Content
);
var
result
=
JsonConvert
.
DeserializeObject
<
DeviceActionResult
>(
response
.
Content
);
if
(
result
is
{
success
:
true
})
if
(
result
is
{
success
:
true
})
{
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
}
}
...
@@ -50,12 +40,10 @@ namespace IoTSharp.TaskAction
...
@@ -50,12 +40,10 @@ namespace IoTSharp.TaskAction
{
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
;
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
;
}
}
}
}
class
DeviceActionResult
{
private
class
DeviceActionResult
{
public
bool
success
{
get
;
set
;
}
public
bool
success
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
...
@@ -63,11 +51,9 @@ namespace IoTSharp.TaskAction
...
@@ -63,11 +51,9 @@ namespace IoTSharp.TaskAction
public
long
timestamp
{
get
;
set
;
}
public
long
timestamp
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
}
}
class
ModelExecutorConfig
private
class
ModelExecutorConfig
{
{
public
string
Url
{
get
;
set
;
}
public
string
Url
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
...
@@ -75,7 +61,6 @@ namespace IoTSharp.TaskAction
...
@@ -75,7 +61,6 @@ namespace IoTSharp.TaskAction
public
string
Passwoid
{
get
;
set
;
}
public
string
Passwoid
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
}
}
}
}
}
}
\ No newline at end of file
IoTSharp.TaskAction/ITaskAction.cs
浏览文件 @
59818722
...
@@ -8,8 +8,7 @@ namespace IoTSharp.TaskAction
...
@@ -8,8 +8,7 @@ namespace IoTSharp.TaskAction
{
{
public
abstract
class
ITaskAction
public
abstract
class
ITaskAction
{
{
public
abstract
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
_input
);
public
abstract
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
_input
);
public
IServiceProvider
ServiceProvider
{
get
;
set
;
}
public
IServiceProvider
ServiceProvider
{
get
;
set
;
}
}
}
...
@@ -22,6 +21,7 @@ namespace IoTSharp.TaskAction
...
@@ -22,6 +21,7 @@ namespace IoTSharp.TaskAction
public
Guid
DeviceId
{
get
;
set
;
}
public
Guid
DeviceId
{
get
;
set
;
}
public
bool
ExecutionStatus
{
get
;
set
;
}
public
bool
ExecutionStatus
{
get
;
set
;
}
public
string
ExecutionInfo
{
get
;
set
;
}
public
string
ExecutionInfo
{
get
;
set
;
}
public
dynamic
DynamicOutput
public
dynamic
DynamicOutput
{
{
get
get
...
@@ -54,8 +54,9 @@ namespace IoTSharp.TaskAction
...
@@ -54,8 +54,9 @@ namespace IoTSharp.TaskAction
private
dynamic
_DynamicOutput
;
private
dynamic
_DynamicOutput
;
private
string
_value
;
private
string
_value
;
private
readonly
ExpandoObjectConverter
expConverter
=
new
();
private
readonly
ExpandoObjectConverter
expConverter
=
new
();
public
Guid
DeviceId
{
get
;
set
;
}
public
Guid
DeviceId
{
get
;
set
;
}
public
String
ExecutorConfig
{
get
;
set
;
}
public
String
ExecutorConfig
{
get
;
set
;
}
public
dynamic
DynamicInput
public
dynamic
DynamicInput
{
{
get
get
...
...
IoTSharp.TaskAction/MessagePullExcutor.cs
浏览文件 @
59818722
using
System
;
using
Newtonsoft.Json
;
using
System.Collections.Generic
;
using
Newtonsoft.Json.Linq
;
using
RestSharp
;
using
System
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Dynamic
;
using
System.Linq
;
using
System.Linq
;
using
System.Net
;
using
System.Net
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Castle.Components.DictionaryAdapter
;
using
IoTSharp.Data
;
using
IoTSharp.TaskAction
;
using
Microsoft.Extensions.Caching.Memory
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
RestSharp
;
namespace
IoTSharp.TaskAction
namespace
IoTSharp.TaskAction
{
{
[
DisplayName
(
"用于消息推送的执行器"
)]
[
DisplayName
(
"用于消息推送的执行器"
)]
public
class
MessagePullExecutor
:
ITaskAction
public
class
MessagePullExecutor
:
ITaskAction
{
{
public
MessagePullExecutor
()
{
}
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
{
{
try
try
{
{
// var cache = this.ServiceProvider.GetService(typeof(IMemoryCache)) as IMemoryCache;
return
SendData
(
input
);
return
SendData
(
input
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
});
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
});
}
}
}
}
private
async
Task
<
TaskActionOutput
>
SendData
(
TaskActionInput
input
)
private
void
Login
(
ModelExecutorConfig
config
)
{
}
private
async
Task
<
TaskActionOutput
>
SendData
(
TaskActionInput
input
)
{
{
try
try
{
{
if
(
input
.
Input
.
Contains
(
"ValueKind"
))
if
(
input
.
Input
.
Contains
(
"ValueKind"
))
{
{
JObject
o
=
JsonConvert
.
DeserializeObject
(
input
.
Input
)
as
JObject
;
JObject
o
=
JsonConvert
.
DeserializeObject
(
input
.
Input
)
as
JObject
;
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
var
dd
=
o
.
Properties
().
Select
(
c
=>
new
ParamObject
{
keyName
=
c
.
Name
,
value
=
JPropertyToObject
(
c
.
Value
.
First
as
JProperty
)
}).
ToList
();
var
dd
=
o
.
Properties
().
Select
(
c
=>
new
ParamObject
{
keyName
=
c
.
Name
,
value
=
JPropertyToObject
(
c
.
Value
.
First
as
JProperty
)
}).
ToList
();
...
@@ -75,7 +46,7 @@ namespace IoTSharp.TaskAction
...
@@ -75,7 +46,7 @@ namespace IoTSharp.TaskAction
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
{
var
result
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Content
);
var
result
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Content
);
if
(
result
is
{
success
:
true
})
if
(
result
is
{
success
:
true
})
{
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
}
}
...
@@ -88,9 +59,6 @@ namespace IoTSharp.TaskAction
...
@@ -88,9 +59,6 @@ namespace IoTSharp.TaskAction
{
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
ErrorMessage
,
ExecutionStatus
=
false
};
;
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
ErrorMessage
,
ExecutionStatus
=
false
};
;
}
}
}
}
else
else
{
{
...
@@ -106,12 +74,12 @@ namespace IoTSharp.TaskAction
...
@@ -106,12 +74,12 @@ namespace IoTSharp.TaskAction
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddHeader
(
"Content-Type"
,
"application/json"
);
request
.
AddHeader
(
"Content-Type"
,
"application/json"
);
request
.
AddJsonBody
(
dd
);
request
.
AddJsonBody
(
dd
);
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
{
var
result
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Content
);
var
result
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Content
);
if
(
result
is
{
success
:
true
})
if
(
result
is
{
success
:
true
})
{
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
result
.
success
,
DynamicOutput
=
input
.
DynamicInput
};
;
}
}
...
@@ -122,14 +90,9 @@ namespace IoTSharp.TaskAction
...
@@ -122,14 +90,9 @@ namespace IoTSharp.TaskAction
}
}
else
else
{
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
;
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
;
}
}
}
}
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
...
@@ -137,7 +100,6 @@ namespace IoTSharp.TaskAction
...
@@ -137,7 +100,6 @@ namespace IoTSharp.TaskAction
}
}
}
}
public
static
object
JPropertyToObject
(
JProperty
property
)
public
static
object
JPropertyToObject
(
JProperty
property
)
{
{
object
obj
=
null
;
object
obj
=
null
;
...
@@ -146,30 +108,39 @@ namespace IoTSharp.TaskAction
...
@@ -146,30 +108,39 @@ namespace IoTSharp.TaskAction
case
JTokenType
.
Integer
:
case
JTokenType
.
Integer
:
obj
=
property
.
Value
.
ToObject
<
int
>();
obj
=
property
.
Value
.
ToObject
<
int
>();
break
;
break
;
case
JTokenType
.
Float
:
case
JTokenType
.
Float
:
obj
=
property
.
Value
.
ToObject
<
float
>();
obj
=
property
.
Value
.
ToObject
<
float
>();
break
;
break
;
case
JTokenType
.
String
:
case
JTokenType
.
String
:
obj
=
property
.
Value
.
ToObject
<
string
>();
obj
=
property
.
Value
.
ToObject
<
string
>();
break
;
break
;
case
JTokenType
.
Boolean
:
case
JTokenType
.
Boolean
:
obj
=
property
.
Value
.
ToObject
<
bool
>();
obj
=
property
.
Value
.
ToObject
<
bool
>();
break
;
break
;
case
JTokenType
.
Date
:
case
JTokenType
.
Date
:
obj
=
property
.
Value
.
ToObject
<
DateTime
>();
obj
=
property
.
Value
.
ToObject
<
DateTime
>();
break
;
break
;
case
JTokenType
.
Bytes
:
case
JTokenType
.
Bytes
:
obj
=
property
.
Value
.
ToObject
<
byte
[
]>
();
obj
=
property
.
Value
.
ToObject
<
byte
[
]>
();
break
;
break
;
case
JTokenType
.
Guid
:
case
JTokenType
.
Guid
:
obj
=
property
.
Value
.
ToObject
<
Guid
>();
obj
=
property
.
Value
.
ToObject
<
Guid
>();
break
;
break
;
case
JTokenType
.
Uri
:
case
JTokenType
.
Uri
:
obj
=
property
.
Value
.
ToObject
<
Uri
>();
obj
=
property
.
Value
.
ToObject
<
Uri
>();
break
;
break
;
case
JTokenType
.
TimeSpan
:
case
JTokenType
.
TimeSpan
:
obj
=
property
.
Value
.
ToObject
<
TimeSpan
>();
obj
=
property
.
Value
.
ToObject
<
TimeSpan
>();
break
;
break
;
default
:
default
:
obj
=
property
.
Value
;
obj
=
property
.
Value
;
break
;
break
;
...
@@ -177,28 +148,8 @@ namespace IoTSharp.TaskAction
...
@@ -177,28 +148,8 @@ namespace IoTSharp.TaskAction
return
obj
;
return
obj
;
}
}
class
MessagePullParam
private
class
MessagePullResult
{
{
public
double
param1
{
get
;
set
;
}
public
double
param2
{
get
;
set
;
}
public
double
param3
{
get
;
set
;
}
public
int
param4
{
get
;
set
;
}
public
long
param5
{
get
;
set
;
}
public
ParamObject
param6
{
get
;
set
;
}
public
string
param9
{
get
;
set
;
}
}
class
MessagePullResult
{
public
bool
success
{
get
;
set
;
}
public
bool
success
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
...
@@ -206,25 +157,15 @@ namespace IoTSharp.TaskAction
...
@@ -206,25 +157,15 @@ namespace IoTSharp.TaskAction
public
long
timestamp
{
get
;
set
;
}
public
long
timestamp
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
}
public
class
LoginParam
{
}
}
public
class
ParamObject
public
class
ParamObject
{
{
public
string
keyName
{
get
;
set
;
}
public
string
keyName
{
get
;
set
;
}
public
dynamic
value
{
get
;
set
;
}
public
dynamic
value
{
get
;
set
;
}
}
}
class
ModelExecutorConfig
private
class
ModelExecutorConfig
{
{
public
string
Url
{
get
;
set
;
}
public
string
Url
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
...
@@ -232,7 +173,6 @@ namespace IoTSharp.TaskAction
...
@@ -232,7 +173,6 @@ namespace IoTSharp.TaskAction
public
string
Password
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
public
string
Token
{
get
;
set
;
}
}
}
}
}
}
}
\ No newline at end of file
IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs
浏览文件 @
59818722
using
System
;
using
Newtonsoft.Json
;
using
System.Collections.Generic
;
using
RestSharp
;
using
System
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Linq
;
using
System.Net
;
using
System.Net
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
RestSharp
;
namespace
IoTSharp.TaskAction
namespace
IoTSharp.TaskAction
{
{
[
DisplayName
(
"用于遥测数组推送的执行器"
)]
[
DisplayName
(
"用于遥测数组推送的执行器"
)]
public
class
TelemetryArrayPullExcutor
:
ITaskAction
public
class
TelemetryArrayPullExcutor
:
ITaskAction
{
{
public
TelemetryArrayPullExcutor
()
public
TelemetryArrayPullExcutor
()
{
{
}
}
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
public
override
Task
<
TaskActionOutput
>
ExecuteAsync
(
TaskActionInput
input
)
{
{
try
try
{
{
// var cache = this.ServiceProvider.GetService(typeof(IMemoryCache)) as IMemoryCache;
return
SendData
(
input
);
return
SendData
(
input
);
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
});
return
Task
.
FromResult
(
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
});
}
}
}
}
private
void
Login
(
ModelExecutorConfig
config
)
{
}
private
async
Task
<
TaskActionOutput
>
SendData
(
TaskActionInput
input
)
private
async
Task
<
TaskActionOutput
>
SendData
(
TaskActionInput
input
)
{
{
try
try
{
{
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
var
restclient
=
new
RestClient
(
config
.
BaseUrl
);
var
config
=
JsonConvert
.
DeserializeObject
<
ModelExecutorConfig
>(
input
.
ExecutorConfig
);
restclient
.
AddDefaultHeader
(
KnownHeaders
.
Accept
,
"*/*"
);
var
request
=
var
restclient
=
new
RestClient
(
config
.
BaseUrl
);
new
RestRequest
(
config
.
Url
+
(
input
.
DeviceId
==
Guid
.
Empty
?
""
:
"/"
+
input
.
DeviceId
)
);
restclient
.
AddDefaultHeader
(
KnownHeaders
.
Accept
,
"*/*"
);
request
.
AddHeader
(
"X-Access-Token"
,
var
request
=
config
.
Token
);
new
RestRequest
(
config
.
Url
+
(
input
.
DeviceId
==
Guid
.
Empty
?
""
:
"/"
+
input
.
DeviceId
))
;
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
AddHeader
(
"X-Access-Token"
,
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
config
.
Token
);
request
.
AddHeader
(
"Content-Type"
,
"application/json"
);
request
.
RequestFormat
=
DataFormat
.
Json
;
request
.
AddJsonBody
(
JsonConvert
.
DeserializeObject
(
input
.
Input
))
;
request
.
AddHeader
(
"cache-control"
,
"no-cache"
);
request
.
AddHeader
(
"Content-Type"
,
"application/json"
);
var
response
=
await
restclient
.
ExecutePostAsync
(
request
);
request
.
AddJsonBody
(
JsonConvert
.
DeserializeObject
(
input
.
Input
));
if
(
response
.
StatusCode
==
HttpStatusCode
.
OK
)
{
var
res
ponse
=
await
restclient
.
ExecutePostAsync
(
reques
t
);
var
res
ult
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Conten
t
);
if
(
res
ponse
.
StatusCode
==
HttpStatusCode
.
OK
)
if
(
res
ult
is
{
success
:
true
}
)
{
{
var
result
=
JsonConvert
.
DeserializeObject
<
MessagePullResult
>(
response
.
Content
);
return
new
TaskActionOutput
()
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
};
ExecutionInfo
=
response
.
Content
,
;
ExecutionStatus
=
result
.
success
,
}
DynamicOutput
=
input
.
DynamicInput
};
;
}
}
else
else
{
{
return
new
TaskActionOutput
()
return
new
TaskActionOutput
()
{
ExecutionInfo
=
response
.
Content
,
ExecutionStatus
=
false
};
{
;
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
}
}
}
else
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
$"StatusCode:
{
response
.
StatusCode
}
StatusDescription:
{
response
.
StatusDescription
}
{
response
.
ErrorMessage
}
"
,
ExecutionStatus
=
false
};
}
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
return
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
};
return
new
TaskActionOutput
()
{
ExecutionInfo
=
ex
.
Message
,
ExecutionStatus
=
false
};
;
;
}
}
}
}
public
static
object
JPropertyToObject
(
JProperty
property
)
private
class
MessagePullResult
{
{
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
;
}
class
MessagePullResult
{
public
bool
success
{
get
;
set
;
}
public
bool
success
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
message
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
public
string
code
{
get
;
set
;
}
...
@@ -167,25 +89,9 @@ namespace IoTSharp.TaskAction
...
@@ -167,25 +89,9 @@ namespace IoTSharp.TaskAction
public
long
timestamp
{
get
;
set
;
}
public
long
timestamp
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
public
dynamic
result
{
get
;
set
;
}
}
public
class
LoginParam
{
}
}
public
class
ParamObject
private
class
ModelExecutorConfig
{
public
string
keyName
{
get
;
set
;
}
public
dynamic
value
{
get
;
set
;
}
}
class
ModelExecutorConfig
{
{
public
string
Url
{
get
;
set
;
}
public
string
Url
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
public
string
BaseUrl
{
get
;
set
;
}
...
@@ -193,7 +99,6 @@ namespace IoTSharp.TaskAction
...
@@ -193,7 +99,6 @@ namespace IoTSharp.TaskAction
public
string
Password
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
UserName
{
get
;
set
;
}
public
string
Token
{
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录