1.0.0.507-1

Former-commit-id: 8be8acfcc11b8e6a7540164bcf28c7a2a8efcdfb
TangShanKaiPing
wanggang 5 years ago
parent 035f1143e9
commit 3862807320

@ -5,6 +5,9 @@
public const string ServerToClient = nameof(ServerToClient); public const string ServerToClient = nameof(ServerToClient);
public const string ClientToServer = nameof(ClientToServer); public const string ClientToServer = nameof(ClientToServer);
public const string UploadNode = nameof(UploadNode);
public const string StopNode = nameof(StopNode);
public const string ExecApiRequest = nameof(ExecApiRequest); public const string ExecApiRequest = nameof(ExecApiRequest);
public const string ExecApiResponse = nameof(ExecApiResponse); public const string ExecApiResponse = nameof(ExecApiResponse);
public const string ExecSceneRequest = nameof(ExecSceneRequest); public const string ExecSceneRequest = nameof(ExecSceneRequest);

@ -28,11 +28,13 @@ namespace IoT.Shared.Services
private bool disposed = false; private bool disposed = false;
private string _notifyHost; private string _notifyHost;
private HubConnection Connection; private HubConnection Connection;
private readonly IHostApplicationLifetime _lifetime;
private readonly IServiceProvider _applicationServices; private readonly IServiceProvider _applicationServices;
private readonly ILogger<IoTNodeClient> _logger; private readonly ILogger<IoTNodeClient> _logger;
public IoTNodeClient(IServiceProvider applicationServices, ILogger<IoTNodeClient> logger) public IoTNodeClient(IHostApplicationLifetime lifetime, IServiceProvider applicationServices, ILogger<IoTNodeClient> logger)
{ {
this._lifetime = lifetime;
this._applicationServices = applicationServices; this._applicationServices = applicationServices;
this._logger = logger; this._logger = logger;
} }
@ -132,7 +134,7 @@ namespace IoT.Shared.Services
private void InitConnection() private void InitConnection()
{ {
this._notifyHost = GetSetting("notify:host"); this._notifyHost = GetSetting("notify:host");
var organ= GetSetting("organ"); var organ = GetSetting("organ");
var url = $"{this._notifyHost}/hub?type=node&organ={organ}&group={GetSetting("sn")}"; var url = $"{this._notifyHost}/hub?type=node&organ={organ}&group={GetSetting("sn")}";
this._logger.LogDebug($"init connection for {url}"); this._logger.LogDebug($"init connection for {url}");
if (this.Connection != null) if (this.Connection != null)
@ -235,7 +237,11 @@ namespace IoT.Shared.Services
var dataService = scope.ServiceProvider.GetService<DataService>(); var dataService = scope.ServiceProvider.GetService<DataService>();
var eventPublisher = scope.ServiceProvider.GetService<IEventPublisher>(); var eventPublisher = scope.ServiceProvider.GetService<IEventPublisher>();
if (method == "UpdateNode") if (method == Methods.StopNode)
{
this._lifetime.StopApplication();
}
else if (method == Methods.UploadNode)
{ {
this.OnConnected(); this.OnConnected();
} }

@ -88,6 +88,19 @@ namespace IoTCenter.Api.Controllers
return this.Power(number, "Off"); return this.Power(number, "Off");
} }
[HttpPost]
public ActionResult Upload([FromBody][Required]string number)
{
this._hub.ServerToClient(Methods.UploadNode, "", number);
return Ok();
}
public IActionResult Stop([FromBody][Required]string number)
{
this._hub.ServerToClient(Methods.StopNode, "", number);
return Ok();
}
private ActionResult Power(string number, string command) private ActionResult Power(string number, string command)
{ {
var devices = this._deviceRepo.ReadOnlyTable() var devices = this._deviceRepo.ReadOnlyTable()

@ -53,8 +53,15 @@
<a class="card-body" href="@Url.Action("Index","Device",new { nodeId=item.Id})" style="display:block;text-align:center;"> <a class="card-body" href="@Url.Action("Index","Device",new { nodeId=item.Id})" style="display:block;text-align:center;">
<img alt="@item.Name" src="@Url.Content("~"+item.Image??"/images/empty.png")" style="margin:0 auto;width:64px;" /> <img alt="@item.Name" src="@Url.Content("~"+item.Image??"/images/empty.png")" style="margin:0 auto;width:64px;" />
</a> </a>
<div class="card-footer text-center">
<button class="btn btn-success" onclick="nodeMethod('@item.Number','Upload')">上传</button>
<button class="btn btn-success" onclick="nodeMethod('@item.Number','Stop')">重启</button>
</div>
</div> </div>
</div> </div>
} }
} }
</div> </div>
@section scripts{
<script src="~/js/util.js"></script>
}

@ -102,6 +102,20 @@ function nodePower(number,command) {
loading.show(); loading.show();
}); });
} }
function nodeMethod(number,method) {
loading.show();
axios.post('/IoTCenter/api/v1/node/'+method, '"' + number + '"', { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
loading.show();
});
}
// //
function Select(e) { function Select(e) {
var checkbox = $(e.target); var checkbox = $(e.target);

@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("1.0.0.*")] [assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyInformationalVersion("1.0.0.507")] [assembly: AssemblyInformationalVersion("1.0.0.507-1")]
Loading…
Cancel
Save