diff --git a/projects/CheckSum/Program.cs b/projects/CheckSum/Program.cs index a3250eea..6c2a2321 100644 --- a/projects/CheckSum/Program.cs +++ b/projects/CheckSum/Program.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.IO.Compression; using System.Security.Cryptography; using System.Text; @@ -11,24 +12,25 @@ namespace CheckSum { Console.InputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8; - using var sha = SHA512.Create(); - while (true) + var file = string.Empty; + using var sha = SHA1.Create(); + if (args.Length > 0) + { + file = args[0]; + } + else { Console.WriteLine("input file name:"); - var file = Console.ReadLine(); - if (File.Exists(file)) - { - Console.WriteLine(BitConverter.ToString(sha.ComputeHash(File.ReadAllBytes(file))).Replace("-", "").ToLower()); - } - else - { - Console.WriteLine($"file {file} does not Exist"); - } - var key = Console.ReadKey().Key; - if (key == ConsoleKey.Escape) - { - break; - } + file = Console.ReadLine(); + } + if (File.Exists(file)) + { + Console.WriteLine(BitConverter.ToString(sha.ComputeHash(File.ReadAllBytes(file))).Replace("-", "")); + ZipFile.ExtractToDirectory(file, Path.Combine(Directory.GetCurrentDirectory(), "IoTNode"), true); + } + else + { + Console.WriteLine($"file {file} does not Exist"); } } } diff --git a/projects/IoT.Shared/Areas/Admin/Controlls/DeviceController.cs b/projects/IoT.Shared/Areas/Admin/Controlls/DeviceController.cs index be524ad4..d22f6293 100644 --- a/projects/IoT.Shared/Areas/Admin/Controlls/DeviceController.cs +++ b/projects/IoT.Shared/Areas/Admin/Controlls/DeviceController.cs @@ -1,4 +1,4 @@ -using Application.Domain.Entities; +using Application.Domain.Entities; using Application.Models; using Infrastructure.Application; using Infrastructure.Data; @@ -6,6 +6,7 @@ using Infrastructure.Extensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Primitives; using System; using System.Linq; @@ -33,6 +34,12 @@ namespace IoT.Shared.Areas.Admin.Controlls { throw new ArgumentNullException(nameof(model)); } + if (this.HttpContext.Request.Query.TryGetValue("query.organNumber", out StringValues value)) + { + var organNumber = value.ToString(); + query = query.WhereIf(!string.IsNullOrWhiteSpace(organNumber), o => o.Node.OrganNodes.Any(o => o.Organ.Number == organNumber)); + } + return query .WhereIf(model.Query.NodeId.HasValue, o => o.NodeId == model.Query.NodeId.Value) .WhereIf(model.Query.ProductId.HasValue, o => o.ProductId == model.Query.ProductId.Value) diff --git a/projects/IoTCenter/Api/NodeController.cs b/projects/IoTCenter/Api/NodeController.cs index 4a4ec196..4e417c91 100644 --- a/projects/IoTCenter/Api/NodeController.cs +++ b/projects/IoTCenter/Api/NodeController.cs @@ -44,11 +44,12 @@ namespace IoTCenter.Api.Controllers } [HttpPost] - public ActionResult GetNodes() + public ActionResult GetNodes(string organNumber) { try { var model = this._nodeRepo.ReadOnlyTable() + .WhereIf(!string.IsNullOrWhiteSpace(organNumber), o => o.OrganNodes.Any(on => on.Organ.Number == organNumber)) .Where(o => !o.Hidden) .OrderBy(o => o.Name) .ToList() diff --git a/projects/IoTCenter/Api/ProductController.cs b/projects/IoTCenter/Api/ProductController.cs index de05f876..8c76604b 100644 --- a/projects/IoTCenter/Api/ProductController.cs +++ b/projects/IoTCenter/Api/ProductController.cs @@ -15,17 +15,20 @@ namespace IoTCenter.Api.Controllers public class ProductController : ControllerBase { private readonly IRepository _productRepo; + private readonly IRepository _nodeRepo; private readonly IRepository _deviceRepo; public ProductController(IRepository productRepo, + IRepository nodeRepo, IRepository deviceRepo) { this._productRepo = productRepo; + this._nodeRepo = nodeRepo; this._deviceRepo = deviceRepo; } [HttpPost] - public ActionResult GetProducts() + public ActionResult GetProducts(string organNumber) { try { @@ -40,7 +43,9 @@ namespace IoTCenter.Api.Controllers o.Number, o.Image, o.DisplayOrder, - Count = _deviceRepo.ReadOnlyTable().Count(d => d.ProductId == o.Id) + Count = _deviceRepo.ReadOnlyTable() + .WhereIf(!string.IsNullOrWhiteSpace(organNumber), o => o.Node.OrganNodes.Any(o => o.Organ.Number == organNumber)) + .Count(d => d.ProductId == o.Id) }); return Ok(model); } @@ -52,18 +57,17 @@ namespace IoTCenter.Api.Controllers } [HttpPost] - public ActionResult GetProduct([Required(ErrorMessage = nameof(RequiredAttribute))] string number) + public ActionResult GetProduct([Required(ErrorMessage = nameof(RequiredAttribute))] string number, string organNumber) { try { - var model = this._productRepo.ReadOnlyTable() + var model = this._nodeRepo.ReadOnlyTable() + .WhereIf(!string.IsNullOrWhiteSpace(organNumber), o => o.OrganNodes.Any(o => o.Organ.Number == organNumber)) + .Where(o => o.Devices.Any(o => o.Product.Number == number)) .Include(o => o.Devices) .ThenInclude(o => o.Data) - .Include(o => o.Devices) - .ThenInclude(o => o.Node) - .Where(o => o.Number == number) - .FirstOrDefault(); - model.Devices = model.Devices.OrderBy(o => o.NodeId).ToList(); + .SelectMany(o => o.Devices) + .OrderBy(o => o.NodeId).ToList(); return Ok(model); } catch (Exception ex) diff --git a/projects/IoTDameon/UpdateIoTNodeService.cs b/projects/IoTDameon/UpdateIoTNodeService.cs index 7b87a4a7..404fb382 100644 --- a/projects/IoTDameon/UpdateIoTNodeService.cs +++ b/projects/IoTDameon/UpdateIoTNodeService.cs @@ -10,6 +10,7 @@ using System.Net; using System.Net.Http; using System.Runtime.InteropServices; using System.Security.Cryptography; +using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml; @@ -194,7 +195,7 @@ namespace IoTDameon //更新程序 try { - ZipFile.ExtractToDirectory(file, root, true); + ZipFile.ExtractToDirectory(file, root, Encoding.UTF8, true); this.Log($"解压更新文件 {file} 到 {appPath}"); } catch (Exception ex) @@ -226,11 +227,11 @@ namespace IoTDameon private string GetCheckSum(string file) { - using (var sha = SHA512.Create()) + using (var sha = SHA1.Create()) { using (var fs = File.OpenRead(file)) { - var checksum = BitConverter.ToString(sha.ComputeHash(fs)).Replace("-", "").ToLower(); + var checksum = BitConverter.ToString(sha.ComputeHash(fs)).Replace("-", ""); return checksum; } } diff --git a/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs b/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs index c4db1cb5..99a5b021 100644 --- a/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs +++ b/projects/IoTNode/DeviceServices/Onvif/OnvifService.cs @@ -148,6 +148,14 @@ namespace IoTNode.DeviceServices.Onvif this.UpdateData(deviceRepo, device, device.CreateData("ffmpeg.file", file, DeviceDataType.String, "ffmpeg路径", hidden: true)); this.UpdateData(deviceRepo, device, device.CreateData("ffmpeg.args", GetSetting("ffmpeg.args"), DeviceDataType.String, "ffmpeg.args", hidden: true)); } + else + { + if (device.Ip != ipCamera.Ip) + { + device.Ip = ipCamera.Ip; + deviceRepo.SaveChanges(); + } + } var profiles = this._onvifDeviceManagement.GetProfiles(ipCamera.DeviceUrl, ipCamera.MediaUrl); var needAuth = false; var hasAuth = false; diff --git a/projects/IoTNode/Version.cs b/projects/IoTNode/Version.cs index def643dd..5e4c1b76 100644 --- a/projects/IoTNode/Version.cs +++ b/projects/IoTNode/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0.20101901")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.20102102")] \ No newline at end of file diff --git a/projects/Version.cs b/projects/Version.cs index e5aaa5db..32175cca 100644 --- a/projects/Version.cs +++ b/projects/Version.cs @@ -1,4 +1,4 @@ using System.Reflection; [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("1.0.0.20101601")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.20102001")] \ No newline at end of file diff --git a/publish/build.ps1 b/publish/build.ps1 index a256a551..332a29d1 100644 --- a/publish/build.ps1 +++ b/publish/build.ps1 @@ -1,13 +1,20 @@ +echo start: +Get-Date -Format 'yyyy-MM-dd HH:mm:ss' + +echo 'delete dist folder' if(Test-Path dist) { Remove-Item ./dist/* -recurse -force } else { + echo 'create dist folder' mkdir ./dist; } +echo 'copy src to dist' Copy-Item ./src/* ./dist -recurse -Exclude @('.gitignore','start-dev.cmd','docker-compose.override.yml','nginx.development.conf') +echo 'remove temp file in dist folder' Remove-Item ./dist/linux-x64/publish/docker/log/* -recurse -force Remove-Item ./dist/linux-x64/publish/docker/data/* -recurse -force Remove-Item ./dist/linux-x64/publish/apps/srs/objs/*.log -recurse -force @@ -17,6 +24,7 @@ Remove-Item ./dist/linux-x64/publish/apps/srs/objs/nginx/html/live/*.png -recurs Remove-Item ./dist/linux-x64/publish/apps/srs/objs/nginx/html/live/*.m3u8 -recurse -force Remove-Item ./dist/linux-x64/publish/apps/srs/objs/nginx/html/live/*.ts -recurse -force +echo 'copy project files to dist folder' Copy-Item ../projects/WebMVC/wwwroot/* ./dist/linux-x64/publish/apps/WebMVC/wwwroot -recurse Copy-Item ../projects/WebSPA/wwwroot/* ./dist/linux-x64/publish/apps/WebSPA/wwwroot -recurse @@ -26,4 +34,24 @@ dotnet publish ../projects/IoTCenter/IoTCenter.csproj -c Release -r linux-x64 -o dotnet publish ../projects/IoTNode/IoTNode.csproj -c Release -r linux-arm64 -o ../publish/dist/linux-arm64/publish/apps/IoTNode -dotnet publish ../projects/IoTDameon/IoTDameon.csproj -c Release -r linux-arm64 -o ../publish/dist/linux-arm64/publish/apps/IoTDameon \ No newline at end of file +dotnet publish ../projects/IoTDameon/IoTDameon.csproj -c Release -r linux-arm64 -o ../publish/dist/linux-arm64/publish/apps/IoTDameon + +Add-Type -Assembly "System.IO.Compression.FileSystem" +echo 'create zip file' +$level = [System.IO.Compression.CompressionLevel]::Optimal +[System.IO.Compression.ZipFile]::CreateFromDirectory((Get-Item .).FullName+"/dist/linux-arm64/publish", (Get-Item .).FullName+"/dist/linux-arm64/publish.zip",$level,$true) +[System.IO.Compression.ZipFile]::CreateFromDirectory((Get-Item .).FullName+"/dist/linux-arm64/publish/apps/IoTNode", (Get-Item .).FullName+"/dist/linux-arm64/IoTNode.zip",$level,$true) +$zip=(Get-Item .).FullName+"/dist/linux-arm64/IoTNode.zip" +echo 'create xml file' +$v=[System.Diagnostics.FileVersionInfo]::GetVersionInfo((Get-Item .).FullName+"/dist/linux-arm64/publish/apps/IoTNode/IoTNode.dll").ProductVersion; +$sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider +$checksum=[System.BitConverter]::ToString( $sha1.ComputeHash([System.IO.File]::ReadAllBytes($zip))) +$file = (Get-Item .).FullName+'/dist/linux-arm64/iotnode.xml' +$xml = New-Object System.Xml.XmlDocument +$xml.PreserveWhitespace = $true +$xml.LoadXml(''+$v+'D71BD377E3A026C6E4A077554701E44C20B28798') +$xml.Save($file) + +echo end! +Get-Date -Format 'yyyy-MM-dd HH:mm:ss' +Read-Host -Prompt "Press any key to continue" \ No newline at end of file diff --git a/publish/src/linux-arm64/publish/install.sh b/publish/src/linux-arm64/publish/install.sh index 857c764e..d0a0a3e9 100644 --- a/publish/src/linux-arm64/publish/install.sh +++ b/publish/src/linux-arm64/publish/install.sh @@ -57,6 +57,6 @@ if uname -a | grep -q "NanoPC-T4" # sed -i "s/managed=true/managed=false/g" /etc/NetworkManager/NetworkManager.conf # cp -f /etc/network/interfaces /etc/network/interfaces.bk # cp ~/publish/interfaces /etc/network/interfaces - nmcli connection modify 'Wired connection 1' connection.autoconnect yes ipv4.method manual ipv4.address 192.168.1.3/24 ipv4.gateway 192.168.1.1 ipv4.dns "223.5.5.5 119.29.29.29 180.76.76.76" + nmcli connection modify 'Wired connection 1' connection.autoconnect yes ipv4.method manual ipv4.address 192.168.100.3/24 ipv4.gateway 192.168.100.1 ipv4.dns "223.5.5.5 119.29.29.29 180.76.76.76" nmcli c up 'Wired connection 1' fi \ No newline at end of file