Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
5d1c52da
IoTSharp
项目概览
IoTSharp
/
IoTSharp
9 个月 前同步成功
通知
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 搜索 >>
提交
5d1c52da
编写于
6月 24, 2019
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
第一步整合
上级
0c180ae9
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
67 addition
and
59 deletion
+67
-59
IoTSharp/Contracts/IService.cs
IoTSharp/Contracts/IService.cs
+0
-12
IoTSharp/Controllers/MqttController.cs
IoTSharp/Controllers/MqttController.cs
+2
-2
IoTSharp/Diagnostics/DiagnosticsService.cs
IoTSharp/Diagnostics/DiagnosticsService.cs
+16
-7
IoTSharp/Diagnostics/Log/LogService.cs
IoTSharp/Diagnostics/Log/LogService.cs
+16
-6
IoTSharp/Diagnostics/SystemStatusService.cs
IoTSharp/Diagnostics/SystemStatusService.cs
+7
-6
IoTSharp/Handlers/MQTTService.cs
IoTSharp/Handlers/MQTTService.cs
+0
-0
IoTSharp/Services/MQTT/MqttService.cs
IoTSharp/Services/MQTT/MqttService.cs
+11
-6
IoTSharp/Startup.cs
IoTSharp/Startup.cs
+10
-11
IoTSharp/Storage/JsonSerializerService.cs
IoTSharp/Storage/JsonSerializerService.cs
+2
-5
IoTSharp/Storage/StorageService.cs
IoTSharp/Storage/StorageService.cs
+1
-2
IoTSharp/Sys/SystemService.cs
IoTSharp/Sys/SystemService.cs
+2
-2
未找到文件。
IoTSharp/Contracts/IService.cs
已删除
100644 → 0
浏览文件 @
0c180ae9
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Contracts
{
public
interface
IService
{
void
Start
();
}
}
IoTSharp/Controllers/MqttController.cs
浏览文件 @
5d1c52da
...
...
@@ -18,9 +18,9 @@ namespace IoTSharp.Controllers
{
private
readonly
MqttService
_mqttService
;
public
MqttController
()
public
MqttController
(
MqttService
mqttService
)
{
_mqttService
=
MqttExtension
.
mqttServer
;
_mqttService
=
mqttService
;
}
[
HttpPost
]
[
Route
(
"/api/v1/mqtt/publish"
)]
...
...
IoTSharp/Diagnostics/DiagnosticsService.cs
浏览文件 @
5d1c52da
...
...
@@ -3,29 +3,28 @@ using System.Collections.Concurrent;
using
System.Collections.Generic
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
IoTSharp.Contracts
;
using
IoTSharp.Sys
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
namespace
IoTSharp.Diagnostics
{
public
class
DiagnosticsService
:
IService
public
class
DiagnosticsService
:
I
Hosted
Service
{
private
readonly
List
<
OperationsPerSecondCounter
>
_operationsPerSecondCounters
=
new
List
<
OperationsPerSecondCounter
>();
private
readonly
SystemCancellationToken
_systemCancellationToken
;
private
readonly
ILogger
_logger
;
public
DiagnosticsService
(
SystemCancellationToken
systemCancellationToken
,
ILogger
<
DiagnosticsService
>
logger
)
public
DiagnosticsService
(
ILogger
<
DiagnosticsService
>
logger
)
{
_systemCancellationToken
=
systemCancellationToken
??
throw
new
ArgumentNullException
(
nameof
(
systemCancellationToken
));
_logger
=
logger
??
throw
new
ArgumentNullException
(
nameof
(
logger
));
}
public
void
Start
(
)
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
Task
.
Run
(()
=>
ResetOperationsPerSecondCountersAsync
(
_systemCancellationToken
.
Token
),
_systemCancellationToken
.
Token
).
ConfigureAwait
(
false
);
return
ResetOperationsPerSecondCountersAsync
(
cancellationToken
);
}
public
OperationsPerSecondCounter
CreateOperationsPerSecondCounter
(
string
uid
)
{
...
...
@@ -66,5 +65,15 @@ namespace IoTSharp.Diagnostics
}
}
}
public
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
_logger
.
LogInformation
(
"DiagnosticsService stop !"
);
return
Task
.
CompletedTask
;
}
}
}
IoTSharp/Diagnostics/Log/LogService.cs
浏览文件 @
5d1c52da
using
System
;
using
System.Collections.Generic
;
using
IoTSharp.Contracts
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
IoTSharp.Storage
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
namespace
IoTSharp.Diagnostics.Log
{
public
class
LogService
:
IService
public
class
LogService
:
I
Hosted
Service
{
private
readonly
LinkedList
<
LogEntry
>
_logEntries
=
new
LinkedList
<
LogEntry
>();
private
readonly
SystemStatusService
_systemStatusService
;
...
...
@@ -27,10 +29,8 @@ namespace IoTSharp.Diagnostics.Log
}
}
public
void
Start
()
{
}
public
void
Publish
(
DateTime
timestamp
,
LogLevel
logLevel
,
string
source
,
string
message
,
Exception
exception
)
{
var
newLogEntry
=
new
LogEntry
(
timestamp
,
logLevel
,
source
,
message
,
exception
?.
ToString
());
...
...
@@ -133,5 +133,15 @@ namespace IoTSharp.Diagnostics.Log
_systemStatusService
.
Set
(
"log.warnings_count"
,
_warningsCount
);
_systemStatusService
.
Set
(
"log.errors_count"
,
_errorsCount
);
}
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
return
Task
.
CompletedTask
;
}
public
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
return
Task
.
CompletedTask
;
}
}
}
IoTSharp/Diagnostics/SystemStatusService.cs
浏览文件 @
5d1c52da
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
IoTSharp.Contracts
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
namespace
IoTSharp.Diagnostics
{
public
class
SystemStatusService
:
IService
public
class
SystemStatusService
{
private
readonly
ConcurrentDictionary
<
string
,
Func
<
object
>>
_values
=
new
ConcurrentDictionary
<
string
,
Func
<
object
>>();
...
...
@@ -17,10 +19,7 @@ namespace IoTSharp.Diagnostics
_logger
=
logger
??
throw
new
ArgumentNullException
(
nameof
(
logger
));
}
public
void
Start
()
{
}
public
void
Set
(
string
uid
,
object
value
)
{
if
(
uid
==
null
)
throw
new
ArgumentNullException
(
nameof
(
uid
));
...
...
@@ -83,5 +82,7 @@ namespace IoTSharp.Diagnostics
return
result
;
}
}
}
IoTSharp/Handlers/M
qttEventsHandler
.cs
→
IoTSharp/Handlers/M
QTTService
.cs
浏览文件 @
5d1c52da
文件已移动
IoTSharp/Services/MQTT/MqttService.cs
浏览文件 @
5d1c52da
...
...
@@ -5,10 +5,10 @@ using System.Linq;
using
System.Runtime.InteropServices.ComTypes
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
IoTSharp.Contracts
;
using
IoTSharp.Diagnostics
;
using
IoTSharp.Storage
;
using
IoTSharp.Sys
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
using
MQTTnet
;
using
MQTTnet.Client.Receiving
;
...
...
@@ -17,7 +17,7 @@ using MQTTnet.Server.Status;
namespace
IoTSharp.MQTT
{
public
class
MqttService
:
IService
public
class
MqttService
:
I
Hosted
Service
{
private
readonly
BlockingCollection
<
MqttApplicationMessageReceivedEventArgs
>
_incomingMessages
=
new
BlockingCollection
<
MqttApplicationMessageReceivedEventArgs
>();
private
readonly
Dictionary
<
string
,
MqttTopicImporter
>
_importers
=
new
Dictionary
<
string
,
MqttTopicImporter
>();
...
...
@@ -56,7 +56,7 @@ namespace IoTSharp.MQTT
systemStatusService
.
Set
(
"mqtt.connected_clients_count"
,
()
=>
_mqttServer
.
GetClientStatusAsync
().
GetAwaiter
().
GetResult
().
Count
);
}
public
void
Start
(
)
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
_storageService
.
TryReadOrCreate
(
out
MqttServiceOptions
options
,
MqttServiceOptions
.
Filename
);
...
...
@@ -85,9 +85,7 @@ namespace IoTSharp.MQTT
serverOptions
.
WithStorage
(
storage
);
}
_mqttServer
.
StartAsync
(
serverOptions
.
Build
()).
GetAwaiter
().
GetResult
();
Task
.
Factory
.
StartNew
(()
=>
ProcessIncomingMqttMessages
(
_systemCancellationToken
.
Token
),
_systemCancellationToken
.
Token
,
TaskCreationOptions
.
LongRunning
,
TaskScheduler
.
Default
);
return
_mqttServer
.
StartAsync
(
serverOptions
.
Build
()).
ContinueWith
(
a
=>
ProcessIncomingMqttMessages
(
cancellationToken
));
}
public
List
<
string
>
GetTopicImportUids
()
...
...
@@ -281,5 +279,12 @@ namespace IoTSharp.MQTT
_inboundCounter
.
Increment
();
_incomingMessages
.
Add
(
eventArgs
);
}
public
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
return
Task
.
CompletedTask
;
}
}
}
IoTSharp/Startup.cs
浏览文件 @
5d1c52da
using
IoTSharp.Contracts
;
using
IoTSharp.Data
;
using
IoTSharp.Data
;
using
IoTSharp.Extensions
;
using
IoTSharp.MQTT
;
using
IoTSharp.Services
;
...
...
@@ -92,14 +91,14 @@ namespace IoTSharp
});
services
.
AddTransient
<
ApplicationDBInitializer
>();
//
services.AddIoTSharpMqttServer(AppSettings.MqttBroker);
//
services.AddMqttClient(AppSettings.MqttClient);
//
services.AddHostedService<CoAPService>();
services
.
AddTransient
<
IoTSharp
.
Sys
.
SystemCancellationToken
>();
foreach
(
var
singletonService
in
Reflection
.
GetClassesImplementingInterface
<
IService
>())
{
services
.
AddSingleton
(
singletonService
);
}
services
.
AddIoTSharpMqttServer
(
AppSettings
.
MqttBroker
);
services
.
AddMqttClient
(
AppSettings
.
MqttClient
);
services
.
AddHostedService
<
CoAPService
>();
//
services.AddTransient<IoTSharp.Sys.SystemCancellationToken>();
//
foreach (var singletonService in Reflection.GetClassesImplementingInterface<IService>())
//
{
//
services.AddSingleton(singletonService);
//
}
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...
...
@@ -121,7 +120,7 @@ namespace IoTSharp
app
.
UseSwagger
();
app
.
UseHttpsRedirection
();
//app.UseIotSharpMqttServer();
serviceProvider
.
GetRequiredService
<
MqttService
>().
Start
();
//
serviceProvider.GetRequiredService<MqttService>().Start();
app
.
UseForwardedHeaders
(
new
ForwardedHeadersOptions
{
...
...
IoTSharp/Storage/JsonSerializerService.cs
浏览文件 @
5d1c52da
using
System
;
using
System.IO
;
using
System.Text
;
using
IoTSharp.Contracts
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Serialization
;
namespace
IoTSharp.Storage
{
public
class
JsonSerializerService
:
IService
public
class
JsonSerializerService
{
private
readonly
JsonSerializerSettings
_serializerSettings
=
new
JsonSerializerSettings
{
...
...
@@ -27,9 +26,7 @@ namespace IoTSharp.Storage
_serializer
=
JsonSerializer
.
Create
(
_serializerSettings
);
}
public
void
Start
()
{
}
public
string
Serialize
(
object
value
)
{
...
...
IoTSharp/Storage/StorageService.cs
浏览文件 @
5d1c52da
...
...
@@ -3,12 +3,11 @@ using System.Collections.Generic;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
IoTSharp.Contracts
;
using
Microsoft.Extensions.Logging
;
namespace
IoTSharp.Storage
{
public
class
StorageService
:
IService
public
class
StorageService
{
private
readonly
JsonSerializerService
_jsonSerializerService
;
...
...
IoTSharp/Sys/SystemService.cs
浏览文件 @
5d1c52da
...
...
@@ -3,13 +3,13 @@ using System.Diagnostics;
using
System.Runtime.InteropServices
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
IoTSharp.Contracts
;
using
IoTSharp.Diagnostics
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Logging
;
namespace
IoTSharp.Sys
{
public
class
SystemService
:
IService
public
class
SystemService
{
private
readonly
SystemStatusService
_systemStatusService
;
private
readonly
SystemLaunchArguments
_systemLaunchArguments
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录