diff --git a/projects/IoT.Shared/Application/Models/Methods.cs b/projects/IoT.Shared/Application/Models/Methods.cs index 927ccbad..a242cedc 100644 --- a/projects/IoT.Shared/Application/Models/Methods.cs +++ b/projects/IoT.Shared/Application/Models/Methods.cs @@ -5,6 +5,9 @@ public const string ServerToClient = nameof(ServerToClient); 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 ExecApiResponse = nameof(ExecApiResponse); public const string ExecSceneRequest = nameof(ExecSceneRequest); diff --git a/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs b/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs index f5e31f4a..1e80bf2e 100644 --- a/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs +++ b/projects/IoT.Shared/Services/IoTNode/IoTNodeClient.cs @@ -28,11 +28,13 @@ namespace IoT.Shared.Services private bool disposed = false; private string _notifyHost; private HubConnection Connection; + private readonly IHostApplicationLifetime _lifetime; private readonly IServiceProvider _applicationServices; private readonly ILogger _logger; - public IoTNodeClient(IServiceProvider applicationServices, ILogger logger) + public IoTNodeClient(IHostApplicationLifetime lifetime, IServiceProvider applicationServices, ILogger logger) { + this._lifetime = lifetime; this._applicationServices = applicationServices; this._logger = logger; } @@ -132,7 +134,7 @@ namespace IoT.Shared.Services private void InitConnection() { 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")}"; this._logger.LogDebug($"init connection for {url}"); if (this.Connection != null) @@ -235,7 +237,11 @@ namespace IoT.Shared.Services var dataService = scope.ServiceProvider.GetService(); var eventPublisher = scope.ServiceProvider.GetService(); - if (method == "UpdateNode") + if (method == Methods.StopNode) + { + this._lifetime.StopApplication(); + } + else if (method == Methods.UploadNode) { this.OnConnected(); } diff --git a/projects/IoTCenter/Api/NodeController.cs b/projects/IoTCenter/Api/NodeController.cs index c5c0b5c0..c68e0248 100644 --- a/projects/IoTCenter/Api/NodeController.cs +++ b/projects/IoTCenter/Api/NodeController.cs @@ -88,6 +88,19 @@ namespace IoTCenter.Api.Controllers 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) { var devices = this._deviceRepo.ReadOnlyTable() diff --git a/projects/IoTCenter/Areas/Admin/Views/Home/Index.cshtml b/projects/IoTCenter/Areas/Admin/Views/Home/Index.cshtml index 23c2ca61..2287e06f 100644 --- a/projects/IoTCenter/Areas/Admin/Views/Home/Index.cshtml +++ b/projects/IoTCenter/Areas/Admin/Views/Home/Index.cshtml @@ -53,8 +53,15 @@ @item.Name + } } - \ No newline at end of file + +@section scripts{ + +} \ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/js/util.js b/projects/IoTCenter/wwwroot/js/util.js index 05e3647c..2a1d3fd8 100644 --- a/projects/IoTCenter/wwwroot/js/util.js +++ b/projects/IoTCenter/wwwroot/js/util.js @@ -102,6 +102,20 @@ function nodePower(number,command) { 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) { var checkbox = $(e.target); diff --git a/projects/Version.cs b/projects/Version.cs index 1885eab2..161b7e56 100644 --- a/projects/Version.cs +++ b/projects/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.*")] -[assembly: AssemblyInformationalVersion("1.0.0.507")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.507-1")] \ No newline at end of file