diff --git a/projects/IoT/IoTServices/FBeeService/.gitignore b/projects/IoT/IoTServices/FBeeService/.gitignore deleted file mode 100644 index d8cbb114..00000000 --- a/projects/IoT/IoTServices/FBeeService/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -*.bak -*.suo -*.db -*.user -.vs/ -obj -Obj -bin -Bin -debug -Debug -release -Release -Logs -logs -node_modules \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/ClusterId.cs b/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/ClusterId.cs deleted file mode 100644 index 6acf096b..00000000 --- a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/ClusterId.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Application.Domain.Entities -{ - public enum ClusterId - { - off = 0xfbee, - light = 0x0400, - alarm = 0x0500, - pm25 = 0x0415, - temperature = 0x0402, - humidity = 0x0405, - voltage = 0x0001, - socket = 0x0702, - SummationDivisor = 0x0b04 - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/DeviceId.cs b/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/DeviceId.cs deleted file mode 100644 index f6fd1be9..00000000 --- a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/DeviceId.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Infrastructure.Domain; -using System.Collections.Generic; - -namespace Application.Domain.Entities -{ - public class DeviceId : BaseEntity - { - public static List List { get; set; } = new List(); - - static DeviceId() - { - List.Add(new DeviceId { RawDeviceId = 0x0002, Name = "开关", CategoryName = "照明", CategoryNumber = "30", Icon = "switch" }); - List.Add(new DeviceId { RawDeviceId = 0x0009, Name = "插座", CategoryName = "电器", CategoryNumber = "20", Icon = "socket" }); - List.Add(new DeviceId { RawDeviceId = 0x0051, Name = "智能插座", CategoryName = "电器", CategoryNumber = "20", Icon = "socket" }); - List.Add(new DeviceId { RawDeviceId = 0x0106, Name = "光强检测器", CategoryName = "监测", CategoryNumber = "40", Icon = "light" }); - List.Add(new DeviceId { RawDeviceId = 0x0163, Name = "红外转发器", CategoryName = "电器", CategoryNumber = "20", Icon = "control" }); - List.Add(new DeviceId { RawDeviceId = 0x0202, Name = "窗帘", CategoryName = "电器", CategoryNumber = "20", Icon = "curtain" }); - List.Add(new DeviceId { RawDeviceId = 0x0220, Name = "调色灯", CategoryName = "照明", CategoryNumber = "30", Icon = "curtain" }); - List.Add(new DeviceId { RawDeviceId = 0x0309, Name = "粉尘检测器", CategoryName = "监测", CategoryNumber = "40", Icon = "pm25" }); - List.Add(new DeviceId { RawDeviceId = 0x0302, Name = "温湿度传感器", CategoryName = "监测", CategoryNumber = "40", Icon = "temperature" }); - List.Add(new DeviceId { RawDeviceId = 0x0402, Name = "报警器", CategoryName = "安防", CategoryNumber = "10", Icon = "alarm" }); - } - - public string Name { get; set; } - public string Icon { get; set; } - public string CategoryNumber { get; set; } - public string CategoryName { get; set; } - public ushort RawDeviceId { get; set; } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/FBeeDataType.cs b/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/FBeeDataType.cs deleted file mode 100644 index 0f639489..00000000 --- a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/FBeeDataType.cs +++ /dev/null @@ -1,61 +0,0 @@ -namespace Application.Domain.Entities -{ - public enum FBeeDataType - { - null0 = 0x00, - bit1 = 0x08, - bit2, - bit3, - bit4, - bit5, - bit6, - bit7, - bit8, - bool1, - bitmap1 = 0x18, - bitmap2, - bitmpa3, - bitmap4, - bitmap5, - bitmap6, - bitmap7, - bitmap8, - uint1 = 0x20, - uint2, - uint3, - uint4, - uint5, - uint6, - uint7, - uint8, - int1, - int2, - int3, - int4, - int5, - int6, - int7, - int8, - enum1, - enum2, - float2 = 0x38, - float4, - float8, - bitstring = 0x41, - characterstring, - longbitstring, - longcharacterstring, - sequence = 0x4c, - set = 0x50, - bag, - time4 = 0xe0, - date4, - utctime4, - cluster2 = 0xe8, - attribute2, - bacnet4, - ieee1 = 0xf0, - m16, - unknown = 0xff - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/RequestType.cs b/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/RequestType.cs deleted file mode 100644 index 723d6a6d..00000000 --- a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/RequestType.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Application.Domain.Entities -{ - public class RequestType - { - public const int xfe = 0xfe; - public const int x81 = 0x81; - public const int x95 = 0x95; - public const int x9d = 0x9d; - public const int x82 = 0x82; - public const int x83 = 0x83; - public const int x84 = 0x84; - public const int x85 = 0x85; - public const int x86 = 0x86; - public const int x87 = 0x87; - public const int x88 = 0x88; - public const int x8d = 0x8d; - public const int xa9 = 0xa9; - public const int xc1 = 0xc1; - public const int xa7 = 0xa7; - public const int xa8 = 0xa8; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/ResponseType.cs b/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/ResponseType.cs deleted file mode 100644 index e9fa0a17..00000000 --- a/projects/IoT/IoTServices/FBeeService/Application/Domain/Entities/ResponseType.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Application.Domain.Entities -{ - public class ResponseType - { - public const int x01 = 0x01; - public const int x07 = 0x07; - public const int x08 = 0x08; - public const int x09 = 0x09; - public const int x0a = 0x0a; - public const int x27 = 0x27; - public const int x70 = 0x70; - public const int x72 = 0x72; - public const int x15 = 0x15; - public const int x29 = 0x29; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Application/Models/EditGatewayModel.cs b/projects/IoT/IoTServices/FBeeService/Application/Models/EditGatewayModel.cs deleted file mode 100644 index 774623d5..00000000 --- a/projects/IoT/IoTServices/FBeeService/Application/Models/EditGatewayModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Infrastructure.Application; -using System.ComponentModel.DataAnnotations; - -namespace SPService.Applicaiton.Models -{ - [Display(Name = "指令")] - public class EditGatewayModel : EditModel - { - [Required] - [Display(Name = "编号")] - public string Sn { get; set; } - - [Required] - [Display(Name = "IP")] - public string IP { get; set; } - - [Display(Name = "启用")] - public string Enable { get; set; } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Application/Models/TcpClientWrapper.cs b/projects/IoT/IoTServices/FBeeService/Application/Models/TcpClientWrapper.cs deleted file mode 100644 index 87dec9d0..00000000 --- a/projects/IoT/IoTServices/FBeeService/Application/Models/TcpClientWrapper.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Net.Sockets; - -namespace Application.Models -{ - public class TcpClientWrapper - { - public string Sn { get; set; } - public string Ip { get; set; } - public TcpClient Client { get; set; } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/DataController.cs b/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/DataController.cs deleted file mode 100644 index 2eb0834f..00000000 --- a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/DataController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Linq; -using Application.Domain.Entities; -using Application.Models; -using Infrastructure.Data; -using Infrastructure.Extensions; -using Infrastructure.Web.Mvc; -using IoTShared.Controllers; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace IoTCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class DataController : CrudController - { - private readonly AjaxController _ajax; - - public DataController(IRepository repo, AjaxController ajax) : base(repo) - { - this._ajax = ajax; - } - - public override IQueryable Query(DataSearchModel model, IQueryable query) - { - ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId)); - ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetDeviceSelectList(model.NodeId.Value, model.DeviceId), model.NodeId.HasValue); - return query.WhereIf(model.NodeId.HasValue, o => o.Device.NodeId == model.NodeId.Value) - .WhereIf(model.DeviceId.HasValue, o => o.DeviceId == model.DeviceId.Value) - .WhereIf(!string.IsNullOrEmpty(model.Keyword), o => o.Name.Contains(model.Keyword)); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/DeviceController.cs b/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/DeviceController.cs deleted file mode 100644 index 2ec51328..00000000 --- a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/DeviceController.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Application.Domain.Entities; -using Application.Models; -using Infrastructure.Data; -using Infrastructure.Web.Mvc; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace IoTCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class DeviceController : CrudController - { - public DeviceController(IRepository repo) : base(repo) - { - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/HomeController.cs b/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/HomeController.cs deleted file mode 100644 index acba2d08..00000000 --- a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Controllers/HomeController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace UserCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class HomeController : Controller - { - public HomeController() - { - } - - public IActionResult Index() - { - return View(); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Home/Index.cshtml b/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Home/Index.cshtml deleted file mode 100644 index f551b40e..00000000 --- a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Home/Index.cshtml +++ /dev/null @@ -1,4 +0,0 @@ -@{ - ViewData["IsHomePage"] = true; -} -

首页

\ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Shared/_Menu.cshtml b/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Shared/_Menu.cshtml deleted file mode 100644 index ff034510..00000000 --- a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Shared/_Menu.cshtml +++ /dev/null @@ -1,52 +0,0 @@ - -@functions{ - public string GetClass(params string[] controllers) - { - if (controllers.Select(o => o.ToLower()).Contains(this.ViewContext.RouteData.Values["controller"].ToString().ToLower())) - { - if (controllers.Length > 1) - { - return "active open"; - } - return "active"; - } - return ""; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Shared/_Script.cshtml b/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Shared/_Script.cshtml deleted file mode 100644 index 33c931f6..00000000 --- a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/Shared/_Script.cshtml +++ /dev/null @@ -1,24 +0,0 @@ - \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/_ViewImports.cshtml b/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/_ViewImports.cshtml deleted file mode 100644 index f99ab108..00000000 --- a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/_ViewImports.cshtml +++ /dev/null @@ -1,7 +0,0 @@ -@inherits Infrastructure.Web.Mvc.Razor.MyRazorPage -@using Infrastructure.Application -@using Infrastructure.Extensions -@using Infrastructure.Data -@using Application.Domain.Entities -@using Application.Models -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/_ViewStart.cshtml b/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/_ViewStart.cshtml deleted file mode 100644 index d641c67f..00000000 --- a/projects/IoT/IoTServices/FBeeService/Areas/Admin/Views/_ViewStart.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -@{ - Layout = "_Layout"; -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/AccountController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/AccountController.cs deleted file mode 100644 index 5fc0a5e2..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/AccountController.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Application.Domain.Entities; -using Infrastructure.Data; -using Infrastructure.Email; -using Infrastructure.Resources; -using Infrastructure.Security; -using IoT.UI.Shard.Controllers; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Localization; - -namespace FBeeService.Controllers -{ - public class AccountController : BaseAccountController - { - public AccountController(IConfiguration configuration, - IRepository userRepo, - IEncryptionService encryptionService, - IStringLocalizer localizer, - IEmailSender emaliSender) : base(configuration, userRepo, encryptionService, localizer, emaliSender) - { - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/ColorLightController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/ColorLightController.cs deleted file mode 100644 index d417f13b..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/ColorLightController.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Application.Models; -using Infrastructure.Extensions; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; -using System; -using System.ComponentModel.DataAnnotations; - -namespace FBeeService.Controllers -{ - [SwaggerTag("调色灯")] - public class ColorLightController : SwitchController - { - protected readonly DeviceService _deviceService; - - public ColorLightController(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices, deviceService) - { - this._deviceService = deviceService; - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("亮度")] - public ApiResponse SetBrightness([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number, [Range(0, 255)]int brightness) - { - try - { - this._deviceService.X83(gateway, number, (byte)brightness); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("色度")] - public ApiResponse SetColor([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number, [Range(0, 255)]int hue, [Range(0, 255)]int saturation) - { - try - { - this._deviceService.X84(gateway, number, (byte)hue, (byte)saturation); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("色温")] - public ApiResponse SetColorTemperature([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number, [Range(2700, 6500)]int colorTemperature) - { - try - { - this._deviceService.XA8(gateway, number, (ushort)colorTemperature); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/CurtainController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/CurtainController.cs deleted file mode 100644 index 85879eab..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/CurtainController.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Application.Models; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; -using System; - -namespace FBeeService.Controllers -{ - [SwaggerTag("窗帘")] - public class CurtainController : SwitchController - { - protected readonly DeviceService _deviceService; - - public CurtainController(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices, deviceService) - { - this._deviceService = deviceService; - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("停")] - public ApiResponse Stop([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 2); - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/GatewayController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/GatewayController.cs deleted file mode 100644 index ee466afe..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/GatewayController.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Application.Models; -using IoT.Shared.Controllers; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; -using System; - -namespace FBeeService.Controllers -{ - [SwaggerTag("网关")] - public class GatewayController : BaseDeviceController - { - private readonly DeviceService _deviceService; - - public GatewayController(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices) - { - this._deviceService = deviceService; - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("查询所有网关")] - - public ApiResponse Refresh() - { - return this.AsyncAction(() => - { - this._deviceService.Execute(); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("查询网关信息")] - public ApiResponse X9d([SwaggerParameter("网关Id")]string gateway) - { - return this.AsyncAction(() => - { - this._deviceService.X9d(gateway); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("查询所有设备")] - public ApiResponse X81([SwaggerParameter("网关Id")]string gateway) - { - return this.AsyncAction(() => - { - this._deviceService.X81(gateway); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("删除指定设备")] - public ApiResponse X95([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X95(gateway, number); - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs deleted file mode 100644 index 16ec72d8..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/HomeController.cs +++ /dev/null @@ -1,154 +0,0 @@ -using Application.Domain.Entities; -using Application.Models; -using Infrastructure.Data; -using Infrastructure.Extensions; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Swashbuckle.AspNetCore.Annotations; -using System; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Net.Http; - -namespace FBeeService.Controllers -{ - [ApiExplorerSettings(IgnoreApi = true)] - public class HomeController : Controller - { - private readonly IRepository _deviceRepo; - private readonly IHttpClientFactory _httpClientFactory; - private readonly DeviceService _deviceService; - - public HomeController(IHttpClientFactory httpClientFactory, - DeviceService deviceService, - IRepository deviceRepo) - { - this._deviceRepo = deviceRepo; - this._httpClientFactory = httpClientFactory; - this._deviceService = deviceService; - } - - #region ui - - public IActionResult Index() - { - var list = this._deviceRepo.ReadOnlyTable() - .Include(o => o.Data) - .Where(o => o.Info.DeviceType == DeviceType.Gateway) - .OrderBy(o => o.Number) - .ToList(); - return View(list); - } - - public IActionResult Gateway(string sn) - { - var list = this._deviceRepo.ReadOnlyTable() - .Include(o => o.Data) - .Where(o => o.GatewayNumber == sn) - .OrderBy(o => o.CategoryNumber) - .ToList(); - return View(list); - } - - #endregion ui - - #region IR - - [SwaggerOperation("版本")] - [HttpGet] - [Route("/ir/version")] - public ApiResponse Version([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id) - { - try - { - this._deviceService.XA70080(sn, id); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [Route("/ir/test")] - public ApiResponse IRControl([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, byte type, ushort code) - { - try - { - this._deviceService.XA70082(sn, id, type, code); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [Route("/ir/study")] - public ApiResponse IRStudy([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, byte type, ushort code) - { - try - { - this._deviceService.XA70083(sn, id, type, code); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - [SwaggerOperation("版本")] - [HttpGet] - [Route("/ir/control")] - public ApiResponse IRControl([SwaggerParameter("网关Id")]string sn, [SwaggerParameter("设备Id")]string id, int power, int pattern, int temperature, int direction, int wind) - { - try - { - var keyCode = power == 1 ? 1 : power + pattern + temperature + direction + wind; - this._deviceService.XA70082(sn, id, 0x01, (ushort)keyCode); - } - catch (Exception ex) - { - ex.PrintStack(); - return ApiResponse.Error(ex.Message); - } - return ApiResponse.AsyncSuccess(); - } - - #endregion IR - - #region tools - - private string GetApiJson(string prefix) - { - var url = new UriBuilder - { - Host = Request.Host.Host, - Port = Request.Host.Port ?? 80, - Path = "/swagger/v1/swagger.json" - }.ToString(); - var hc = this._httpClientFactory.CreateClient(); - var result = hc.GetStringAsync(url).Result; - var json = JsonConvert.DeserializeObject(result) as JObject; - var paths = json.Properties().FirstOrDefault(o => o.Name == "paths").Value as JObject; - var names = paths.Properties().Select(o => o.Name).ToList(); - foreach (var item in names) - { - if (!item.StartsWith(prefix)) - { - paths.Remove(item); - } - } - var realResult = JsonConvert.SerializeObject(json); - return realResult; - } - - #endregion tools - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/IrController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/IrController.cs deleted file mode 100644 index 27e26b32..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/IrController.cs +++ /dev/null @@ -1,128 +0,0 @@ -using Application.Models; -using IoT.Shared.Controllers; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; -using System; - -namespace FBeeService.Controllers -{ - [SwaggerTag("红外转发器")] - public class IrController : BaseDeviceController - { - private readonly DeviceService _deviceService; - - public IrController(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices) - { - this._deviceService = deviceService; - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("发送指令")] - - public ApiResponse Send([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number, [SwaggerParameter("按键类型")]byte type, [SwaggerParameter("键值")]ushort code) - { - return this.AsyncAction(() => - { - this._deviceService.XA70082(gateway, number, type, code); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("学习")] - public ApiResponse Study([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number, [SwaggerParameter("按键类型")]byte type, [SwaggerParameter("键值")]ushort code) - { - return this.AsyncAction(() => - { - this._deviceService.XA70083(gateway, number, type, code); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用空调")] - public ApiResponse KeyCodeType1On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType1", "开"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用空调")] - public ApiResponse KeyCodeType1Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType1", "关"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用电视")] - public ApiResponse KeyCodeType2On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType2", "开"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用电视")] - public ApiResponse KeyCodeType2Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType2", "关"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用图影仪")] - public ApiResponse KeyCodeType3On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType3", "开"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用图影仪")] - public ApiResponse KeyCodeType3Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType3", "关"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用机顶盒")] - public ApiResponse KeyCodeType4On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType4", "开"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用机顶盒")] - public ApiResponse KeyCodeType4Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType4", "关"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("启用自定义")] - public ApiResponse KeyCodeType5On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType5", "开"); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("禁用自定义")] - public ApiResponse KeyCodeType5Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.SetKeyCodeType(gateway, number, "KeyCodeType5", "关"); - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/SocketController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/SocketController.cs deleted file mode 100644 index 9dd63567..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/SocketController.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Swashbuckle.AspNetCore.Annotations; -using System; - -namespace FBeeService.Controllers -{ - [SwaggerTag("1路插座")] - public class SocketController : SwitchController - { - public SocketController(IServiceProvider applicationService, DeviceService deviceService) : base(applicationService, deviceService) - { - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/Switch2Controller.cs b/projects/IoT/IoTServices/FBeeService/Controllers/Switch2Controller.cs deleted file mode 100644 index 5fa684d1..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/Switch2Controller.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Application.Models; -using IoT.Shared.Controllers; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; -using System; - -namespace FBeeService.Controllers -{ - [SwaggerTag("2路开关")] - public class Switch2Controller : BaseDeviceController - { - private readonly DeviceService _deviceService; - - public Switch2Controller(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices) - { - this._deviceService = deviceService; - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("全开")] - public ApiResponse On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 1, 0x10); - this._deviceService.X82(gateway, number, 1, 0x11); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("全关")] - public ApiResponse Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 0, 0x10); - this._deviceService.X82(gateway, number, 0, 0x11); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L1开")] - public ApiResponse L1On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 1, 0x10); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L1关")] - public ApiResponse L1Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 0, 0x10); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L2开")] - public ApiResponse L2On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 1, 0x11); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L2关")] - public ApiResponse L2Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 0, 0x11); - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/Switch3Controller.cs b/projects/IoT/IoTServices/FBeeService/Controllers/Switch3Controller.cs deleted file mode 100644 index 2bc581ec..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/Switch3Controller.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Application.Models; -using IoT.Shared.Controllers; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; -using System; - -namespace FBeeService.Controllers -{ - [SwaggerTag("3路开关")] - public class Switch3Controller : BaseDeviceController - { - private readonly DeviceService _deviceService; - - public Switch3Controller(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices) - { - this._deviceService = deviceService; - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("全开")] - public ApiResponse On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 1, 0x10); - this._deviceService.X82(gateway, number, 1, 0x11); - this._deviceService.X82(gateway, number, 1, 0x12); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("全关")] - public ApiResponse Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 0, 0x10); - this._deviceService.X82(gateway, number, 0, 0x11); - this._deviceService.X82(gateway, number, 0, 0x12); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L1开")] - public ApiResponse L1On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 1, 0x10); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L1关")] - public ApiResponse L1Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 0, 0x10); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L2开")] - public ApiResponse L2On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 1, 0x11); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L2关")] - public ApiResponse L2Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 0, 0x11); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L3开")] - public ApiResponse L3On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 1, 0x12); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("L3关")] - public ApiResponse L3Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 0, 0x12); - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/SwitchController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/SwitchController.cs deleted file mode 100644 index 50e2f98c..00000000 --- a/projects/IoT/IoTServices/FBeeService/Controllers/SwitchController.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Application.Models; -using IoT.Shared.Controllers; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; -using System; - -namespace FBeeService.Controllers -{ - [SwaggerTag("1路开关")] - public class SwitchController : BaseDeviceController - { - private readonly DeviceService _deviceService; - - public SwitchController(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices) - { - this._deviceService = deviceService; - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("开")] - public ApiResponse On([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 1); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("关")] - public ApiResponse Off([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.X82(gateway, number, 0); - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/FBeeService.csproj b/projects/IoT/IoTServices/FBeeService/FBeeService.csproj deleted file mode 100644 index ad2e71d2..00000000 --- a/projects/IoT/IoTServices/FBeeService/FBeeService.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - netcoreapp2.2 - true - FBeeService - - - - - - - - - - - - - - \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/FBeeService.sln b/projects/IoT/IoTServices/FBeeService/FBeeService.sln deleted file mode 100644 index 1c648665..00000000 --- a/projects/IoT/IoTServices/FBeeService/FBeeService.sln +++ /dev/null @@ -1,43 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28010.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FBeeService", "FBeeService.csproj", "{E25B755D-0074-481F-847B-8D45B33C65A7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "..\..\..\..\Infrastructure\Infrastructure\src\Infrastructure\Infrastructure.csproj", "{6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoT.Shared", "..\..\Libraries\src\IoT.Shared\IoT.Shared.csproj", "{8572A0E0-E4E3-466D-8116-5F686040C66D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoT.UI.Shard", "..\..\Libraries\src\IoT.UI.Shard\IoT.UI.Shard.csproj", "{4D947053-F0FF-4F5B-8E33-CE474BDF0621}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E25B755D-0074-481F-847B-8D45B33C65A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E25B755D-0074-481F-847B-8D45B33C65A7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E25B755D-0074-481F-847B-8D45B33C65A7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E25B755D-0074-481F-847B-8D45B33C65A7}.Release|Any CPU.Build.0 = Release|Any CPU - {6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}.Release|Any CPU.Build.0 = Release|Any CPU - {8572A0E0-E4E3-466D-8116-5F686040C66D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8572A0E0-E4E3-466D-8116-5F686040C66D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8572A0E0-E4E3-466D-8116-5F686040C66D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8572A0E0-E4E3-466D-8116-5F686040C66D}.Release|Any CPU.Build.0 = Release|Any CPU - {4D947053-F0FF-4F5B-8E33-CE474BDF0621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4D947053-F0FF-4F5B-8E33-CE474BDF0621}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4D947053-F0FF-4F5B-8E33-CE474BDF0621}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4D947053-F0FF-4F5B-8E33-CE474BDF0621}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B5A82048-F0E0-4FA7-9954-E5983781CAAC} - EndGlobalSection -EndGlobal diff --git a/projects/IoT/IoTServices/FBeeService/Infrastructure/ClientService.cs b/projects/IoT/IoTServices/FBeeService/Infrastructure/ClientService.cs deleted file mode 100644 index 96c563b0..00000000 --- a/projects/IoT/IoTServices/FBeeService/Infrastructure/ClientService.cs +++ /dev/null @@ -1,105 +0,0 @@ -//using Application.Domain.Entities; -//using Infrastructure.Data; -//using Infrastructure.Extensions; -//using IoT.Shared.Infrastructure; -//using Microsoft.AspNetCore.SignalR.Client; -//using Microsoft.EntityFrameworkCore; -//using Microsoft.Extensions.Configuration; -//using Microsoft.Extensions.DependencyInjection; -//using System; -//using System.Linq; -//using System.Net.Http; -//using System.Threading.Tasks; - -//namespace FBeeService -//{ -// public class ClientService : BaseClientService -// { -// public ClientService(IServiceProvider applicationServices, IConfiguration configuration) : base(applicationServices, configuration) -// { -// } - -// public override void OnConnected() -// { -// using (var scope = this.applicationServices.CreateScope()) -// { -// var deviceInfoRepo = scope.ServiceProvider.GetService>(); -// var deviceInfos = deviceInfoRepo.ReadOnlyTable().ToList(); -// foreach (var deviceInfo in deviceInfos) -// { -// this.SendDeviceInfo(deviceInfo); -// } - -// var deviceRepo = scope.ServiceProvider.GetService>(); -// var devices = deviceRepo.ReadOnlyTable().Include(o => o.Data).ToList(); -// foreach (var device in devices) -// { -// this.SendDevice(device); -// } -// } -// } - -// public override void OnServerToClient(string method, string message, string fromConnectionId) -// { -// if (method == "GetDeviceInfo") -// { -// var infoNumber = message; -// using (var scope = this.applicationServices.CreateScope()) -// { -// var deviceInfoRepo = scope.ServiceProvider.GetService>(); -// var deviceInfo = deviceInfoRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == infoNumber); -// if (deviceInfo == null) -// { -// throw new Exception($"not has infoNumber:{infoNumber}"); -// } -// this.SendDeviceInfo(deviceInfo); -// } -// } -// else if (method == "CallDeviceMethod") -// { -// using (var scope = this.applicationServices.CreateScope()) -// { -// var serviceProvider = scope.ServiceProvider; -// var cfg = serviceProvider.GetService(); -// var port = cfg["server.urls"].Split(':')[2]; -// var url = $"http://localhost:{port}{message}"; -// var httpClient = serviceProvider.GetService().CreateClient(); -// var result = httpClient.GetStringAsync(url).Result; -// this.Connection.SendAsync("ClientToServer", "ApiCallback", result, cfg["connectId"]); -// } -// } -// } - -// public void SendDevice(Device device) -// { -// Task.Run(() => -// { -// try -// { -// Console.WriteLine("send device to server"); -// this.ClientToServer("UpdateDevice", device.ToJson()); -// } -// catch (Exception ex) -// { -// ex.PrintStack(); -// } -// }); -// } - -// public void SendDeviceInfo(DeviceInfo deviceInfo) -// { -// Task.Run(() => -// { -// try -// { -// Console.WriteLine("send device to server"); -// this.ClientToServer("UpdateDeviceInfo", deviceInfo.ToJson()); -// } -// catch (Exception ex) -// { -// ex.PrintStack(); -// } -// }); -// } -// } -//} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs b/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs deleted file mode 100644 index 7fe7d78d..00000000 --- a/projects/IoT/IoTServices/FBeeService/Infrastructure/DeviceService.cs +++ /dev/null @@ -1,1283 +0,0 @@ -using Application.Domain.Entities; -using Application.Models; -using Infrastructure.Data; -using Infrastructure.Extensions; -using IoT.Shared.Infrastructure; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.NetworkInformation; -using System.Net.Sockets; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; - -namespace FBeeService -{ - public class DeviceService : BaseDeviceService - { - private readonly ConcurrentDictionary Clients = new ConcurrentDictionary(); - - public DeviceService(IServiceProvider applicationServices, IConfiguration configuration) - : base(applicationServices, configuration) - { - } - - #region impl interface - - public override void Start() - { - base.Start(); - this.HealthCheck(); - } - - public override void Execute() - { - Refresh(); - } - - public override void Stop() - { - foreach (var item in Clients) - { - if (item.Value.Client != null) - { - item.Value.Client.Dispose(); - } - } - } - - #endregion impl interface - - #region private - - private void HealthCheck() - { - Task.Run(async () => - { - while (!_tokenSource.IsCancellationRequested) - { - try - { - foreach (var item in this.Clients) - { - this.X9d(item.Key); - } - } - catch (Exception ex) - { - ex.PrintStack(); - } - await Task.Delay(1000 * 60); - } - }); - } - - private void Refresh() - { - var ips = NetworkInterface.GetAllNetworkInterfaces() - .Where(nic => nic.OperationalStatus == OperationalStatus.Up && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback) - .Select(nic => nic.GetIPProperties().UnicastAddresses) - .SelectMany(o => o.ToList()) - .Select(o => o.Address) - .Where(o => o.AddressFamily == AddressFamily.InterNetwork) - .ToList(); - var list = new ConcurrentBag(); - foreach (var ip in ips) - { - Console.WriteLine($"search:{ip}"); - var tokenSource = new CancellationTokenSource(); - using (var client = new UdpClient(new IPEndPoint(ip, 0))) - { - var message = Encoding.ASCII.GetBytes("GETIP\r\n"); - client.Send(message, message.Length, new IPEndPoint(IPAddress.Parse("255.255.255.255"), 9090)); - Task.Run(() => - { - try - { - var ep = new IPEndPoint(IPAddress.Any, 3702); - while (!tokenSource.IsCancellationRequested) - { - if (client.Available > 0) - { - var buffer = client.Receive(ref ep); - var result = Encoding.ASCII.GetString(buffer); - Console.WriteLine(result); - if (!list.Any(o => o == result)) - { - list.Add(result); - } - } - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - }, tokenSource.Token); - Thread.Sleep(1000); - tokenSource.Cancel(); - } - } - using (var scope = _applicationServices.CreateScope()) - { - var deviceInfoNumber = "fbee:gateway"; - var deviceInfoRepo = scope.ServiceProvider.GetService>(); - var deviceInfo = deviceInfoRepo.Table().FirstOrDefault(o => o.Number == deviceInfoNumber); - if (deviceInfo == null) - { - deviceInfo = new DeviceInfo - { - Number = deviceInfoNumber, - Name = "FBee网关", - DeviceType = DeviceType.Gateway, - ApiJson = this.GetApiJson("/Gateway/") - }; - deviceInfoRepo.Add(deviceInfo); - deviceInfoRepo.SaveChanges(); - this.SendDeviceInfo(deviceInfo); - } - var deviceRepo = scope.ServiceProvider.GetService>(); - foreach (var result in list) - { - var sn = Regex.Match(result, @"SN:([^\s]*)").Groups[1].Value; - var ip = Regex.Match(result, @"IP:([^\s]*)").Groups[1].Value; - var device = deviceRepo.Table().FirstOrDefault(o => o.Number == sn); - - if (device == null) - { - device = new Device - { - Number = sn, - Name = "网关", - Enable = true, - Icon = "gateway", - CategoryNumber = "0", - InfoNumber = deviceInfoNumber, - InfoId = deviceInfo.Id, - }; - device.ConnectId = this._configuration["connectId"]; - device.NodeNumber = this._configuration["node.number"]; - deviceRepo.Add(device); - } - device.Ip = ip; - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - var gateways = deviceRepo.ReadOnlyTable().Where(o => o.Info.DeviceType == DeviceType.Gateway).ToList(); - foreach (var gateway in gateways) - { - if (gateway.Enable) - { - if (Clients.Any(o => o.Key == gateway.Number)) - { - Clients.TryGetValue(gateway.Number, out TcpClientWrapper client); - if (client.Ip != gateway.Ip) - { - this.Connect(client); - } - else - { - if (!client.Client.Connected) - { - this.Connect(client); - } - } - } - else - { - var client = new TcpClientWrapper { Sn = gateway.Number, Ip = gateway.Ip, Client = new TcpClient() }; - Clients.TryAdd(gateway.Number, client); - this.Connect(client); - } - this.X81(gateway.Number); - } - else - { - if (Clients.Any(o => o.Key == gateway.Number)) - { - Clients.TryRemove(gateway.Number, out TcpClientWrapper client); - if (client.Client.Connected) - { - client.Client.Close(); - } - } - } - } - } - } - - private void Connect(TcpClientWrapper client) - { - try - { - if (client != null) - { - client.Client.Dispose(); - client.Client = new TcpClient(); - } - Console.WriteLine($"connect {client.Ip} for {client.Sn}"); - client.Client.Connect(client.Ip, 8001); - new Thread(() => - { - var stream = client.Client.GetStream(); - while (client.Client.Connected) - { - try - { - if (stream.DataAvailable) - { - var buffer = new byte[512]; - var length = stream.Read(buffer); - var data = buffer.ToList().Take(length).ToArray(); - Console.WriteLine($"response:{BitConverter.ToString(data)}"); - this.Handle(client.Sn, data); - } - } - catch (Exception ex) - { - ex.PrintStack("read stream error"); - break; - } - } - }).Start(); - this.X9d(client.Sn); - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - - private void Handle(string sn, byte[] data) - { - var length = 2 + data[1]; - if (data.Length > length) - { - Handle(sn, data.Skip(length).ToArray()); - } - this.HandleInternal(sn, data.Take(length).ToArray()); - } - - private void HandleInternal(string sn, byte[] data) - { - Console.WriteLine($"read:{BitConverter.ToString(data).Replace("-", " ")}"); - var responseType = data[0]; - if (responseType == ResponseType.x15) - { - this.X15(sn, data); - } - else if (responseType == ResponseType.x01) - { - this.X01(sn, data); - } - else if (responseType == ResponseType.x07) - { - this.X07(sn, data); - } - else if (responseType == ResponseType.x08) - { - this.X08(sn, data); - } - else if (responseType == ResponseType.x09) - { - this.X09(sn, data); - } - else if (responseType == ResponseType.x0a) - { - this.X0A(sn, data); - } - else if (responseType == ResponseType.x27) - { - this.X27(sn, data); - } - else if (responseType == ResponseType.x70) - { - this.X70(sn, data); - } - else if (responseType == ResponseType.x72) - { - this.X70(sn, data); - } - else - { - Console.WriteLine($"{responseType} hasn't handle"); - } - } - - private void Write(string sn, byte commandType, string ieee = null, List command = null, int format = 1, byte? ep = null) - { - this.Clients.TryGetValue(sn, out TcpClientWrapper client); - var data = new List(); - data.AddRange(sn.HexToBytes().Reverse());//sn号 - data.Add(RequestType.xfe);//控制标志 - data.Add(commandType);//控制类型 - - if (command != null) - { - byte addressType = 0x02; - var payload = new List(); - using (var scope = _applicationServices.CreateScope()) - { - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = this.GetDevice(deviceRepo, sn, ieee); - var address = device.GetDataValue(Keys.Address).HexToBytes().Reverse(); - var endPoint = Convert.ToInt32(device.GetDataValue(Keys.EndPoint)); - if (format == 0) - { - payload.Add((byte)(command.Count() + 1 + 2));//数据总长 - payload.Add(addressType);//地址模式 - payload.AddRange(address); - payload.AddRange(command); - } - else if (format == 1) - { - payload.Add((byte)(command.Count() + 1 + 2 + 6 + 1 + 2));//数据总长 - payload.Add(addressType);//地址模式 - payload.AddRange(address); - payload.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); - payload.Add(ep ?? (byte)endPoint); - payload.AddRange(new byte[] { 0x00, 0x00 }); - payload.AddRange(command); - } - else if (format == 2) - { - payload.Add((byte)(command.Count() + 2 + 1));//数据总长 - payload.AddRange(address); - payload.Add(ep ?? (byte)endPoint); - payload.AddRange(command); - } - data.AddRange(payload); - } - } - - var MessageLength = BitConverter.GetBytes((ushort)(data.Count() + 2));//消息总长 - if (BitConverter.IsLittleEndian) - { - MessageLength.Reverse(); - } - var message = new List(); - message.AddRange(MessageLength); - message.AddRange(data); - var bytes = message.ToArray(); - this.Send(client, bytes); - } - - private void Send(TcpClientWrapper client, byte[] bytes) - { - Console.WriteLine($"write:{BitConverter.ToString(bytes).Replace("-", " ")}"); - try - { - client.Client.GetStream().Write(bytes); - } - catch (IOException) - { - if (!client.Client.Connected) - { - this.Connect(client); - client.Client.GetStream().Write(bytes); - } - } - } - - #endregion private - - #region api - - /// - /// 0x81获取当前连接所有设备 - /// - /// - public void X81(string sn) - { - Console.WriteLine($"refresh {sn}"); - this.Write(sn, RequestType.x81); - } - - /// - /// 接收当前连接的设备信息返回值 - /// - /// - /// - private void X01(string sn, byte[] data) - { - var create = false; - try - { - using (var ms = new MemoryStream(data)) - { - var responseType = ms.ReadByte(); - var dataLength = ms.ReadByte(); - var address = ms.ReadHexStringDesc(2); - var endpoint = ms.ReadByte(); - using (var scope = _applicationServices.CreateScope()) - { - var profileId = ms.ReadInt(); - var deviceId = ms.ReadInt(); - var switchState = ms.ReadByte(); - var nameLength = ms.ReadByte(); - var cname = ""; - if (nameLength > 0) - { - cname = ms.ReadASIIString(nameLength); - } - var isOnline = ms.ReadByte(); - var ieee = ms.ReadHexString(8); - var snLength = ms.ReadByte(); - var rawSn = ms.ReadHexString(snLength); - var zoneType = ms.ReadInt(); - var deviceType = DeviceId.List.FirstOrDefault(o => o.RawDeviceId == deviceId); - var deviceName = deviceType.Name; - if (deviceId == 0x402) - { - if (zoneType == 0x0028) - { - deviceName = "烟雾传感器"; - } - else if (zoneType == 0x000d) - { - deviceName = "红外感应器"; - } - } - else if (deviceId == 0x002) - { - if (zoneType == 0x0001) - { - deviceName = "一路开关"; - } - else if (zoneType == 0x0002) - { - deviceName = "二路开关"; - } - else if (zoneType == 0x0003) - { - deviceName = "三路开关"; - } - } - var infoNumber = $"fbee:{deviceType.RawDeviceId.ToString("x4")}:{zoneType.ToString("x2")}"; - if (deviceType != null) - { - var number = deviceType.RawDeviceId; - var deviceInfoRepo = scope.ServiceProvider.GetService>(); - var deviceInfo = deviceInfoRepo.Table().FirstOrDefault(o => o.Number == infoNumber); - if (deviceInfo == null) - { - deviceInfo = new DeviceInfo - { - Name = deviceName, - Number = infoNumber, - DeviceType = DeviceType.Device - }; - if (deviceName == "插座" || deviceName == "智能插座") - { - deviceInfo.ApiJson = this.GetApiJson("/Socket/"); - } - else if (deviceName == "一路开关") - { - deviceInfo.ApiJson = this.GetApiJson("/Switch/"); - } - else if (deviceName == "二路开关") - { - deviceInfo.ApiJson = this.GetApiJson("/Switch2/"); - } - else if (deviceName == "三路开关") - { - deviceInfo.ApiJson = this.GetApiJson("/Switch3/"); - } - else if (deviceName == "窗帘") - { - deviceInfo.ApiJson = this.GetApiJson("/Curtain/"); - } - else if (deviceName == "调色灯") - { - deviceInfo.ApiJson = this.GetApiJson("/ColorLight/"); - } - else if (deviceName == "红外转发器") - { - deviceInfo.ApiJson = this.GetApiJson("/Ir/"); - } - deviceInfoRepo.Add(deviceInfo); - deviceInfoRepo.SaveChanges(); - this.SendDeviceInfo(deviceInfo); - } - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = this.GetDevice(deviceRepo, sn, ieee); - if (device == null) - { - create = true; - device = new Device - { - Number = ieee, - Name = deviceName, - Icon = deviceType.Icon, - CategoryNumber = deviceType.CategoryNumber, - GatewayNumber = sn, - InfoNumber = infoNumber, - InfoId = deviceInfo.Id - }; - if (deviceName == "红外转发器") - { - device.AddorUpdateData("KeyCodeType1", "关", DeviceDataType.String, "空调"); - device.AddorUpdateData("KeyCodeType2", "关", DeviceDataType.String, "电视"); - device.AddorUpdateData("KeyCodeType3", "关", DeviceDataType.String, "图影仪"); - device.AddorUpdateData("KeyCodeType4", "关", DeviceDataType.String, "机顶盒"); - device.AddorUpdateData("KeyCodeType5", "关", DeviceDataType.String, "自定义"); - } - deviceRepo.Add(device); - } - device.IsOnline = isOnline != 0x00; - device.ConnectId = this._configuration["connectId"]; - device.NodeNumber = this._configuration["node.Number"]; - - device.AddorUpdateData(Keys.DeviceId, deviceId, DeviceDataType.Int, Keys.DeviceId, hidden: true); - device.AddorUpdateData(Keys.Address, address, DeviceDataType.String, Keys.Address, hidden: true); - device.AddorUpdateData(Keys.EndPoint, endpoint, DeviceDataType.Int, Keys.EndPoint, hidden: true); - if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId)) - { - device.AddorUpdateData(Keys.State, switchState == 0 ? "关" : (switchState == 1 ? "关" : "停"), DeviceDataType.String, "状态"); - } - var battery = ms.ReadByte(); - device.AddorUpdateData(Keys.Battery, battery, DeviceDataType.Int, Keys.Battery, hidden: true); - var epCount = ms.ReadByte(); - device.AddorUpdateData(Keys.EndPointCount, battery, DeviceDataType.Int, Keys.EndPointCount, hidden: true); - var historyData = ms.ReadHexString(4); - device.AddorUpdateData(Keys.Data, historyData, DeviceDataType.String, Keys.Data, hidden: true); - device.AddorUpdateData(Keys.ZoneType, zoneType, DeviceDataType.String, Keys.ZoneType, hidden: true); - deviceRepo.SaveChanges(); - if (create) - { - this.UpdateStatus(device); - } - this.SendDevice(device); - } - else - { - Console.WriteLine("uknown device type"); - } - } - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - private void UpdateStatus(Device device) - { - var deviceId = Convert.ToInt32(device.GetDataValue(Keys.DeviceId)); - var sn = device.GatewayNumber; - var ieee = device.Number; - if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId)) - { - this.X85(sn, ieee); - } - if (deviceId == 0x0220) - { - this.X86(sn, ieee); - this.X87(sn, ieee); - this.X88(sn, ieee); - this.XA9(sn, ieee); - } - else if (deviceId == 0x0163) - { - this.XA70080(sn, ieee); - } - else if (deviceId == 0x0051) - { - this.X8D07020000(sn, ieee); - } - } - - /// - /// 0x95删除指定设备 - /// - /// - /// - public void X95(string sn, string ieee) - { - Console.WriteLine($"delete {ieee} from {sn}"); - var list = new List(); - list.AddRange(ieee.HexToBytes()); - list.Add(0x01); - this.Write(sn, RequestType.x95, ieee, list, 0); - } - - //0x94更改指定设备名 - /// - /// 0x82设置指定设备的开关状态 - /// - /// - /// - /// - public void X82(string sn, string ieee, byte status, byte? ep = null) - { - var list = new List - { - status - }; - this.Write(sn, RequestType.x82, ieee, list, ep: ep); - } - - /// - /// 0x85-0x07接收指定设备的开关状态 - /// - /// - /// - private void X07(string sn, byte[] data) - { - using (var ms = new MemoryStream(data)) - { - var responseType = ms.ReadByte(); - var dataLength = ms.ReadByte(); - var address = ms.ReadHexStringDesc(2); - var endpoint = ms.ReadByte(); - using (var scope = _applicationServices.CreateScope()) - { - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = this.GetDeviceByAddress(deviceRepo, sn, address); - if (device != null) - { - if (device.Name.Contains("二路开关") || device.Name.Contains("三路开关")) - { - if (endpoint == 0x10) - { - device.AddorUpdateData(Keys.L1State, ms.ReadInt() == 0 ? "关" : "开", DeviceDataType.String, "L1状态"); - } - else if (endpoint == 0x11) - { - device.AddorUpdateData(Keys.L2State, ms.ReadInt() == 0 ? "关" : "开", DeviceDataType.String, "L2状态"); - } - else if (endpoint == 0x12) - { - device.AddorUpdateData(Keys.L3State, ms.ReadInt() == 0 ? "关" : "开", DeviceDataType.String, "L3状态"); - } - } - else - { - device.AddorUpdateData(Keys.State, ms.ReadInt() == 0 ? "关" : "开", DeviceDataType.String, "状态"); - } - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - else - { - Console.WriteLine($"device {address} hasn't save in database"); - } - } - } - } - - /// - /// 0x83设置指定设备的亮度 - /// - /// - /// - /// 0-255 - public void X83(string sn, string ieee, [Range(0, 255)]byte brightness) - { - var list = new List - { - brightness - }; - list.AddRange(new byte[] { 0x00, 0x00 }); - this.Write(sn, RequestType.x83, ieee, list); - } - - /// - /// 0x08接收指定设备的亮度状态返回值 - /// - /// - /// - private void X08(string sn, byte[] data) - { - using (var ms = new MemoryStream(data)) - { - var responseType = ms.ReadByte(); - var dataLength = ms.ReadByte(); - var address = ms.ReadHexStringDesc(2); - var endpoint = ms.ReadByte(); - using (var scope = _applicationServices.CreateScope()) - { - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = this.GetDeviceByAddress(deviceRepo, sn, address); - if (device != null) - { - device.AddorUpdateData(Keys.Brightness, ms.ReadByte(), DeviceDataType.Int, "亮度"); - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - else - { - Console.WriteLine($"device {address} hasn't save in database"); - } - } - } - } - - /// - /// 0x83设置指定设备的颜色,即色调和饱和度 - /// - public void X84(string sn, string ieee, [Range(0, 255)]byte hue, [Range(0, 255)]byte saturation) - { - var list = new List - { - hue, - saturation - }; - list.AddRange(new byte[] { 0x00, 0x00 }); - this.Write(sn, RequestType.x84, ieee, list); - } - - /// - /// 0x09接收指定设备的色调返回值 - /// - /// - /// - private void X09(string sn, byte[] data) - { - using (var ms = new MemoryStream(data)) - { - var responseType = ms.ReadByte(); - var dataLength = ms.ReadByte(); - var address = ms.ReadHexStringDesc(2); - var endpoint = ms.ReadByte(); - using (var scope = _applicationServices.CreateScope()) - { - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = this.GetDeviceByAddress(deviceRepo, sn, address); - if (device != null) - { - device.AddorUpdateData(Keys.Hue, ms.ReadByte(), DeviceDataType.Int, "色调"); - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - else - { - Console.WriteLine($"device {address} hasn't save in database"); - } - } - } - } - - /// - /// 0x09接收指定设备的饱和度返回值 - /// - /// - /// - private void X0A(string sn, byte[] data) - { - using (var ms = new MemoryStream(data)) - { - var responseType = ms.ReadByte(); - var dataLength = ms.ReadByte(); - var address = ms.ReadHexStringDesc(2); - var endpoint = ms.ReadByte(); - using (var scope = _applicationServices.CreateScope()) - { - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = this.GetDeviceByAddress(deviceRepo, sn, address); - if (device != null) - { - device.AddorUpdateData(Keys.Saturation, ms.ReadByte(), DeviceDataType.Int, "饱和度"); - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - else - { - Console.WriteLine($"device {address} hasn't save in database"); - } - } - } - } - - /// - /// 0x85-0x07查询开关状态 - /// - public void X85(string sn, string ieee) - { - var list = new List(); - this.Write(sn, RequestType.x85, ieee, list); - } - - /// - /// 0x86-0x08查询亮度状态 - /// - public void X86(string sn, string ieee) - { - var list = new List(); - this.Write(sn, RequestType.x86, ieee, list); - } - - /// - /// 0x87-0x09查询色度状态 - /// - public void X87(string sn, string ieee) - { - var list = new List(); - this.Write(sn, RequestType.x87, ieee, list); - } - - /// - /// 0x88-0x0a查询饱和度状态 - /// - public void X88(string sn, string ieee) - { - var list = new List(); - this.Write(sn, RequestType.x88, ieee, list); - } - - /// - /// 0x8d-0x70发送zcl指令,读取簇id为0702属性为0000的电量值 - /// - public void X8D07020000(string sn, string ieee) - { - var list = new List() { 0x02, 0x07, 0x00, 0x00, 0x00 }; - this.Write(sn, RequestType.xa7, ieee, list, 2); - } - - // - //0x96 - //0x8e - //0x8f - //0x97 - //0x98 - //0x90 - //0x91 - //0x92 - //0x93 - //0x8a - //0x8b - //0x8c - //0x99 - //0x9a - //0x9b - //0x9c - //0x9d获取网关信息 - public void X9d(string sn) - { - this.Write(sn, RequestType.x9d); - } - - /// - /// 0x15接收网关信息 - /// - /// - /// - private void X15(string sn, byte[] data) - { - using (var ms = new MemoryStream(data)) - { - var responseType = ms.ReadByte(); - var dataLength = ms.ReadByte(); - var version = ms.ReadASIIString(5); - var snid = ms.ReadHexString(4); - using (var scope = _applicationServices.CreateScope()) - { - var gatewayRepo = scope.ServiceProvider.GetService>(); - var gateway = gatewayRepo.Table() - .Include(o => o.Data) - .FirstOrDefault(o => o.Number == sn); - if (gateway == null) - { - Console.WriteLine($"gateway {sn} hasn't save in database"); - } - else - { - gateway.UserName = ms.ReadASIIString(20); - gateway.Password = ms.ReadASIIString(20); - - gateway.AddorUpdateData(Keys.Version, version, DeviceDataType.String, "版本"); - gateway.AddorUpdateData(Keys.DeviceCount, ms.ReadByte(), DeviceDataType.Int, "设备数量"); - ms.ReadByte(); - ms.ReadByte(); - ms.ReadByte(); - ms.ReadByte(); - var hex = ms.ReadHexString(5); - var compileVersion = ms.ReadHexString(5); - } - gatewayRepo.SaveChanges(); - this.SendDevice(gateway); - } - } - } - - //0x9e - //0x9f - //0xa0 - //0xa1 - //0xa2 - //0xa3 - //0xa4 - //0xa5 - /// - /// 0xa8设置指定设备的色温 - /// - public void XA8(string sn, string ieee, [Range(2700, 6500)]ushort color) - { - var list = new List(); - list.AddRange(BitConverter.GetBytes(color)); - list.AddRange(new byte[] { 0x00, 0x00 }); - this.Write(sn, RequestType.xa8, ieee, list); - } - - /// - /// 0x27接收指定设备的色温返回值 - /// - /// - /// - private void X27(string sn, byte[] data) - { - using (var ms = new MemoryStream(data)) - { - var responseType = ms.ReadByte(); - var dataLength = ms.ReadByte(); - var address = ms.ReadHexStringDesc(2); - var endpoint = ms.ReadByte(); - using (var scope = _applicationServices.CreateScope()) - { - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = this.GetDeviceByAddress(deviceRepo, sn, address); - if (device != null) - { - device.AddorUpdateData(Keys.ColorTemperature, ms.ReadInt(), DeviceDataType.Int, "色温"); - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - else - { - Console.WriteLine($"device {address} hasn't save in database"); - } - } - } - } - - /// - /// 0080查询红外版本号 - /// - /// - /// - public void XA70080(string sn, string ieee) - { - var list = new List - { - 0x03,//控制标志 - 0xff,//包长 - 0x00//包序号 - }; - list.AddRange(new byte[] { 0x55, 0x55 }); - list.Add(0x02); - list.AddRange(new byte[] { 0x80, 0x00 }); - list.Add(0x82); - list[1] = (byte)(list.Count() - 3); - this.Write(sn, RequestType.xa7, ieee, list, 2); - } - - /// - /// 0081开始匹配遥控器 - /// - /// - /// - public void XA70081(string sn, string ieee, string version, [Range(1, 5)]byte type) - { - var list = new List - { - 0x03,//控制标志 - 0xff,//包长 - 0x00//包序号 - }; - list.AddRange(new byte[] { 0x55, 0x55 }); - list.Add(0x09); - list.AddRange(version.HexToBytes()); - list.AddRange(new byte[] { 0x81, 0x00 }); - list.Add(type); - list[1] = (byte)(list.Count() - 3 + 2); - list.Add((byte)list.Skip(3).Take(12).Select(o => (int)o).Sum()); - list.Add(0x0a); - this.Write(sn, RequestType.xa7, ieee, list, 2); - } - - public void XA70082(string sn, string ieee, byte type, ushort code) - { - var list = new List - { - 0x03,//控制标志 - 0xff,//包长 - 0x00//包序号 - }; - list.AddRange(new byte[] { 0x55, 0x55 }); - list.Add(0x0b); - using (var scope = _applicationServices.CreateScope()) - { - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = deviceRepo.Table().Include(o => o.Data).FirstOrDefault(o => o.GatewayNumber == sn && o.Number == ieee); - var version = device.GetDataValue(Keys.Version); - list.AddRange(version.HexToBytes()); - } - list.AddRange(new byte[] { 0x82, 0x00 }); - list.Add(type); - list.AddRange(BitConverter.GetBytes(code)); - list[1] = (byte)(list.Count() - 3 + 1); - list.Add((byte)list.Skip(5).Take(12).Select(o => (int)o).Sum()); - this.Write(sn, RequestType.xa7, ieee, list, 2); - } - - public void XA70083(string sn, string ieee, byte type, ushort code) - { - if (type == 1) - { - if (code <= 602) - { - throw new Exception($"code {code} must > 602 when type is {type} "); - } - } - else - { - if (code <= 43) - { - throw new Exception($"code {code} must > 43 when type is {type} "); - } - } - var list = new List - { - 0x03,//控制标志 - 0xff,//包长 - 0x00//包序号 - }; - list.AddRange(new byte[] { 0x55, 0x55 }); - list.Add(0x0b); - using (var scope = _applicationServices.CreateScope()) - { - var repo = scope.ServiceProvider.GetService>(); - var device = repo.ReadOnlyTable().Include(o => o.Data).FirstOrDefault(o => o.GatewayNumber == sn && o.Number == ieee); - var version = device.GetDataValue(Keys.Version); - list.AddRange(version.HexToBytes()); - } - list.AddRange(new byte[] { 0x83, 0x00 }); - list.Add(type); - list.AddRange(BitConverter.GetBytes(code)); - list[1] = (byte)(list.Count() - 3 + 2); - list.Add((byte)list.Skip(5).Take(12).Select(o => (int)o).Sum()); - list.Add(0x0a); - this.Write(sn, RequestType.xa7, ieee, list, 2); - } - - /// - /// 0xa9-0x27查询色温状态 - /// - public void XA9(string sn, string ieee) - { - var list = new List(); - this.Write(sn, RequestType.xa9, ieee, list); - } - - //0xac - //0xaf - //0xb0 - /// - /// 0x70设备上报信息 - /// - /// - /// - private void X70(string sn, byte[] data) - { - using (var ms = new MemoryStream(data)) - { - var responseType = ms.ReadByte(); - var dataLength = ms.ReadByte(); - var address = ms.ReadHexStringDesc(2); - var endpoint = ms.ReadByte(); - using (var scope = _applicationServices.CreateScope()) - { - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = this.GetDeviceByAddress(deviceRepo, sn, address); - var clusterId = (ClusterId)ms.ReadInt(); - if (device != null) - { - var deviceId = Convert.ToInt32(device.GetDataValue(Keys.DeviceId)); - var reportCount = ms.ReadByte(); - var props = new Dictionary(); - for (int i = 0; i < reportCount; i++) - { - var propId = ms.ReadInt(); - var propDataTypeValue = ms.ReadByte(); - int propDataLength; - if (Enum.IsDefined(typeof(FBeeDataType), propDataTypeValue)) - { - var propDataType = (FBeeDataType)propDataTypeValue; - if (propDataType == FBeeDataType.bitstring || propDataType == FBeeDataType.characterstring) - { - propDataLength = ms.ReadByte(); - } - else if (propDataType == FBeeDataType.longbitstring || propDataType == FBeeDataType.longcharacterstring) - { - propDataLength = ms.ReadInt(); - } - else if (propDataType == FBeeDataType.sequence || propDataType == FBeeDataType.set || propDataType == FBeeDataType.bag) - { - propDataLength = ms.ReadInt(); - } - else if (propDataType == FBeeDataType.unknown) - { - propDataLength = 0; - } - else - { - try - { - propDataLength = Convert.ToInt32(Regex.Match(propDataType.GetName(), @"(\d+)$").Groups[1].Value); - } - catch (Exception ex) - { - Console.WriteLine(ex.ToString()); - propDataLength = 1; - } - } - } - else - { - propDataLength = 1; - } - var propData = ms.Read(propDataLength); - props.Add(propId, propData); - } - if (clusterId == ClusterId.off) - { - var status = props.First().Value[0]; - if (status == 0x00)//离网 - { - deviceRepo.Delete(device); - deviceRepo.Delete(device); - } - else if (status == 0x03)//入网 - { - } - } - else if (clusterId == ClusterId.light) - { - device.AddorUpdateData(Keys.Light, BitConverter.ToInt16(props[0x0000]), DeviceDataType.Int, "光照度", "lux"); - } - else if (clusterId == ClusterId.alarm) - { - var state = BitConverter.ToInt16(props[0x0080]); - device.AddorUpdateData(Keys.Warning, state == 1 ? "报警" : "正常", DeviceDataType.String, "状态"); - device.AddorUpdateData(Keys.UnderVoltage, new BitArray(props[0x0080])[3], DeviceDataType.Int, "低电量"); - } - else if (clusterId == ClusterId.pm25) - { - device.AddorUpdateData(Keys.PM25, BitConverter.ToInt16(props[0x0000]), DeviceDataType.Int, "PM2.5", "μg/m³"); - device.AddorUpdateData(Keys.PM100, BitConverter.ToInt16(props[0x0002]), DeviceDataType.Int, "PM10", "μg/m³"); - device.AddorUpdateData(Keys.PM10, BitConverter.ToInt16(props[0x0001]), DeviceDataType.Int, "PM1.0", "μg/m³"); - } - else if (clusterId == ClusterId.temperature) - { - device.AddorUpdateData(Keys.Temperature, BitConverter.ToInt16(props[0x0000]) / 100f, DeviceDataType.Float, "温度", "℃"); - } - else if (clusterId == ClusterId.humidity) - { - device.AddorUpdateData(Keys.Humidity, BitConverter.ToInt16(props[0x0000]) / 100f, DeviceDataType.Float, "湿度", "RH%"); - } - else if (clusterId == ClusterId.voltage) - { - device.AddorUpdateData(Keys.Voltage, props[0x21][0] / 2f, DeviceDataType.Float, "电量"); - } - else if (clusterId == ClusterId.socket) - { - if (props.Keys.Contains(0x0000)) - { - var tempBytes = new List(); - tempBytes.AddRange(props[0x00]); - tempBytes.Add(0x00); - tempBytes.Add(0x00); - var electricity = BitConverter.ToInt64(tempBytes.ToArray()) / 1000f; - device.AddorUpdateData(Keys.Electricity, electricity, DeviceDataType.Long, "电量", "kw/h"); - } - } - if (deviceId == 0x0163) - { - if (props.ContainsKey(0x400a)) - { - var irdata = props[0x400a]; - if (irdata.Length == 10) - { - device.AddorUpdateData(Keys.Version, BitConverter.ToString((props[0x400a].Skip(3).Take(6).ToArray())).Replace("-", "").ToLower(), DeviceDataType.String, "红外版本"); - } - else - { - var irtype = BitConverter.ToInt16(irdata.Skip(9).Take(2).ToArray()); - if (irtype == 0x0082) - { - var irDeviceType = irdata.Skip(11).First(); - if (irDeviceType == 0x01) - { - var keyCode = BitConverter.ToInt16(irdata.Skip(12).Take(2).ToArray()); - device.AddorUpdateData(Keys.KeyPress, keyCode, DeviceDataType.Int, "按键"); - } - } - } - } - } - else if (deviceId == 0x0051) - { - if (clusterId == ClusterId.SummationDivisor) - { - this.X8D07020000(sn, device.Number); - } - } - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - } - } - } - - //0xb1 - //0xb2 - //0xc2 - //0xc3 - //0xc4 - //0xc5 - //0x75 - - #endregion api - - public void SetKeyCodeType(string sn, string ieee, string keyType, string value) - { - using (var scope = _applicationServices.CreateScope()) - { - var repo = scope.ServiceProvider.GetService>(); - var device = repo.Table().Include(o => o.Data).FirstOrDefault(o => o.GatewayNumber == sn && o.Number == ieee); - var data = device.Data.FirstOrDefault(o => o.Key == keyType); - if (data != null) - { - data.Value = value; - } - repo.SaveChanges(); - this.SendDevice(device); - } - } - - private Device GetDevice(IRepository deviceRepo, string sn, string ieee) - { - return deviceRepo.Table() - .Include(o => o.Data) - .FirstOrDefault(o => o.GatewayNumber == sn && o.Number == ieee); - } - - private Device GetDeviceByAddress(IRepository deviceRepo, string sn, string address) - { - return deviceRepo.Table() - .Include(o => o.Data) - .FirstOrDefault(o => o.GatewayNumber == sn && o.Data.Any(d => d.Key == Keys.Address && d.Value == address)); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Infrastructure/Keys.cs b/projects/IoT/IoTServices/FBeeService/Infrastructure/Keys.cs deleted file mode 100644 index 8ff7c445..00000000 --- a/projects/IoT/IoTServices/FBeeService/Infrastructure/Keys.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace FBeeService -{ - public static class Keys - { - public const string DeviceId = "DeviceId"; - public const string Address = "Address"; - public const string EndPoint = "EndPoint"; - public const string Version = "Version"; - public const string Electricity = "Electricity"; - public const string KeyPress = "KeyPress"; - public const string State = "State"; - public const string L1State = "L1State"; - public const string L2State = "L2State"; - public const string L3State = "L3State"; - public const string Battery = "Battery"; - public const string EndPointCount = "EndPointCount"; - public const string Data = "Data"; - public const string ZoneType = "ZoneType"; - public const string Brightness = "Brightness"; - public const string Hue = "Hue"; - public const string Saturation = "Saturation"; - public const string ColorTemperature = "ColorTemperature"; - public const string Light = "Light"; - public const string Warning = "Warning"; - public const string UnderVoltage = "UnderVoltage"; - public const string PM25 = "PM25"; - public const string PM100 = "PM100"; - public const string PM10 = "PM10"; - public const string Temperature = "Temperature"; - public const string Humidity = "Humidity"; - public const string Voltage = "Voltage"; - public const string DeviceCount = "DeviceCount"; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Program.cs b/projects/IoT/IoTServices/FBeeService/Program.cs deleted file mode 100644 index 6d36ec9e..00000000 --- a/projects/IoT/IoTServices/FBeeService/Program.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using Infrastructure.Application; -using Infrastructure.Configuration; -using Infrastructure.Extensions; -using Infrastructure.Web.Hosting; -using Microsoft.AspNetCore; - -namespace FBeeService -{ - public class Program - { - public static void Main(string[] args) - { - var host = "localhost"; - WebHost.CreateDefaultBuilder(args) - .Run(new List { - new EFConfigurationValue { Id = "openapi.name", Value= "v1" }, - new EFConfigurationValue { Id = "openapi.title", Value= "fbee api" }, - new EFConfigurationValue { Id = "openapi.version", Value= "1.0" }, - new EFConfigurationValue { Id = "security:key", Value= "111111111111111111111111"}, - new EFConfigurationValue { Id = "security:iv", Value= "11111111"}, - new EFConfigurationValue { Id = "email:host", Value= "nbaxp.com"}, - new EFConfigurationValue { Id = "email:port", Value= "25"}, - new EFConfigurationValue { Id = "email:user", Value= "admin@nbaxp.com"}, - new EFConfigurationValue { Id = "email:password", Value= "aA123456"}, - new EFConfigurationValue { Id = "server.ip", Value= "" }, - new EFConfigurationValue { Id = "server.urls", Value= "http://*:8009" }, - new EFConfigurationValue { Id = "notify:enabled", Value= "false"}, - new EFConfigurationValue { Id = "notify:host", Value= $"{host}:8001"}, - new EFConfigurationValue { Id = "timer.seconds", Value="600"}, - new EFConfigurationValue { Id = "connectId", Value= Guid.NewGuid().ToBase62() }, - new EFConfigurationValue { Id = "node.number", Value= "所属节点编号" }, - // - new EFConfigurationValue { Id = "name", Value= "FBeeService服务"}, - new EFConfigurationValue { Id = "logo", Value= "/images/logo.png",Type= InputType.ImageUrl}, - new EFConfigurationValue { Id = "copyright", Value= "Copyright © {now} Company. All rights reserved",Type= InputType.Html} - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Properties/launchSettings.json b/projects/IoT/IoTServices/FBeeService/Properties/launchSettings.json deleted file mode 100644 index bf677ea0..00000000 --- a/projects/IoT/IoTServices/FBeeService/Properties/launchSettings.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:8009/", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "OnvifService": { - "commandName": "Project", - "launchBrowser": true, - "applicationUrl": "http://127.0.0.1:8009/", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Startup.cs b/projects/IoT/IoTServices/FBeeService/Startup.cs deleted file mode 100644 index f8a93c01..00000000 --- a/projects/IoT/IoTServices/FBeeService/Startup.cs +++ /dev/null @@ -1,31 +0,0 @@ -using IoT.Shared.Infrastructure; -using IoT.UI.Shard; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace FBeeService -{ - public class Startup : IoTServiceStartup - { - public Startup(IConfiguration configuration, IHostingEnvironment env) : base(configuration, env) - { - } - - public override void ConfigureServices(IServiceCollection services) - { - services.AddSingleton(); - services.AddSingleton(); - base.ConfigureServices(services); - } - - public override void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) - { - base.Configure(app, env, loggerFactory); - app.ApplicationServices.GetService().Start(); - app.ApplicationServices.GetService().Start(); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Views/Home/Gateway.cshtml b/projects/IoT/IoTServices/FBeeService/Views/Home/Gateway.cshtml deleted file mode 100644 index a0b8def1..00000000 --- a/projects/IoT/IoTServices/FBeeService/Views/Home/Gateway.cshtml +++ /dev/null @@ -1,222 +0,0 @@ -@model List -@{ - this.HtmlTitle = "设备列表"; - var index = 0; -} -
- - - - - - - - - - - - - - - @foreach (var item in Model) - { - var deviceId = Convert.ToInt32(item.Data.FirstOrDefault(o => o.Key == "DeviceId").Value); - var address = item.Data.FirstOrDefault(o => o.Key == "Address").Value; - var voltage = item.Data.FirstOrDefault(o => o.Key == "Voltage")?.Value; - var state = item.Data.FirstOrDefault(o => o.Key == "State")?.Value; - var battery = item.Data.FirstOrDefault(o => o.Key == "Battery")?.Value; - - - - - - - - - - - - - - } -
编号名称类别地址电量在线状态设备状态连接Id操作删除
@(++index)@item.Number@item.Name@deviceId@address@voltage/@battery@Html.DisplayFor(o => item.IsOnline) - @if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId)) - { - @state - } - @if (deviceId == 0x0106) - { - @item.Data.FirstOrDefault(o => o.Key == "Light")?.Value - } - else if (deviceId == 0x0402) - { - @item.Data.FirstOrDefault(o => o.Key == "Warning")?.Value - } - else if (deviceId == 0x0309) - { - 温度:@item.Data.FirstOrDefault(o => o.Key == "Temperature")?.Value - 湿度:@item.Data.FirstOrDefault(o => o.Key == "Humidity")?.Value -
- PM 1.0:@item.Data.FirstOrDefault(o => o.Key == "PM10")?.Value - PM 2.5:@item.Data.FirstOrDefault(o => o.Key == "PM25")?.Value - PM 10:@item.Data.FirstOrDefault(o => o.Key == "PM100")?.Value - } - else if (deviceId == 0x0302) - { - 温度:@item.Data.FirstOrDefault(o => o.Key == "Temperature")?.Value - 湿度:@item.Data.FirstOrDefault(o => o.Key == "Humidity")?.Value - } - else if (deviceId == 0x0220) - { - 亮度:@item.Data.FirstOrDefault(o => o.Key == "Brightness")?.Value -
- 色调: @item.Data.FirstOrDefault(o => o.Key == "Hue")?.Value - 饱和度: @item.Data.FirstOrDefault(o => o.Key == "Saturation")?.Value -
- 色温:@item.Data.FirstOrDefault(o => o.Key == "ColorTemperature")?.Value - } - else if (deviceId == 0x0163) - { - var version = item.Data.FirstOrDefault(o => o.Key == "Version")?.Value; - if (!string.IsNullOrEmpty(version)) - { - 版本:@version - } - } - else if (deviceId == 0x0051) - { - var electricity = item.Data.FirstOrDefault(o => o.Key == "Electricity")?.Value; - if (!string.IsNullOrEmpty(electricity)) - { - 电量:@electricity - } - - } -
@item.ConnectId - @if (new int[] { 0x0002, 0x0009, 0x0081, 0x0202, 0x0220, 0x0051 }.Contains(deviceId)) - { - - - } - @if (deviceId == 0x0202) - { - - } - @if (deviceId == 0x0163) - { - 版本 - } - @if (deviceId == 0x0220) - { -
- - - -
-
- - - - -
-
- - - -
- } - @if (deviceId == 0x0163) - { -

发射:

-
- - - - -
-

空调:

-
- - -
- 开关: - - -
-
- 模式 - - - - - -
-
- -
-
- 风向 - - - -
-
- 风量 - - - - -
-
-

电视:

-
- - - - @{ - var tvKeys = new string[] { "POWR","AV","1","2","3","4","5","6","7","8","9","0", - "返回","退出","静音","菜单","音量+","音量-","上","下","左","右", - "OK","CH+>>|","CH-|<<","快退","快进","录像","暂停","停止","红","绿","黄","蓝", - "自定义","自定义","自定义","自定义","自定义","自定义","自定义","自定义"}; - } - @for (int i = 0; i < tvKeys.Length; i++) - { - - - @if (i % 5 == 0) - { -
- } - } -
-

学习:

-
- - - - -
- } -
删除设备
-
-@section scripts{ - -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Views/Home/Index.cshtml b/projects/IoT/IoTServices/FBeeService/Views/Home/Index.cshtml deleted file mode 100644 index 94a0b40b..00000000 --- a/projects/IoT/IoTServices/FBeeService/Views/Home/Index.cshtml +++ /dev/null @@ -1,33 +0,0 @@ -@model List -@{ - ViewBag.HideBread = true; -} - -
- - - - - - - - - - - @foreach (var item in Model) - { - - - - - - - - - - - } -
编号Ip地址启用用户名密码查询网关设备查看
@item.Number@item.Ip@Html.DisplayFor(o => item.Enable)@item.UserName@item.Password查询网关信息查询网关设备查看设备
-
\ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Views/Shared/_Menu.cshtml b/projects/IoT/IoTServices/FBeeService/Views/Shared/_Menu.cshtml deleted file mode 100644 index 29286277..00000000 --- a/projects/IoT/IoTServices/FBeeService/Views/Shared/_Menu.cshtml +++ /dev/null @@ -1,26 +0,0 @@ - -@functions{ - public string GetClass(params string[] controllers) - { - if (controllers.Select(o => o.ToLower()).Contains(this.ViewContext.RouteData.Values["controller"].ToString().ToLower())) - { - if (controllers.Length > 1) - { - return "active open"; - } - return "active"; - } - return ""; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Views/_ViewImports.cshtml b/projects/IoT/IoTServices/FBeeService/Views/_ViewImports.cshtml deleted file mode 100644 index 7b266683..00000000 --- a/projects/IoT/IoTServices/FBeeService/Views/_ViewImports.cshtml +++ /dev/null @@ -1,11 +0,0 @@ -@inherits Infrastructure.Web.Mvc.Razor.MyRazorPage -@using Microsoft.Extensions.Configuration -@using System.ComponentModel.DataAnnotations -@using Infrastructure.Application -@using Infrastructure.Web -@using Infrastructure.Web.DataAnnotations -@using Infrastructure.Extensions -@using Infrastructure.Data -@using Application.Domain.Entities -@using Application.Models -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Views/_ViewStart.cshtml b/projects/IoT/IoTServices/FBeeService/Views/_ViewStart.cshtml deleted file mode 100644 index a5f10045..00000000 --- a/projects/IoT/IoTServices/FBeeService/Views/_ViewStart.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -@{ - Layout = "_Layout"; -} diff --git a/projects/IoT/IoTServices/FBeeService/appsettings.Development.json b/projects/IoT/IoTServices/FBeeService/appsettings.Development.json deleted file mode 100644 index bb0aceca..00000000 --- a/projects/IoT/IoTServices/FBeeService/appsettings.Development.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - }, - "UseMiniProfiler": false -}. \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/appsettings.json b/projects/IoT/IoTServices/FBeeService/appsettings.json deleted file mode 100644 index ccd3bc47..00000000 --- a/projects/IoT/IoTServices/FBeeService/appsettings.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": "1.0.0-beta.108", - "Logging": { - "LogLevel": { - "Default": "Information" - } - }, - "AllowedHosts": "*", - "ConnectionStrings": { - "database.mysql.connection": "Server=127.0.0.1;Port=3306;Database=data;Uid=root;Pwd=root;", - "database.sqlite.connection": "Data Source=data.db" - }, - "AppSettings": { - "database": "sqlite", - "UseCookieSessionStore": false - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/wwwroot/favicon.ico b/projects/IoT/IoTServices/FBeeService/wwwroot/favicon.ico deleted file mode 100644 index 01872ed9..00000000 Binary files a/projects/IoT/IoTServices/FBeeService/wwwroot/favicon.ico and /dev/null differ diff --git a/projects/IoT/IoTServices/FBeeService/wwwroot/images/logo.png b/projects/IoT/IoTServices/FBeeService/wwwroot/images/logo.png deleted file mode 100644 index a80fbab7..00000000 Binary files a/projects/IoT/IoTServices/FBeeService/wwwroot/images/logo.png and /dev/null differ diff --git a/projects/IoT/IoTServices/ONVIFService/.gitignore b/projects/IoT/IoTServices/ONVIFService/.gitignore deleted file mode 100644 index 988994ff..00000000 --- a/projects/IoT/IoTServices/ONVIFService/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -*.bak -*.suo -*.db -*.user -.vs -obj -Obj -bin -Bin -debug -Debug -release -Release -Logs -logs -node_modules \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Application/Models/EditCameraModel.cs b/projects/IoT/IoTServices/ONVIFService/Application/Models/EditCameraModel.cs deleted file mode 100644 index aba15ef7..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Application/Models/EditCameraModel.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Infrastructure.Application; -using System.ComponentModel.DataAnnotations; - -namespace ONVIFService.Applicaiton.Models -{ - [Display(Name = "摄像头")] - public class EditCameraModel : EditModel - { - [Required] - [Display(Name = "编号")] - public string Number { get; set; } - - [Required] - [Display(Name = "设备地址")] - public string DeviceUrl { get; set; } - - [Required] - [Display(Name = "码流")] - public string Profiles { get; set; } - - [Display(Name = "流地址")] - public string StreamUri { get; set; } - - [Display(Name = "截图地址")] - public string SnapshotUri { get; set; } - - [Display(Name = "控制台地址")] - public string PtzAddress { get; set; } - - [Display(Name = "缩放支持")] - public bool Ptz3DZoomSupport { get; set; } - - [Display(Name = "需验证")] - public bool NeedAuth { get; set; } - - [Display(Name = "已验证")] - public bool HasAuth { get; set; } - - [Display(Name = "用户名")] - public string UserName { get; set; } - - [Display(Name = "密码")] - public string Password { get; set; } - - public string Rtmp1 { get; set; } - public string Flv1 { get; set; } - public string Hls1 { get; set; } - public string Rtmp2 { get; set; } - public string Flv2 { get; set; } - public string Hls2 { get; set; } - - [Display(Name = "启用")] - public bool Enabled { get; set; } - - [Display(Name = "推流")] - public bool Publish { get; set; } - - [Display(Name = "自定义参数")] - public bool UseCustomArguments { get; set; } - - [Display(Name = "自定义参数")] - public string Arguments { get; set; } - - [Display(Name = "自定义ffmpeg")] - public bool UseCustomFile { get; set; } - - [Display(Name = "ffmpeg")] - public string File { get; set; } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/DataController.cs b/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/DataController.cs deleted file mode 100644 index 2eb0834f..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/DataController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Linq; -using Application.Domain.Entities; -using Application.Models; -using Infrastructure.Data; -using Infrastructure.Extensions; -using Infrastructure.Web.Mvc; -using IoTShared.Controllers; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace IoTCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class DataController : CrudController - { - private readonly AjaxController _ajax; - - public DataController(IRepository repo, AjaxController ajax) : base(repo) - { - this._ajax = ajax; - } - - public override IQueryable Query(DataSearchModel model, IQueryable query) - { - ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId)); - ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetDeviceSelectList(model.NodeId.Value, model.DeviceId), model.NodeId.HasValue); - return query.WhereIf(model.NodeId.HasValue, o => o.Device.NodeId == model.NodeId.Value) - .WhereIf(model.DeviceId.HasValue, o => o.DeviceId == model.DeviceId.Value) - .WhereIf(!string.IsNullOrEmpty(model.Keyword), o => o.Name.Contains(model.Keyword)); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/DeviceController.cs b/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/DeviceController.cs deleted file mode 100644 index 2ec51328..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/DeviceController.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Application.Domain.Entities; -using Application.Models; -using Infrastructure.Data; -using Infrastructure.Web.Mvc; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace IoTCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class DeviceController : CrudController - { - public DeviceController(IRepository repo) : base(repo) - { - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/HomeController.cs b/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/HomeController.cs deleted file mode 100644 index acba2d08..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Controllers/HomeController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace UserCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class HomeController : Controller - { - public HomeController() - { - } - - public IActionResult Index() - { - return View(); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Home/Index.cshtml b/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Home/Index.cshtml deleted file mode 100644 index f551b40e..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Home/Index.cshtml +++ /dev/null @@ -1,4 +0,0 @@ -@{ - ViewData["IsHomePage"] = true; -} -

首页

\ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Shared/_Menu.cshtml b/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Shared/_Menu.cshtml deleted file mode 100644 index ff034510..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Shared/_Menu.cshtml +++ /dev/null @@ -1,52 +0,0 @@ - -@functions{ - public string GetClass(params string[] controllers) - { - if (controllers.Select(o => o.ToLower()).Contains(this.ViewContext.RouteData.Values["controller"].ToString().ToLower())) - { - if (controllers.Length > 1) - { - return "active open"; - } - return "active"; - } - return ""; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Shared/_Script.cshtml b/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Shared/_Script.cshtml deleted file mode 100644 index 33c931f6..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/Shared/_Script.cshtml +++ /dev/null @@ -1,24 +0,0 @@ - \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/_ViewImports.cshtml b/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/_ViewImports.cshtml deleted file mode 100644 index f99ab108..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/_ViewImports.cshtml +++ /dev/null @@ -1,7 +0,0 @@ -@inherits Infrastructure.Web.Mvc.Razor.MyRazorPage -@using Infrastructure.Application -@using Infrastructure.Extensions -@using Infrastructure.Data -@using Application.Domain.Entities -@using Application.Models -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/_ViewStart.cshtml b/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/_ViewStart.cshtml deleted file mode 100644 index d641c67f..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Areas/Admin/Views/_ViewStart.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -@{ - Layout = "_Layout"; -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Controllers/AccountController.cs b/projects/IoT/IoTServices/ONVIFService/Controllers/AccountController.cs deleted file mode 100644 index 6a255af5..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Controllers/AccountController.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Application.Domain.Entities; -using Infrastructure.Data; -using Infrastructure.Email; -using Infrastructure.Resources; -using Infrastructure.Security; -using IoT.UI.Shard.Controllers; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Localization; - -namespace ONVIFService.Controllers -{ - public class AccountController : BaseAccountController - { - public AccountController(IConfiguration configuration, - IRepository userRepo, - IEncryptionService encryptionService, - IStringLocalizer localizer, - IEmailSender emaliSender) : base(configuration, userRepo, encryptionService, localizer, emaliSender) - { - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Controllers/CameraController.cs b/projects/IoT/IoTServices/ONVIFService/Controllers/CameraController.cs deleted file mode 100644 index ea5b923b..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Controllers/CameraController.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Application.Models; -using IoT.Shared.Controllers; -using Microsoft.AspNetCore.Mvc; -using Swashbuckle.AspNetCore.Annotations; -using System; - -namespace ONVIFService.Controllers -{ - [SwaggerTag("摄像头")] - public class CameraController : BaseDeviceController - { - private readonly DeviceService _deviceService; - - public CameraController(IServiceProvider applicationServices, DeviceService deviceService) : base(applicationServices) - { - this._deviceService = deviceService; - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("截屏")] - public ApiResponse ScreenShot([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.ScreenShot(number); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("上")] - public ApiResponse Up([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.Up(number, 0.5f); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("下")] - public ApiResponse Down([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.Down(number, 0.5f); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("左")] - public ApiResponse Left([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.Left(number, 0.5f); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("右")] - public ApiResponse Right([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.Right(number, 0.5f); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("大")] - public ApiResponse Zoomin([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.ZoomIn(number, 0.5f); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("小")] - public ApiResponse Zoomout([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.ZoomOut(number, 0.5f); - }); - } - - [HttpGet, Route("/[controller]/[action]"), SwaggerOperation("停")] - public ApiResponse Stop([SwaggerParameter("网关编号")]string gateway, [SwaggerParameter("设备编号")]string number) - { - return this.AsyncAction(() => - { - this._deviceService.Stop(number); - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Controllers/HomeController.cs b/projects/IoT/IoTServices/ONVIFService/Controllers/HomeController.cs deleted file mode 100644 index 536a1428..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Controllers/HomeController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Application.Domain.Entities; -using Infrastructure.Data; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using System.Linq; - -namespace ONVIFService.Controllers -{ - public class HomeController : Controller - { - private readonly IRepository _cameraRepo; - private readonly DeviceService _onvifService; - - public HomeController(DeviceService onvifService, IRepository cameraRepo) - { - this._cameraRepo = cameraRepo; - this._onvifService = onvifService; - } - - public IActionResult Index() - { - var model = this._cameraRepo.ReadOnlyTable().Include(o => o.Data).ToList(); - return View(model); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Infrastructure/DeviceService.cs b/projects/IoT/IoTServices/ONVIFService/Infrastructure/DeviceService.cs deleted file mode 100644 index de8626bf..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Infrastructure/DeviceService.cs +++ /dev/null @@ -1,518 +0,0 @@ -using Application.Domain.Entities; -using Infrastructure.Data; -using Infrastructure.Extensions; -using Infrastructure.Models; -using IoT.Shared.Infrastructure; -using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Concurrent; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Net.Http; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading; - -namespace ONVIFService -{ - public class DeviceService : BaseDeviceService - { - private readonly ConcurrentDictionary _list = new ConcurrentDictionary(); - private readonly IHostingEnvironment _env; - private readonly IHttpClientFactory _httpClientFactory; - private readonly IOnvifDeviceManagement _onvifDeviceManagement; - - public DeviceService(IServiceProvider applicationServices, IConfiguration configuration, IHostingEnvironment env, IHttpClientFactory httpClientFactory) - : base(applicationServices, configuration) - { - this._env = env; - this._httpClientFactory = httpClientFactory; - this._onvifDeviceManagement = new OnvifDeviceManagement(httpClientFactory); - } - - #region impl interface - - public override void Execute() - { - Refresh(); - } - - public override void Stop() - { - try - { - this._tokenSource.Cancel(); - foreach (var item in this._list.Keys.ToList()) - { - this.Remove(item); - } - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - - #endregion impl interface - - private void Refresh() - { - try - { - Search(); - Notify(); - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - - public void Search() - { - try - { - var list = this._onvifDeviceManagement.Discovery(); - foreach (var ipCamera in list) - { - if (string.IsNullOrEmpty(ipCamera.Id) || string.IsNullOrEmpty(ipCamera.DeviceUrl)) - { - continue; - } - Console.WriteLine(ipCamera.DeviceUrl); - using (var scope = _applicationServices.CreateScope()) - { - var deviceInfoNumber = "onvifcamera"; - var deviceInfoRepo = scope.ServiceProvider.GetService>(); - var deviceInfo = deviceInfoRepo.Table().FirstOrDefault(o => o.Number == deviceInfoNumber); - if (deviceInfo == null) - { - deviceInfo = new DeviceInfo - { - Number = deviceInfoNumber, - Name = "ONVIF摄像头", - DeviceType = DeviceType.Gateway, - ApiJson = this.GetApiJson("/Camera/") - }; - deviceInfoRepo.Add(deviceInfo); - deviceInfoRepo.SaveChanges(); - this.SendDeviceInfo(deviceInfo); - } - var deviceRepo = scope.ServiceProvider.GetService>(); - var device = deviceRepo.Table().Include(o => o.Data).FirstOrDefault(o => o.Number == ipCamera.Id); - if (device == null) - { - device = new Device - { - Name = "摄像头", - Number = ipCamera.Id, - Icon = "camera", - CategoryNumber = "10", - InfoNumber = deviceInfoNumber, - InfoId = deviceInfo.Id - }; - device.AddorUpdateData("mainrtmp", $"rtmp://{this._configuration["stream.rtmp"]}/live/main{ipCamera.Id}", DeviceDataType.String, "主码流rtmp"); - device.AddorUpdateData("mainflv", $"http://{this._configuration["stream.flv"]}/live/main{ipCamera.Id}.flv", DeviceDataType.String, "主码流flv"); - device.AddorUpdateData("mainhls", $"http://{this._configuration["stream.hls"]}/live/main{ipCamera.Id}.m3u8", DeviceDataType.String, "主码流hls"); - device.AddorUpdateData("subrtmp", $"rtmp://{this._configuration["stream.rtmp"]}/live/sub{ipCamera.Id}", DeviceDataType.String, "子码流rtmp"); - device.AddorUpdateData("subflv", $"http://{this._configuration["stream.flv"]}/live/sub{ipCamera.Id}.flv", DeviceDataType.String, "子码流flv"); - device.AddorUpdateData("subhls", $"http://{this._configuration["stream.hls"]}/live/sub{ipCamera.Id}.m3u8", DeviceDataType.String, "子码流hls"); - device.AddorUpdateData("ffmpeg.file", this._configuration["ffmpeg.file"], DeviceDataType.String, "ffmpeg.file", hidden: true); - device.AddorUpdateData("ffmpeg.args", this._configuration["ffmpeg.args"], DeviceDataType.String, "ffmpeg.args", hidden: true); - device.AddorUpdateData("CustomFile", "", DeviceDataType.String, "自定义ffmpeg路径", hidden: true); - device.ConnectId = this._configuration["connectId"]; - device.NodeNumber = this._configuration["node.number"]; - deviceRepo.Add(device); - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - var profiles = this._onvifDeviceManagement.GetProfiles(ipCamera.DeviceUrl, ipCamera.MediaUrl); - var needAuth = false; - var hasAuth = false; - if (profiles == "") - { - needAuth = true; - device.UserName = device.UserName ?? this._configuration["camera.usr"]; - device.Password = device.Password ?? this._configuration["camera.pwd"]; - profiles = this._onvifDeviceManagement.GetProfiles(ipCamera.DeviceUrl, ipCamera.MediaUrl, device.UserName, device.Password); - if (profiles == "") - { - hasAuth = false; - } - else - { - hasAuth = true; - ipCamera.GetProfilesXml = profiles; - } - } - else - { - ipCamera.GetProfilesXml = profiles; - } - ipCamera.ParseProfiles(); - - if (needAuth) - { - ipCamera.MainStreamUriXml = this._onvifDeviceManagement.GetStreamUri(ipCamera.DeviceUrl, ipCamera.MediaUrl, device.UserName, device.Password, ipCamera.Profiles.First().Token); - ipCamera.MainSnapshotUriXml = this._onvifDeviceManagement.GetSnapshotUri(ipCamera.DeviceUrl, ipCamera.MediaUrl, device.UserName, device.Password, ipCamera.Profiles.First().Token); - ipCamera.SubStreamUriXml = this._onvifDeviceManagement.GetStreamUri(ipCamera.DeviceUrl, ipCamera.MediaUrl, device.UserName, device.Password, ipCamera.Profiles.Last().Token); - ipCamera.SubSnapshotUriXml = this._onvifDeviceManagement.GetSnapshotUri(ipCamera.DeviceUrl, ipCamera.MediaUrl, device.UserName, device.Password, ipCamera.Profiles.Last().Token); - } - else - { - ipCamera.MainStreamUriXml = this._onvifDeviceManagement.GetStreamUri(ipCamera.DeviceUrl, ipCamera.MediaUrl, ipCamera.Profiles.First().Token); - ipCamera.MainSnapshotUriXml = this._onvifDeviceManagement.GetSnapshotUri(ipCamera.DeviceUrl, ipCamera.MediaUrl, ipCamera.Profiles.First().Token); - ipCamera.SubStreamUriXml = this._onvifDeviceManagement.GetStreamUri(ipCamera.DeviceUrl, ipCamera.MediaUrl, ipCamera.Profiles.Last().Token); - ipCamera.SubSnapshotUriXml = this._onvifDeviceManagement.GetSnapshotUri(ipCamera.DeviceUrl, ipCamera.MediaUrl, ipCamera.Profiles.Last().Token); - } - ipCamera.ParseStreamUri(); - ipCamera.ParseSnapshotUri(); - device.AddorUpdateData("NeedAuth", needAuth ? "是" : "否", DeviceDataType.String, "需认证"); - device.AddorUpdateData("HasAuth", hasAuth ? "是" : "否", DeviceDataType.String, "已认证"); - device.AddorUpdateData("DeviceUrl", ipCamera.DeviceUrl, DeviceDataType.String, "设备地址"); - device.AddorUpdateData("PtzAddress", ipCamera.PTZAddress, DeviceDataType.String, "云台地址"); - device.AddorUpdateData("Ptz3DZoomSupport", ipCamera.Ptz3DZoomSupport ? "是" : "否", DeviceDataType.String, "缩放支持"); - device.AddorUpdateData("MainToken", ipCamera.Profiles.First().Token, DeviceDataType.String, "主码流Token"); - device.AddorUpdateData("SubToken", ipCamera.Profiles.Last().Token, DeviceDataType.String, "子码流Token"); - device.AddorUpdateData("MainStreamUri", ipCamera.MainStreamUri, DeviceDataType.String, "主码流地址"); - device.AddorUpdateData("MainSnapshotUri", ipCamera.MainSnapshotUri, DeviceDataType.String, "主码流截图地址"); - device.AddorUpdateData("SubStreamUri", ipCamera.SubStreamUri, DeviceDataType.String, "子码流地址"); - device.AddorUpdateData("SubSnapshotUri", ipCamera.SubSnapshotUri, DeviceDataType.String, "子码流截图地址"); - deviceRepo.SaveChanges(); - this.SendDevice(device); - } - } - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - - public void Notify() - { - using (var scope = _applicationServices.CreateScope()) - { - var repo = scope.ServiceProvider.GetService>(); - var cameras = repo.ReadOnlyTable().Include(o => o.Data).Where(o => o.Enable).ToList(); - foreach (var key in this._list.Keys) - { - var camera = cameras.FirstOrDefault(o => o.Number == key); - var remove = false; - if (!camera.Enable) - { - remove = true; - } - if (camera.Data.FirstOrDefault(o => o.Key == "NeedAuth").Value == "是" && camera.Data.FirstOrDefault(o => o.Key == "HasAuth").Value == "否") - { - remove = true; - } - if (remove) - { - this.Remove(key); - } - } - foreach (var camera in cameras) - { - try - { - if (camera.Enable) - { - if (camera.Data.FirstOrDefault(o => o.Key == "NeedAuth").Value == "否" || camera.Data.FirstOrDefault(o => o.Key == "HasAuth").Value == "是") - { - this.Publish(camera); - } - } - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - } - } - - private void Publish(Device camera) - { - try - { - if (!this._list.Any(o => o.Key == camera.Number)) - { - this.Add(camera); - } - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - - public void Add(string key) - { - using (var scope = _applicationServices.CreateScope()) - { - var repo = scope.ServiceProvider.GetService>(); - var camera = repo.ReadOnlyTable().Include(o => o.Data).FirstOrDefault(o => o.Number == key); - if (camera != null && camera.Enable)// && camera.Publish && (!camera.NeedAuth || (camera.NeedAuth && camera.HasAuth))) - { - if (camera.Data.FirstOrDefault(o => o.Key == "NeedAuth").Value == "否" || camera.Data.FirstOrDefault(o => o.Key == "HasAuth").Value == "是") - { - this.Add(camera); - } - } - } - } - - public void Add(Device camera) - { - if (this._list.Any(o => o.Key == camera.Number)) - { - return; - } - var needAuth = camera.Data.FirstOrDefault(o => o.Key == "NeedAuth").Value == "是"; - var hasAuth = camera.Data.FirstOrDefault(o => o.Key == "HasAuth").Value == "是"; - var mainStreamUri = camera.Data.FirstOrDefault(o => o.Key == "MainStreamUri").Value; - var mainRtspUrl = $"rtsp://{(needAuth ? $"{camera.UserName}:{camera.Password}@" : "")}{mainStreamUri.Substring(7)}"; - var subStreamUri = camera.Data.FirstOrDefault(o => o.Key == "SubStreamUri").Value; - var subRtspUrl = $"rtsp://{(needAuth ? $"{camera.UserName}:{camera.Password}@" : "")}{subStreamUri.Substring(7)}"; - var fileName = $"ffmpeg-{Helper.Instance.GetRunTime()}{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")}"; - var file = Path.Combine(this._env.WebRootPath, fileName); - var mainRtmp = camera.Data.FirstOrDefault(o => o.Key == "mainrtmp").Value; - var subRtmp = camera.Data.FirstOrDefault(o => o.Key == "subrtmp").Value; - var customFile = camera.GetData("CustomFile")?.Value; - if (!string.IsNullOrEmpty(customFile)) - { - file = customFile; - } - Console.WriteLine(file); - var arguments = camera.Data.FirstOrDefault(o => o.Key == "ffmpeg.args").Value; - Process main = null, sub = null; - if (!string.IsNullOrEmpty(mainStreamUri)) - { - if (!string.IsNullOrEmpty(mainRtmp)) - { - main = this.SetProcess(file, string.Format(arguments, Environment.ProcessorCount, mainRtspUrl, mainRtmp)); - } - if (!string.IsNullOrEmpty(subRtmp)) - { - sub = this.SetProcess(file, string.Format(arguments, Environment.ProcessorCount, subRtspUrl, subRtmp)); - } - } - if (this._list.TryAdd(camera.Number, (camera, main, sub))) - { - Console.WriteLine($"add {camera.Number} to list"); - } - else - { - if (main != null) - { - this.CloseProcess(main); - this.CloseProcess(sub); - } - } - } - - public void Remove(string key) - { - var item = this._list[key]; - this.CloseProcess(item.local); - this.CloseProcess(item.remote); - if (this._list.TryRemove(key, out item)) - { - Console.WriteLine($"remove {key} from list"); - } - } - - private Process SetProcess(string file, string arguments) - { - Console.WriteLine(file); - var process = new Process - { - StartInfo = new ProcessStartInfo - { - WorkingDirectory = this._env.WebRootPath, - FileName = file, - Arguments = arguments, - UseShellExecute = false, - CreateNoWindow = true, - RedirectStandardError = true - }, - EnableRaisingEvents = true - }; - process.Exited += (s, e) => - { - var _process = s as Process; - Console.WriteLine($"list:{_list.Count},exit:{_process.ExitCode},args:{arguments}"); - if (_process != null) - { - Thread.Sleep(10 * 1000); - _process.CancelErrorRead(); - _process.Start(); - _process.BeginErrorReadLine(); - } - }; - process.ErrorDataReceived += (s, e) => - { - if (!string.IsNullOrEmpty(e.Data)) - { - //Console.WriteLine(e.Data); - if (e.Data.IndexOf("forcing output") > -1) - { - process.Kill(); - } - } - }; - Console.WriteLine(arguments); - process.Start(); - process.BeginErrorReadLine(); - return process; - } - - private void CloseProcess(Process process) - { - if (process != null) - { - process.EnableRaisingEvents = false; - try - { - process.Kill(); - process.WaitForExit(); - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - } - - private string GetOnoce(string deviceUrl) - { - var message = @" - - - - "; - var hc = this._httpClientFactory.CreateClient(); - hc.DefaultRequestHeaders.Add("ContentType", $"application/soap+xml; charset=utf-8; action=\"{Template.GetDeviceInformationAction}\""); - var task = hc.PostAsync(deviceUrl, new StringContent(message)); - var result = task.Result.Headers.WwwAuthenticate; - return Regex.Match(result.ToString(), "nonce=\"([^\"]+)\"").Groups[1].Value; - } - - private string RequestXml(string url, string action, string body, string userName, string password, string onoce) - { - var nonce_b = Convert.FromBase64String(onoce); - var now = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ss.fffZ"); - var creationtime_b = Encoding.ASCII.GetBytes(now); - var password_b = Encoding.ASCII.GetBytes(password); - var concatenation_b = new byte[nonce_b.Length + creationtime_b.Length + password_b.Length]; - Buffer.BlockCopy(nonce_b, 0, concatenation_b, 0, nonce_b.Length); - Buffer.BlockCopy(creationtime_b, 0, concatenation_b, nonce_b.Length, creationtime_b.Length); - Buffer.BlockCopy(password_b, 0, concatenation_b, nonce_b.Length + creationtime_b.Length, password_b.Length); - var sha = new SHA1CryptoServiceProvider(); - var pdresult = sha.ComputeHash(concatenation_b); - var passworddigest = Convert.ToBase64String(pdresult); - var message = string.Format(Template.AuthTemplate, userName, passworddigest, Convert.ToBase64String(nonce_b), now, body); - var result = SoapRequest(url, action, message); - return result; - } - - private string SoapRequest(string url, string action, string message) - { - var hc = this._httpClientFactory.CreateClient(); - hc.DefaultRequestHeaders.Add("ContentType", $"application/soap+xml; charset=utf-8; action=\"{action}\""); - var task = hc.PostAsync(url, new StringContent(message)); - var result = task.Result.Content.ReadAsStringAsync().Result; - return result; - } - - public void ZoomIn(string id, float speed) - { - this.Move(id, speed, 0, 0); - } - - public void ZoomOut(string id, float speed) - { - this.Move(id, -speed, 0, 0); - } - - public void Up(string id, float speed) - { - this.Move(id, 0, 0, speed); - } - - public void Right(string id, float speed) - { - this.Move(id, 0, speed, 0); - } - - public void Down(string id, float speed) - { - this.Move(id, 0, 0, -speed); - } - - public void Left(string id, float speed) - { - this.Move(id, 0, -speed, 0); - } - - public void Stop(string id) - { - var camera = this.GetCamera(id); - if (camera != null) - { - var ptzAddress = camera.GetDataValue("PtzAddress"); - if (!string.IsNullOrEmpty(ptzAddress)) - { - var deviceUrl = camera.GetDataValue("DeviceUrl"); - RequestXml(ptzAddress, Template.StopAction, String.Format(Template.StopMessage, camera.GetDataValue("MainToken"), true, true), camera.UserName, camera.Password, GetOnoce(deviceUrl)); - } - } - } - - public void Move(string id, float zx, float px, float py) - { - var camera = this.GetCamera(id); - if (camera != null) - { - var ptzAddress = camera.GetDataValue("PtzAddress"); - if (!string.IsNullOrEmpty(ptzAddress)) - { - var deviceUrl = camera.GetDataValue("DeviceUrl"); - RequestXml(ptzAddress, Template.ContinuousMoveAction, String.Format(Template.ContinuousMoveMessage, camera.GetDataValue("MainToken"), zx, px, py), camera.UserName, camera.Password, GetOnoce(deviceUrl)); - } - } - } - - public byte[] ScreenShot(string id) - { - var camera = this.GetCamera(id); - var url = camera.GetDataValue("SnapshotUri"); - 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); - } - - private Device GetCamera(string number) - { - using (var scope = _applicationServices.CreateScope()) - { - var repo = scope.ServiceProvider.GetService>(); - return repo.ReadOnlyTable().Include(o => o.Data).FirstOrDefault(o => o.Number == number); - } - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Infrastructure/IOnvifDeviceManagement.cs b/projects/IoT/IoTServices/ONVIFService/Infrastructure/IOnvifDeviceManagement.cs deleted file mode 100644 index 8ddbbc2c..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Infrastructure/IOnvifDeviceManagement.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; - -namespace ONVIFService -{ - public interface IOnvifDeviceManagement - { - List Discovery(); - - string GetCapabilities(string deviceUrl); - - string GetProfiles(string deviceUrl, string mediaUrl); - - string GetProfiles(string deviceUrl, string mediaUrl, string userName, string password); - - string GetStreamUri(string deviceUrl, string mediaUrl, string token); - - string GetStreamUri(string deviceUrl, string mediaUrl, string userName, string password, string token); - - string GetSnapshotUri(string deviceUrl, string mediaUrl, string token); - - string GetSnapshotUri(string deviceUrl, string mediaUrl, string userName, string password, string token); - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Infrastructure/IPCamera.cs b/projects/IoT/IoTServices/ONVIFService/Infrastructure/IPCamera.cs deleted file mode 100644 index 7181d494..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Infrastructure/IPCamera.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text.RegularExpressions; -using System.Xml.Linq; - -namespace ONVIFService -{ - public class IPCamera - { - public string DiscoveryXml { get; set; } - public string GetCapabilitiesXml { get; set; } - public string DeviceUrl { get; set; } - public string Id { get; set; } - public string MediaUrl { get; set; } - public string GetProfilesXml { get; set; } - public string UserName { get; set; } - public string Password { get; set; } - public string PTZAddress { get; set; } - public bool Ptz3DZoomSupport { get; set; } - public List Profiles { get; set; } = new List(); - public string MainStreamUriXml { get; set; } - public string MainSnapshotUriXml { get; set; } - public string SubStreamUriXml { get; set; } - public string SubSnapshotUriXml { get; set; } - public string MainStreamUri { get; set; } - public string SubStreamUri { get; set; } - public string MainSnapshotUri { get; set; } - public string SubSnapshotUri { get; set; } - - public void ParseDiscovery() - { - var doc = XDocument.Parse(this.DiscoveryXml); - this.DeviceUrl = doc.Descendants().FirstOrDefault(o => o.Name.LocalName == "XAddrs").Value.Split(' ')[0]; - this.Id = doc.Descendants() - .FirstOrDefault(o => o.Name.LocalName == "EndpointReference").Elements() - .FirstOrDefault(o => o.Name.LocalName == "Address").Value.Replace("urn:uuid:", "").Replace("-", ""); - } - - public void ParseCapabilities() - { - var doc = XDocument.Parse(this.GetCapabilitiesXml); - this.MediaUrl = doc.Descendants().FirstOrDefault(o => o.Name.LocalName == "Media").Elements().FirstOrDefault(o => o.Name.LocalName == "XAddr").Value; - this.PTZAddress = doc.Descendants().FirstOrDefault(o => o.Name.LocalName == "PTZ")?.Elements().FirstOrDefault(o => o.Name.LocalName == "XAddr")?.Value; - this.Ptz3DZoomSupport = string.IsNullOrWhiteSpace(this.PTZAddress) ? false : true; - } - - public void ParseProfiles() - { - var doc = XDocument.Parse(this.GetProfilesXml); - foreach (var item in doc.Descendants().Where(o => o.Name.LocalName == "Profiles")) - { - var profile = new Profile - { - Token = item.Attribute("token").Value, - Name = item.Elements().FirstOrDefault(o => o.Name.LocalName == "Name").Value - }; - var videoEncoderConfiguration = item.Elements().FirstOrDefault(o => o.Name.LocalName == "VideoEncoderConfiguration"); - profile.Encoding = videoEncoderConfiguration.Elements().FirstOrDefault(o => o.Name.LocalName == "Encoding").Value; - var resolution = videoEncoderConfiguration.Elements().FirstOrDefault(o => o.Name.LocalName == "Resolution"); - profile.Width = Convert.ToInt32(resolution.Elements().FirstOrDefault(o => o.Name.LocalName == "Width").Value); - profile.Height = Convert.ToInt32(resolution.Elements().FirstOrDefault(o => o.Name.LocalName == "Height").Value); - this.Profiles.Add(profile); - } - } - - public void ParseStreamUri() - { - this.MainStreamUri = WebUtility.HtmlDecode(this.RegexMatch(this.MainStreamUriXml, @"[^<>]*", @"", @"")); - this.SubStreamUri = WebUtility.HtmlDecode(this.RegexMatch(this.SubStreamUriXml, @"[^<>]*", @"", @"")); - } - - public void ParseSnapshotUri() - { - this.MainSnapshotUri = WebUtility.HtmlDecode(this.RegexMatch(this.MainSnapshotUriXml, @"[^<>]*", @"", @"")); - this.SubSnapshotUri = WebUtility.HtmlDecode(this.RegexMatch(this.SubSnapshotUriXml, @"[^<>]*", @"", @"")); - } - - private string RegexMatch(string input, string pattern, string prefix, string suffix) - { - return Regex.Match(input, $"(?<={prefix}){pattern}(?={suffix})").Value; - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Infrastructure/OnvifDeviceManagement.cs b/projects/IoT/IoTServices/ONVIFService/Infrastructure/OnvifDeviceManagement.cs deleted file mode 100644 index 465fbd54..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Infrastructure/OnvifDeviceManagement.cs +++ /dev/null @@ -1,181 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.NetworkInformation; -using System.Net.Sockets; -using System.Security.Cryptography; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading; -using System.Threading.Tasks; -using Infrastructure.Extensions; - -namespace ONVIFService -{ - public class OnvifDeviceManagement : IOnvifDeviceManagement - { - private readonly IHttpClientFactory _httpClientFactory; - private readonly object thisLock = new object(); - - public OnvifDeviceManagement(IHttpClientFactory httpClientFactory) - { - this._httpClientFactory = httpClientFactory; - } - - public List Discovery() - { - Console.WriteLine("search onvif devices..."); - var list = new ConcurrentBag(); - var ips = NetworkInterface.GetAllNetworkInterfaces() - .Where(nic => nic.OperationalStatus == OperationalStatus.Up && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback) - .Select(nic => nic.GetIPProperties().UnicastAddresses) - .SelectMany(o => o.ToList()) - .Select(o => o.Address) - .Where(o => o.AddressFamily == AddressFamily.InterNetwork) - .ToList(); - foreach (var ip in ips) - { - Console.WriteLine($"search:{ip}"); - lock (thisLock) - { - try - { - var tokenSource = new CancellationTokenSource(); - using (var client = new UdpClient(new IPEndPoint(ip, 0))) - { - var probeMessage = string.Format(Template.GetServiceRequestTemplage, Guid.NewGuid()); - var message = Encoding.UTF8.GetBytes(probeMessage); - client.Send(message, message.Length, new IPEndPoint(IPAddress.Parse("239.255.255.250"), 3702)); - Task.Run(() => - { - try - { - var ep = new IPEndPoint(IPAddress.Any, 3702); - while (!tokenSource.IsCancellationRequested) - { - if (client.Available > 0) - { - var buffer = client.Receive(ref ep); - var result = Encoding.UTF8.GetString(buffer); - if (!list.Any(o => o == result)) - { - list.Add(result); - } - } - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - }, tokenSource.Token); - Thread.Sleep(1000); - tokenSource.Cancel(); - } - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - } - var cameras = new List(); - foreach (var item in list) - { - var camera = new IPCamera { DiscoveryXml = item }; - try - { - camera.ParseDiscovery(); - camera.GetCapabilitiesXml = GetCapabilities(camera.DeviceUrl); - camera.ParseCapabilities(); - cameras.Add(camera); - } - catch (Exception ex) - { - ex.PrintStack(); - } - } - return cameras; - } - - public string GetCapabilities(string deviceUrl) - { - return SoapRequest(deviceUrl, Template.GetCapabilitiesAction, Template.GetCapabilitiesMessage); - } - - public string GetProfiles(string deviceUrl, string mediaUrl) - { - return SoapRequest(mediaUrl, Template.GetProfilesAction, string.Format(Template.Templage, Template.GetProfilesMessageBody)); - } - - public string GetProfiles(string deviceUrl, string mediaUrl, string userName, string password) - { - return RequestXml(mediaUrl, Template.GetProfilesAction, Template.GetProfilesMessageBody, userName, password, GetOnoce(deviceUrl)); - } - - public string GetStreamUri(string deviceUrl, string mediaUrl, string token) - { - return SoapRequest(mediaUrl, Template.GetStreamUriAction, string.Format(Template.Templage, String.Format(Template.GetStreamUriMessage, token))); - } - - public string GetStreamUri(string deviceUrl, string mediaUrl, string userName, string password, string token) - { - return RequestXml(mediaUrl, Template.GetStreamUriAction, String.Format(Template.GetStreamUriMessage, token), userName, password, GetOnoce(deviceUrl)); - } - - public string GetSnapshotUri(string deviceUrl, string mediaUrl, string token) - { - return SoapRequest(mediaUrl, Template.GetSnapshotUriAction, string.Format(Template.Templage, String.Format(Template.GetSnapshotUriMessage, token))); - } - - public string GetSnapshotUri(string deviceUrl, string mediaUrl, string userName, string password, string token) - { - return RequestXml(mediaUrl, Template.GetSnapshotUriAction, String.Format(Template.GetSnapshotUriMessage, token), userName, password, GetOnoce(deviceUrl)); - } - - private string SoapRequest(string url, string action, string message) - { - var hc = this._httpClientFactory.CreateClient(); - hc.DefaultRequestHeaders.Add("ContentType", $"application/soap+xml; charset=utf-8; action=\"{action}\""); - var task = hc.PostAsync(url, new StringContent(message)); - var result = task.Result; - var content = result.Content.ReadAsStringAsync().Result; - return result.StatusCode == HttpStatusCode.OK ? content : ""; - } - - private string RequestXml(string url, string action, string body, string userName, string password, string onoce) - { - var nonce_b = Convert.FromBase64String(onoce); - var now = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ss.fffZ"); - var creationtime_b = Encoding.ASCII.GetBytes(now); - var password_b = Encoding.ASCII.GetBytes(password); - var concatenation_b = new byte[nonce_b.Length + creationtime_b.Length + password_b.Length]; - Buffer.BlockCopy(nonce_b, 0, concatenation_b, 0, nonce_b.Length); - Buffer.BlockCopy(creationtime_b, 0, concatenation_b, nonce_b.Length, creationtime_b.Length); - Buffer.BlockCopy(password_b, 0, concatenation_b, nonce_b.Length + creationtime_b.Length, password_b.Length); - var sha = new SHA1CryptoServiceProvider(); - var pdresult = sha.ComputeHash(concatenation_b); - var passworddigest = Convert.ToBase64String(pdresult); - var message = string.Format(Template.AuthTemplate, userName, passworddigest, Convert.ToBase64String(nonce_b), now, body); - var result = SoapRequest(url, action, message); - return result; - } - - private string GetOnoce(string deviceUrl) - { - var message = @" - - - - "; - var hc = this._httpClientFactory.CreateClient(); - hc.DefaultRequestHeaders.Add("ContentType", $"application/soap+xml; charset=utf-8; action=\"{Template.GetDeviceInformationAction}\""); - var task = hc.PostAsync(deviceUrl, new StringContent(message)); - var result = task.Result.Headers.WwwAuthenticate; - return Regex.Match(result.ToString(), "nonce=\"([^\"]+)\"").Groups[1].Value; - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Infrastructure/Profile.cs b/projects/IoT/IoTServices/ONVIFService/Infrastructure/Profile.cs deleted file mode 100644 index b693c7b8..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Infrastructure/Profile.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Xml.Linq; - -namespace ONVIFService -{ - public class Profile - { - public string Token { get; set; } - public string Name { get; set; } - public string Encoding { get; set; } - public int Width { get; set; } - public int Height { get; set; } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Infrastructure/Template.cs b/projects/IoT/IoTServices/ONVIFService/Infrastructure/Template.cs deleted file mode 100644 index e58acb8b..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Infrastructure/Template.cs +++ /dev/null @@ -1,95 +0,0 @@ -namespace ONVIFService -{ - public class Template - { - public const string GetServiceRequestTemplage = @" - - http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe - urn:uuid:{0} - - http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous - - urn:schemas-xmlsoap-org:ws:2005:04:discovery - - - - dp0:Device - - - - "; - - public const string GetCapabilitiesAction = "http://www.onvif.org/ver10/device/wsdl/GetCapabilities"; - - public const string GetCapabilitiesMessage = @" - - - All - - - "; - - public const string GetProfilesAction = "http://www.onvif.org/ver10/media/wsdlGetProfiles/"; - public const string GetProfilesMessageBody = @""; - - public const string GetStreamUriAction = "http://www.onvif.org/ver10/media/wsdl/GetStreamUri"; - - public const string GetStreamUriMessage = @" - - RTP-Unicast - - RTSP - - - {0} - "; - - public const string GetDeviceInformationAction = "http://www.onvif.org/ver10/device/wsdl/GetDeviceInformation"; - - public const string Templage = @" - - {0} - - "; - - public const string AuthTemplate = @" - - - - {0} - {1} - {2} - {3} - - - - - {4} - - "; - - public const string GetSnapshotUriAction = "http://www.onvif.org/ver10/media/wsdl/GetSnapshotUri"; - - public const string GetSnapshotUriMessage = @" - {0} - "; - - public const string ContinuousMoveAction = "http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"; - - public const string ContinuousMoveMessage = @" - {0} - - - - - "; - - public const string StopAction = "http://www.onvif.org/ver20/ptz/wsdl/Stop"; - public const string StopMessage = @"{0}truetrue"; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/ONVIFService.csproj b/projects/IoT/IoTServices/ONVIFService/ONVIFService.csproj deleted file mode 100644 index ea0f38d6..00000000 --- a/projects/IoT/IoTServices/ONVIFService/ONVIFService.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - netcoreapp2.2 - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/ONVIFService.sln b/projects/IoT/IoTServices/ONVIFService/ONVIFService.sln deleted file mode 100644 index a06708b6..00000000 --- a/projects/IoT/IoTServices/ONVIFService/ONVIFService.sln +++ /dev/null @@ -1,43 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28010.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ONVIFService", "ONVIFService.csproj", "{E25B755D-0074-481F-847B-8D45B33C65A7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure", "..\..\..\..\Infrastructure\Infrastructure\src\Infrastructure\Infrastructure.csproj", "{6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoT.Shared", "..\..\Libraries\src\IoT.Shared\IoT.Shared.csproj", "{8572A0E0-E4E3-466D-8116-5F686040C66D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoT.UI.Shard", "..\..\Libraries\src\IoT.UI.Shard\IoT.UI.Shard.csproj", "{4D947053-F0FF-4F5B-8E33-CE474BDF0621}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E25B755D-0074-481F-847B-8D45B33C65A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E25B755D-0074-481F-847B-8D45B33C65A7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E25B755D-0074-481F-847B-8D45B33C65A7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E25B755D-0074-481F-847B-8D45B33C65A7}.Release|Any CPU.Build.0 = Release|Any CPU - {6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6DC05FAD-C2E7-4C7F-B376-3BEFE56439B9}.Release|Any CPU.Build.0 = Release|Any CPU - {8572A0E0-E4E3-466D-8116-5F686040C66D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8572A0E0-E4E3-466D-8116-5F686040C66D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8572A0E0-E4E3-466D-8116-5F686040C66D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8572A0E0-E4E3-466D-8116-5F686040C66D}.Release|Any CPU.Build.0 = Release|Any CPU - {4D947053-F0FF-4F5B-8E33-CE474BDF0621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4D947053-F0FF-4F5B-8E33-CE474BDF0621}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4D947053-F0FF-4F5B-8E33-CE474BDF0621}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4D947053-F0FF-4F5B-8E33-CE474BDF0621}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B5A82048-F0E0-4FA7-9954-E5983781CAAC} - EndGlobalSection -EndGlobal diff --git a/projects/IoT/IoTServices/ONVIFService/Program.cs b/projects/IoT/IoTServices/ONVIFService/Program.cs deleted file mode 100644 index aca121dc..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Program.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Infrastructure.Application; -using Infrastructure.Configuration; -using Infrastructure.Extensions; -using Infrastructure.Web.Hosting; -using Microsoft.AspNetCore; -using System; -using System.Collections.Generic; - -namespace ONVIFService -{ - public class Program - { - public static void Main(string[] args) - { - var host = "localhost"; - WebHost.CreateDefaultBuilder(args) - .Run(new List { - new EFConfigurationValue { Id = "openapi.title", Value= "web api" }, - new EFConfigurationValue { Id = "openapi.version", Value= "1.0" }, - new EFConfigurationValue { Id = "security:key", Value= "111111111111111111111111"}, - new EFConfigurationValue { Id = "security:iv", Value= "11111111"}, - new EFConfigurationValue { Id = "email:host", Value= "nbaxp.com"}, - new EFConfigurationValue { Id = "email:port", Value= "25"}, - new EFConfigurationValue { Id = "email:user", Value= "admin@nbaxp.com"}, - new EFConfigurationValue { Id = "email:password", Value= "aA123456"}, - new EFConfigurationValue { Id = "server.urls", Value= "http://*:8004" }, - new EFConfigurationValue { Id = "notify:enabled", Value= "false"}, - new EFConfigurationValue { Id = "notify:host", Value= $"{host}:8001"}, - new EFConfigurationValue { Id = "timer.seconds", Value="600"}, - new EFConfigurationValue { Id = "connectId", Value= Guid.NewGuid().ToBase62() }, - new EFConfigurationValue { Id = "node.number", Value= "所属节点编号" }, - new EFConfigurationValue { Id = "onvif.timer", Value="1"}, - new EFConfigurationValue { Id = "onvif.speed", Value="0.2"}, - new EFConfigurationValue { Id = "camera.usr", Value="admin"}, - new EFConfigurationValue { Id = "camera.pwd", Value="lg123456"}, - new EFConfigurationValue { Id = "stream.rtmp", Value=host}, - new EFConfigurationValue { Id = "stream.flv", Value=$"{host}:8080"}, - new EFConfigurationValue { Id = "stream.hls", Value=$"{host}:8080"}, - new EFConfigurationValue { Id = "ffmpeg.args", Value=" -y -threads {0} -rtsp_transport tcp -use_wallclock_as_timestamps 1 -stimeout 3000000 -i \"{1}\" -fflags +genpts -c copy -f flv \"{2}\""}, - new EFConfigurationValue { Id = "ffmpeg.file", Value="/usr/ffmpeg-rkmp/bin/ffmpeg"}, - // - new EFConfigurationValue { Id = "name", Value= "ONVIF服务"}, - new EFConfigurationValue { Id = "logo", Value= "/images/logo.png",Type= InputType.ImageUrl}, - new EFConfigurationValue { Id = "copyright", Value= "Copyright © {now} Company. All rights reserved",Type= InputType.Html} - }); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Properties/launchSettings.json b/projects/IoT/IoTServices/ONVIFService/Properties/launchSettings.json deleted file mode 100644 index 3f3adaeb..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Properties/launchSettings.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:8004/", - "sslPort": 0 - } - }, - "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "OnvifService": { - "commandName": "Project", - "launchBrowser": true, - "applicationUrl": "http://127.0.0.1:8004/", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Startup.cs b/projects/IoT/IoTServices/ONVIFService/Startup.cs deleted file mode 100644 index 320f3c85..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Startup.cs +++ /dev/null @@ -1,31 +0,0 @@ -using IoT.Shared.Infrastructure; -using IoT.UI.Shard; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace ONVIFService -{ - public class Startup : IoTServiceStartup - { - public Startup(IConfiguration configuration, IHostingEnvironment env) : base(configuration, env) - { - } - - public override void ConfigureServices(IServiceCollection services) - { - services.AddSingleton(); - services.AddSingleton(); - base.ConfigureServices(services); - } - - public override void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) - { - base.Configure(app, env, loggerFactory); - app.ApplicationServices.GetService().Start(); - app.ApplicationServices.GetService().Start(); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Views/Home/Index.cshtml b/projects/IoT/IoTServices/ONVIFService/Views/Home/Index.cshtml deleted file mode 100644 index b0a274ca..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Views/Home/Index.cshtml +++ /dev/null @@ -1,263 +0,0 @@ -@model List -@section styles{ - -} -@if (Model != null && Model.Count > 0) -{ -
- @foreach (var item in Model) - { - var url = "/images/empty.png"; - var needAuth = item.GetDataValue("NeedAuth") == "是"; - var hasAuth = item.GetDataValue("hasAuth") == "是"; - if (!needAuth || hasAuth) - { - url = Url.Action("Image", "Home", new { id = item.Number }); - } -
-
-
-

@item.GetDataValue("StreamUri")

-
-
- -
-
- PTZ支持:@item.GetDataValue("SubPtz3DZoomSupport") - 需认证:@Html.DisplayFor(o => needAuth) - @if (needAuth) - { - 已认证:@Html.DisplayFor(o => hasAuth) - } -
- - -
-
- } -
-} - -@section scripts{ - - - - - -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Views/Shared/_Menu.cshtml b/projects/IoT/IoTServices/ONVIFService/Views/Shared/_Menu.cshtml deleted file mode 100644 index 29286277..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Views/Shared/_Menu.cshtml +++ /dev/null @@ -1,26 +0,0 @@ - -@functions{ - public string GetClass(params string[] controllers) - { - if (controllers.Select(o => o.ToLower()).Contains(this.ViewContext.RouteData.Values["controller"].ToString().ToLower())) - { - if (controllers.Length > 1) - { - return "active open"; - } - return "active"; - } - return ""; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Views/_ViewImports.cshtml b/projects/IoT/IoTServices/ONVIFService/Views/_ViewImports.cshtml deleted file mode 100644 index 7b266683..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Views/_ViewImports.cshtml +++ /dev/null @@ -1,11 +0,0 @@ -@inherits Infrastructure.Web.Mvc.Razor.MyRazorPage -@using Microsoft.Extensions.Configuration -@using System.ComponentModel.DataAnnotations -@using Infrastructure.Application -@using Infrastructure.Web -@using Infrastructure.Web.DataAnnotations -@using Infrastructure.Extensions -@using Infrastructure.Data -@using Application.Domain.Entities -@using Application.Models -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/Views/_ViewStart.cshtml b/projects/IoT/IoTServices/ONVIFService/Views/_ViewStart.cshtml deleted file mode 100644 index a5f10045..00000000 --- a/projects/IoT/IoTServices/ONVIFService/Views/_ViewStart.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -@{ - Layout = "_Layout"; -} diff --git a/projects/IoT/IoTServices/ONVIFService/appsettings.Development.json b/projects/IoT/IoTServices/ONVIFService/appsettings.Development.json deleted file mode 100644 index e203e940..00000000 --- a/projects/IoT/IoTServices/ONVIFService/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - } -} diff --git a/projects/IoT/IoTServices/ONVIFService/appsettings.json b/projects/IoT/IoTServices/ONVIFService/appsettings.json deleted file mode 100644 index f234ad0d..00000000 --- a/projects/IoT/IoTServices/ONVIFService/appsettings.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": "1.0.0-beta.108", - "Logging": { - "LogLevel": { - "Default": "Information" - } - }, - "AllowedHosts": "*", - "ConnectionStrings": { - "database.mysql.connection": "Server=127.0.0.1;Port=3306;Database=iotnode;Uid=root;Pwd=root;", - "database.sqlite.connection": "Data Source=data.db" - }, - "AppSettings": { - "database": "sqlite", - "UseCookieSessionStore": false - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/wwwroot/favicon.ico b/projects/IoT/IoTServices/ONVIFService/wwwroot/favicon.ico deleted file mode 100644 index a6fd6b28..00000000 Binary files a/projects/IoT/IoTServices/ONVIFService/wwwroot/favicon.ico and /dev/null differ diff --git a/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-arm b/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-arm deleted file mode 100644 index 870c72db..00000000 Binary files a/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-arm and /dev/null differ diff --git a/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-arm64 b/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-arm64 deleted file mode 100644 index eaa91c9b..00000000 Binary files a/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-arm64 and /dev/null differ diff --git a/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-x64 b/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-x64 deleted file mode 100644 index add3792a..00000000 Binary files a/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-linux-x64 and /dev/null differ diff --git a/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-windows-x64.exe b/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-windows-x64.exe deleted file mode 100644 index 87eb0894..00000000 Binary files a/projects/IoT/IoTServices/ONVIFService/wwwroot/ffmpeg-windows-x64.exe and /dev/null differ diff --git a/projects/IoT/IoTServices/ONVIFService/wwwroot/flvjsdemo.html b/projects/IoT/IoTServices/ONVIFService/wwwroot/flvjsdemo.html deleted file mode 100644 index 00a0acab..00000000 --- a/projects/IoT/IoTServices/ONVIFService/wwwroot/flvjsdemo.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - flvjsdemo - - -
- -
- - - - - \ No newline at end of file diff --git a/projects/IoT/IoTServices/ONVIFService/wwwroot/images/logo.png b/projects/IoT/IoTServices/ONVIFService/wwwroot/images/logo.png deleted file mode 100644 index 7a0f0e8d..00000000 Binary files a/projects/IoT/IoTServices/ONVIFService/wwwroot/images/logo.png and /dev/null differ diff --git a/projects/IoT/IoTServices/ONVIFService/wwwroot/test.mp3 b/projects/IoT/IoTServices/ONVIFService/wwwroot/test.mp3 deleted file mode 100644 index cd676d72..00000000 Binary files a/projects/IoT/IoTServices/ONVIFService/wwwroot/test.mp3 and /dev/null differ diff --git a/projects/IoT/IoTServices/SerialPortService/.gitignore b/projects/IoT/IoTServices/SerialPortService/.gitignore deleted file mode 100644 index d8cbb114..00000000 --- a/projects/IoT/IoTServices/SerialPortService/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -*.bak -*.suo -*.db -*.user -.vs/ -obj -Obj -bin -Bin -debug -Debug -release -Release -Logs -logs -node_modules \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Application/Domain/Entities/Button.cs b/projects/IoT/IoTServices/SerialPortService/Application/Domain/Entities/Button.cs deleted file mode 100644 index d742a8a8..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Application/Domain/Entities/Button.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Infrastructure.Domain; - -namespace Application.Domain.Entities -{ - public class Button : BaseEntity - { - public string Name { get; set; } - public string Message { get; set; } - public string SerialPort { get; set; } - public int Baud { get; set; } - public int Data { get; set; } - public int Partity { get; set; } - public int StopBits { get; set; } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Application/Models/EditButtonModel.cs b/projects/IoT/IoTServices/SerialPortService/Application/Models/EditButtonModel.cs deleted file mode 100644 index fc708f16..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Application/Models/EditButtonModel.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Infrastructure.Application; - -namespace SPService.Applicaiton.Models -{ - [Display(Name = "指令")] - public class EditButtonModel : EditModel - { - [Required] - [Display(Name = "名称")] - public string Name { get; set; } - - [Required] - [Display(Name = "消息")] - public string Message { get; set; } - - [Required] - [Display(Name = "串口")] - public string SerialPort { get; set; } - - [Required] - [Display(Name = "波特率")] - public int Baud { get; set; } = 9600; - - [Required] - [Display(Name = "数据位")] - public int Data { get; set; } = 8; - - [Required] - [Display(Name = "停止位")] - public int StopBits { get; set; } = 0; - - [Required] - [Display(Name = "校验位")] - public int Partity { get; set; } = 0; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Application/Models/EditSerialPortDeviceModel.cs b/projects/IoT/IoTServices/SerialPortService/Application/Models/EditSerialPortDeviceModel.cs deleted file mode 100644 index 2a79e0e2..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Application/Models/EditSerialPortDeviceModel.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace SerialPortService.Application.Models -{ - public class EditSerialPortDeviceModel - { - } -} diff --git a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/DataController.cs b/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/DataController.cs deleted file mode 100644 index 2eb0834f..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/DataController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Linq; -using Application.Domain.Entities; -using Application.Models; -using Infrastructure.Data; -using Infrastructure.Extensions; -using Infrastructure.Web.Mvc; -using IoTShared.Controllers; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace IoTCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class DataController : CrudController - { - private readonly AjaxController _ajax; - - public DataController(IRepository repo, AjaxController ajax) : base(repo) - { - this._ajax = ajax; - } - - public override IQueryable Query(DataSearchModel model, IQueryable query) - { - ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId)); - ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetDeviceSelectList(model.NodeId.Value, model.DeviceId), model.NodeId.HasValue); - return query.WhereIf(model.NodeId.HasValue, o => o.Device.NodeId == model.NodeId.Value) - .WhereIf(model.DeviceId.HasValue, o => o.DeviceId == model.DeviceId.Value) - .WhereIf(!string.IsNullOrEmpty(model.Keyword), o => o.Name.Contains(model.Keyword)); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/DeviceController.cs b/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/DeviceController.cs deleted file mode 100644 index 7bf1d1da..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/DeviceController.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Application.Domain.Entities; -using Application.Models; -using Infrastructure.Data; -using Infrastructure.Extensions; -using Infrastructure.Web.Mvc; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace IoTCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class DeviceController : CrudController - { - private readonly IConfiguration _cfg; - private readonly IRepository _productRepo; - - public DeviceController(IConfiguration cfg, IRepository productRepo, IRepository repo) : base(repo) - { - this._cfg = cfg; - this._productRepo = productRepo; - } - - public override IActionResult Add() - { - var model = new EditDeviceModel - { - CategoryNumber = "20", - InfoNumber = "serialport", - ConnectId = this._cfg["ConnectId"], - Number = Guid.NewGuid().ToBase62(), - NodeNumber = this._cfg["node.number"] - }; - return View(model); - } - - public override void ToEntity(EditDeviceModel model, Device entity) - { - if (!this.repo.ReadOnlyTable().Any(o => o.Id == model.Id)) - { - entity.ProductId = this._productRepo.ReadOnlyTable().First().Id; - entity.AddorUpdateData("SerialPort", "", DeviceDataType.String, "", hidden: true); - entity.AddorUpdateData("Baud", "9600", DeviceDataType.Int, "", hidden: true); - entity.AddorUpdateData("Partity", "0", DeviceDataType.Int, "Уλ", hidden: true); - entity.AddorUpdateData("DataBits", "8", DeviceDataType.Int, "λ", hidden: true); - entity.AddorUpdateData("StopBits", "1", DeviceDataType.Int, "ֹͣλ", hidden: true); - entity.AddorUpdateData("Buttons", new List> { new KeyValuePair("԰", "11111111") }.ToJson(), DeviceDataType.SelectList, ""); - } - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/HomeController.cs b/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/HomeController.cs deleted file mode 100644 index acba2d08..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Controllers/HomeController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace UserCenter.Areas.Admin.Controllers -{ - [Authorize] - [Area(nameof(Admin))] - public class HomeController : Controller - { - public HomeController() - { - } - - public IActionResult Index() - { - return View(); - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Home/Index.cshtml b/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Home/Index.cshtml deleted file mode 100644 index f551b40e..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Home/Index.cshtml +++ /dev/null @@ -1,4 +0,0 @@ -@{ - ViewData["IsHomePage"] = true; -} -

首页

\ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Shared/_Menu.cshtml b/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Shared/_Menu.cshtml deleted file mode 100644 index bb3678bd..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Shared/_Menu.cshtml +++ /dev/null @@ -1,52 +0,0 @@ - -@functions{ - public string GetClass(params string[] controllers) - { - if (controllers.Select(o => o.ToLower()).Contains(this.ViewContext.RouteData.Values["controller"].ToString().ToLower())) - { - if (controllers.Length > 1) - { - return "active open"; - } - return "active"; - } - return ""; - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Shared/_Script.cshtml b/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Shared/_Script.cshtml deleted file mode 100644 index 33c931f6..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/Shared/_Script.cshtml +++ /dev/null @@ -1,24 +0,0 @@ - \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/_ViewImports.cshtml b/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/_ViewImports.cshtml deleted file mode 100644 index f99ab108..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/_ViewImports.cshtml +++ /dev/null @@ -1,7 +0,0 @@ -@inherits Infrastructure.Web.Mvc.Razor.MyRazorPage -@using Infrastructure.Application -@using Infrastructure.Extensions -@using Infrastructure.Data -@using Application.Domain.Entities -@using Application.Models -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/_ViewStart.cshtml b/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/_ViewStart.cshtml deleted file mode 100644 index d641c67f..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Areas/Admin/Views/_ViewStart.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -@{ - Layout = "_Layout"; -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Controllers/AccountController.cs b/projects/IoT/IoTServices/SerialPortService/Controllers/AccountController.cs deleted file mode 100644 index 6a255af5..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Controllers/AccountController.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Application.Domain.Entities; -using Infrastructure.Data; -using Infrastructure.Email; -using Infrastructure.Resources; -using Infrastructure.Security; -using IoT.UI.Shard.Controllers; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Localization; - -namespace ONVIFService.Controllers -{ - public class AccountController : BaseAccountController - { - public AccountController(IConfiguration configuration, - IRepository userRepo, - IEncryptionService encryptionService, - IStringLocalizer localizer, - IEmailSender emaliSender) : base(configuration, userRepo, encryptionService, localizer, emaliSender) - { - } - } -} \ No newline at end of file diff --git a/projects/IoT/IoTServices/SerialPortService/Controllers/HomeController.cs b/projects/IoT/IoTServices/SerialPortService/Controllers/HomeController.cs deleted file mode 100644 index f31ebebb..00000000 --- a/projects/IoT/IoTServices/SerialPortService/Controllers/HomeController.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Application.Domain.Entities; -using Infrastructure.Data; -using Infrastructure.Extensions; -using Microsoft.AspNetCore.Mvc; -using SPService.Applicaiton.Models; -using System; -using System.Net.Http; - -namespace SerialPortService.Controllers -{ - public class HomeController : Controller - { - private readonly IRepository