1.0 beta.101

TangShanKaiPing
wanggang 6 years ago
parent c24fc1c457
commit 9ff44216e4

@ -27,6 +27,7 @@ namespace Application.Services
private readonly IConfiguration _cfg; private readonly IConfiguration _cfg;
private CancellationTokenSource _tokenSource; private CancellationTokenSource _tokenSource;
public HubConnection Connection; public HubConnection Connection;
private string _notifyHost;
public NodeService(IServiceProvider applicationServices, IConfiguration configuration) public NodeService(IServiceProvider applicationServices, IConfiguration configuration)
{ {
@ -533,7 +534,7 @@ namespace Application.Services
while (!_tokenSource.IsCancellationRequested) while (!_tokenSource.IsCancellationRequested)
{ {
this.Connect(); this.Connect();
await Task.Delay(60 * 1000); await Task.Delay(this._cfg.GetValue<int>("timer.seconds", 60) * 1000);
} }
}); });
} }
@ -552,12 +553,19 @@ namespace Application.Services
if (Connection.State == HubConnectionState.Disconnected) if (Connection.State == HubConnectionState.Disconnected)
{ {
Console.WriteLine("start connect"); Console.WriteLine("start connect");
Connection.StartAsync(); Connection.StartAsync().Wait();
this.Notify(); this.Notify();
} }
else else
{ {
Console.WriteLine($"connection is connected"); if (this._notifyHost != this._cfg["notify:host"])
{
this.ReConnect(null);
}
else
{
Console.WriteLine($"connection is connected");
}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -589,12 +597,13 @@ namespace Application.Services
private void InitConnection() private void InitConnection()
{ {
this._notifyHost = this._cfg["notify:host"];
var url = ""; var url = "";
using (var scope = applicationServices.CreateScope()) using (var scope = applicationServices.CreateScope())
{ {
var repo = scope.ServiceProvider.GetService<IRepository<Node>>(); var repo = scope.ServiceProvider.GetService<IRepository<Node>>();
var nodeNumber = repo.ReadOnlyTable().FirstOrDefault().Number; var nodeNumber = repo.ReadOnlyTable().FirstOrDefault().Number;
url = $"http://{this._cfg["notify:host"]}/hub?group={nodeNumber}"; url = $"http://{this._notifyHost}/hub?group={nodeNumber}";
} }
this.Connection = new HubConnectionBuilder().WithUrl(url).Build(); this.Connection = new HubConnectionBuilder().WithUrl(url).Build();
this.Connection.Closed += ReConnect; this.Connection.Closed += ReConnect;

@ -24,6 +24,7 @@ namespace IoTNode
new EFConfigurationValue { Id = "email:password", Value= "aA123456"}, new EFConfigurationValue { Id = "email:password", Value= "aA123456"},
new EFConfigurationValue { Id = "notify:enabled", Value= "true"}, new EFConfigurationValue { Id = "notify:enabled", Value= "true"},
new EFConfigurationValue { Id = "notify:host", Value= "127.0.0.1:8001"}, new EFConfigurationValue { Id = "notify:host", Value= "127.0.0.1:8001"},
new EFConfigurationValue { Id = "timer.seconds", Value="10"},
new EFConfigurationValue { Id = "influxdb:url", Value= "http://localhost:8086"}, new EFConfigurationValue { Id = "influxdb:url", Value= "http://localhost:8086"},
new EFConfigurationValue { Id = "influxdb:usr", Value= "admin"}, new EFConfigurationValue { Id = "influxdb:usr", Value= "admin"},
new EFConfigurationValue { Id = "influxdb:pwd", Value= "admin"}, new EFConfigurationValue { Id = "influxdb:pwd", Value= "admin"},

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Warning"

@ -21,6 +21,11 @@ namespace APService.Controllers
} }
public IActionResult Index(string command) public IActionResult Index(string command)
{
return View();
}
public IActionResult Test(string command)
{ {
var result = string.IsNullOrEmpty(command) ? "" : this._apService.RunCommand(command); var result = string.IsNullOrEmpty(command) ? "" : this._apService.RunCommand(command);
ViewBag.Result = result; ViewBag.Result = result;

@ -23,10 +23,6 @@ namespace APService
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly IHttpClientFactory _httpClientFactory; private readonly IHttpClientFactory _httpClientFactory;
private CancellationTokenSource _tokenSource; private CancellationTokenSource _tokenSource;
private readonly string _ip;
private readonly int _port;
private readonly string _usr;
private readonly string _pwd;
private static readonly object thisLock = new object(); private static readonly object thisLock = new object();
public ApService(IHostingEnvironment env, IConfiguration configuration, IHttpClientFactory httpClientFactory) public ApService(IHostingEnvironment env, IConfiguration configuration, IHttpClientFactory httpClientFactory)
@ -34,10 +30,6 @@ namespace APService
this._env = env; this._env = env;
this._configuration = configuration; this._configuration = configuration;
this._httpClientFactory = httpClientFactory; this._httpClientFactory = httpClientFactory;
this._ip = this._configuration["ap.ip"];
this._port = this._configuration.GetValue<int>("ap.port");
this._usr = this._configuration["ap.usr"];
this._pwd = this._configuration["ap.pwd"];
} }
public void Start() public void Start()
@ -183,7 +175,11 @@ namespace APService
{ {
lock (thisLock) lock (thisLock)
{ {
using (var client = new SshClient(this._ip, this._port, this._usr, this._pwd)) var ip = this._configuration["ap.ip"];
var port = this._configuration.GetValue<int>("ap.port");
var usr = this._configuration["ap.usr"];
var pwd = this._configuration["ap.pwd"];
using (var client = new SshClient(ip, port, usr, pwd))
{ {
client.Connect(); client.Connect();
using (var stream = client.CreateShellStream("AP", 80, 24, 800, 600, 1024)) using (var stream = client.CreateShellStream("AP", 80, 24, 800, 600, 1024))
@ -197,12 +193,12 @@ namespace APService
reader.ReadToEnd(); reader.ReadToEnd();
//usr //usr
writer.WriteLine(this._usr); writer.WriteLine(usr);
this.Sleep(); this.Sleep();
reader.ReadToEnd(); reader.ReadToEnd();
//pwd //pwd
writer.WriteLine(this._pwd); writer.WriteLine(pwd);
this.Sleep(); this.Sleep();
reader.ReadToEnd(); reader.ReadToEnd();

@ -24,7 +24,7 @@ namespace APService
new EFConfigurationValue { Id = "email:user", Value= "admin@nbaxp.com"}, new EFConfigurationValue { Id = "email:user", Value= "admin@nbaxp.com"},
new EFConfigurationValue { Id = "email:password", Value= "aA123456"}, new EFConfigurationValue { Id = "email:password", Value= "aA123456"},
new EFConfigurationValue { Id = "node.url", Value= "127.0.0.1:8002"}, new EFConfigurationValue { Id = "node.url", Value= "127.0.0.1:8002"},
new EFConfigurationValue { Id = "ap.ip", Value= "192.254.1.1"}, new EFConfigurationValue { Id = "ap.ip", Value= "192.168.3.1"},
new EFConfigurationValue { Id = "ap.port", Value= "22"}, new EFConfigurationValue { Id = "ap.port", Value= "22"},
new EFConfigurationValue { Id = "ap.usr", Value= "super"}, new EFConfigurationValue { Id = "ap.usr", Value= "super"},
new EFConfigurationValue { Id = "ap.pwd", Value= "sp-admin"}, new EFConfigurationValue { Id = "ap.pwd", Value= "sp-admin"},

@ -1,22 +0,0 @@
@model Infrastructure.Models.NotifyModel
<table class="table">
<tr>
<td>设备名称:</td>
<td>@Model.Name</td>
</tr>
<tr>
<td>设备编号:</td>
<td>@Model.Number</td>
</tr>
<tr>
<td>设备数据:</td>
<td>
<table>
@foreach (var item in Model.Data)
{
<tr><td>@item.Name</td><td>@item.Value</td><td>@item.Unit</td><td>@item.Description</td></tr>
}
</table>
</td>
</tr>
</table>

@ -0,0 +1,22 @@
@model Infrastructure.Models.NotifyModel
<table class="table">
<tr>
<td>设备名称:</td>
<td>@Model.Name</td>
</tr>
<tr>
<td>设备编号:</td>
<td>@Model.Number</td>
</tr>
<tr>
<td>设备数据:</td>
<td>
<table>
@foreach (var item in Model.Data)
{
<tr><td>@item.Name</td><td>@item.Value</td><td>@item.Unit</td><td>@item.Description</td></tr>
}
</table>
</td>
</tr>
</table>

@ -4,6 +4,11 @@
首页 首页
</a> </a>
</li> </li>
<li>
<a href="@Url.Action("Test","Home")">
测试
</a>
</li>
<li> <li>
<a href="/swagger/index.html"> <a href="/swagger/index.html">
Open API Open API

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Warning"

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information" "Default": "Information"

@ -1,4 +1,4 @@
version=1.0.0-beta.100 version=1.0.0-beta.101
server.host=127.0.0.1 server.host=127.0.0.1
server.port=8003 server.port=8003
spring.thymeleaf.cache=false spring.thymeleaf.cache=false

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information" "Default": "Information"

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information" "Default": "Information"

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Warning"

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Warning"

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Warning"

@ -1,5 +1,5 @@
{ {
"version": "1.0.0-beta.100", "version": "1.0.0-beta.101",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Warning"
@ -16,7 +16,7 @@
}, },
//Ocelot config //Ocelot config
"GlobalConfiguration": { "GlobalConfiguration": {
"BaseUrl": "http://192.168.3.124:8000/" "BaseUrl": "http://192.168.3.83:8000/"
}, },
"ReRoutes": [ "ReRoutes": [
{ {
@ -24,7 +24,7 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "192.168.3.124", "Host": "192.168.3.83",
"Port": 8001 "Port": 8001
} }
], ],

Loading…
Cancel
Save