From a58fa3cad009b49dc47630e7300b2723e12eedfc Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Thu, 1 Aug 2019 16:10:21 +0800 Subject: [PATCH] update Former-commit-id: dd7a36be5f765c8d3619ec1827b77ff973c84a5d --- .../Application/Domain/Entities/Device.cs | 4 ++-- .../Controllers/Onvif/OnvifController.cs | 15 ++++++++++--- .../DeviceServices/Onvif/OnvifService.cs | 21 +++++++++++++++++-- projects/IoT/IoTNode/Startup.cs | 8 +++---- .../StreamingAssets/wwwroot/index2.html | 17 +-------------- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/projects/IoT/IoT.Shared/Application/Domain/Entities/Device.cs b/projects/IoT/IoT.Shared/Application/Domain/Entities/Device.cs index 3a05fa77..a90da967 100644 --- a/projects/IoT/IoT.Shared/Application/Domain/Entities/Device.cs +++ b/projects/IoT/IoT.Shared/Application/Domain/Entities/Device.cs @@ -94,16 +94,16 @@ namespace Application.Domain.Entities public bool AddorUpdateData(string key, object value, DeviceDataType type, string name, string unit = null, string description = null, bool hidden = false) { var result = false; + var dataValue = Convert.ToString(value); var data = this.Data.FirstOrDefault(o => o.Key == key); if (data == null) { - data = new Data { Key = key, Type = type, Name = name, Unit = unit, Description = description, Hidden = hidden }; + data = new Data { Key = key, Value = dataValue, Type = type, Name = name, Unit = unit, Description = description, Hidden = hidden }; this.Data.Add(data); result = true; } else { - var dataValue = Convert.ToString(value); if (data.Value != dataValue) { data.Value = dataValue; diff --git a/projects/IoT/IoT.Shared/Controllers/Onvif/OnvifController.cs b/projects/IoT/IoT.Shared/Controllers/Onvif/OnvifController.cs index 4d8c92ad..939d93a8 100644 --- a/projects/IoT/IoT.Shared/Controllers/Onvif/OnvifController.cs +++ b/projects/IoT/IoT.Shared/Controllers/Onvif/OnvifController.cs @@ -16,12 +16,21 @@ namespace IoT.Shared.Controllers.Onvif this._deviceService = deviceService; } - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("截屏")] - public ApiResponse ScreenShot([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("主码流截屏")] + public ApiResponse MainScreenShot([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) { return this.AsyncAction(() => { - this._deviceService.ScreenShot(number); + this._deviceService.MainScreenShot(number); + }); + } + + [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("子码流截屏")] + public ApiResponse SubScreenShot([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) + { + return this.AsyncAction(() => + { + this._deviceService.SubScreenShot(number); }); } diff --git a/projects/IoT/IoT.Shared/DeviceServices/Onvif/OnvifService.cs b/projects/IoT/IoT.Shared/DeviceServices/Onvif/OnvifService.cs index 6a7c5b19..39e1076e 100644 --- a/projects/IoT/IoT.Shared/DeviceServices/Onvif/OnvifService.cs +++ b/projects/IoT/IoT.Shared/DeviceServices/Onvif/OnvifService.cs @@ -188,6 +188,7 @@ namespace IoT.Shared.DeviceServices.Onvif device.AddorUpdateData("MainSnapshotUri", ipCamera.MainSnapshotUri, DeviceDataType.String, "主码流截图地址"); device.AddorUpdateData("SubStreamUri", ipCamera.SubStreamUri, DeviceDataType.String, "子码流地址"); device.AddorUpdateData("SubSnapshotUri", ipCamera.SubSnapshotUri, DeviceDataType.String, "子码流截图地址"); + device.AddorUpdateData("Snapshot", Convert.ToBase64String(SubScreenShot(device.Number)), DeviceDataType.String, "截图"); deviceRepo.SaveChanges(); this.SendDevice(device); } @@ -494,10 +495,26 @@ namespace IoT.Shared.DeviceServices.Onvif } } - public byte[] ScreenShot(string id) + public byte[] MainScreenShot(string id) { var camera = this.GetCamera(id); - var url = camera.GetDataValue("SnapshotUri"); + var url = camera.GetDataValue("MainSubSnapshotUri"); + if (string.IsNullOrEmpty(url)) + { + return new byte[] { }; + } + var hc = this._httpClientFactory.CreateClient(); + if (camera.GetDataValue("NeedAuth") == "否") + { + return hc.GetByteArrayAsync(url).Result; + } + return hc.GetByteDigest(url, camera.UserName, camera.Password); + } + + public byte[] SubScreenShot(string id) + { + var camera = this.GetCamera(id); + var url = camera.GetDataValue("SubSnapshotUri"); if (string.IsNullOrEmpty(url)) { return new byte[] { }; diff --git a/projects/IoT/IoTNode/Startup.cs b/projects/IoT/IoTNode/Startup.cs index ef6d30eb..d32598dc 100644 --- a/projects/IoT/IoTNode/Startup.cs +++ b/projects/IoT/IoTNode/Startup.cs @@ -25,7 +25,7 @@ namespace IoTNode public override void ConfigureServices(IServiceCollection services) { services.AddSingleton(); - services.AddSingleton(); + //services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); base.ConfigureServices(services); @@ -37,9 +37,9 @@ namespace IoTNode Task.Run(() => { app.ApplicationServices.GetService().Start(); - app.ApplicationServices.GetService().Start(); - app.ApplicationServices.GetService().Start(); - app.ApplicationServices.GetService().Start(); + app.ApplicationServices.GetService()?.Start(); + app.ApplicationServices.GetService()?.Start(); + app.ApplicationServices.GetService()?.Start(); }); } diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index2.html b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index2.html index 6aaff09f..c08ab415 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index2.html +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index2.html @@ -743,22 +743,7 @@
- - + 截图