diff --git a/MasstransferCommon/obj/Debug/net7.0/MasstransferCommon.AssemblyInfo.cs b/MasstransferCommon/obj/Debug/net7.0/MasstransferCommon.AssemblyInfo.cs index 5a3cb42..59b202e 100644 --- a/MasstransferCommon/obj/Debug/net7.0/MasstransferCommon.AssemblyInfo.cs +++ b/MasstransferCommon/obj/Debug/net7.0/MasstransferCommon.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("MasstransferCommon")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c140544af7e52a0669ceafcb39aa5c4e97c5ccae")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a303714a635d3146132582a2408fc8cf76a69947")] [assembly: System.Reflection.AssemblyProductAttribute("MasstransferCommon")] [assembly: System.Reflection.AssemblyTitleAttribute("MasstransferCommon")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/MasstransferCommon/obj/Debug/net7.0/MasstransferCommon.AssemblyInfoInputs.cache b/MasstransferCommon/obj/Debug/net7.0/MasstransferCommon.AssemblyInfoInputs.cache index e03e6aa..6a21fc7 100644 --- a/MasstransferCommon/obj/Debug/net7.0/MasstransferCommon.AssemblyInfoInputs.cache +++ b/MasstransferCommon/obj/Debug/net7.0/MasstransferCommon.AssemblyInfoInputs.cache @@ -1 +1 @@ -bea321349982bc0eb41c769bdac56f18be90a91e28cbb7240ece837e7958e892 +04161de5d5b7e53625665da3c9aa9d1cc0c406c72bef7aeb16057254b572fd39 diff --git a/MasstransferCommon/obj/rider.project.model.nuget.info b/MasstransferCommon/obj/rider.project.model.nuget.info index 8960062..315e907 100644 --- a/MasstransferCommon/obj/rider.project.model.nuget.info +++ b/MasstransferCommon/obj/rider.project.model.nuget.info @@ -1 +1 @@ -17234348283768389 \ No newline at end of file +17234348310820990 \ No newline at end of file diff --git a/MasstransferExporter.sln b/MasstransferExporter.sln index 3ca82b8..4f46ac7 100644 --- a/MasstransferExporter.sln +++ b/MasstransferExporter.sln @@ -6,8 +6,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasstransferInfrastructure" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasstransferCommon", "MasstransferCommon\MasstransferCommon.csproj", "{66C6D73C-BADB-4E28-9C83-E701B019626D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "UnitTest\UnitTest.csproj", "{3E23D7B1-7223-45A1-B0C3-7758372986E2}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -26,9 +24,5 @@ Global {66C6D73C-BADB-4E28-9C83-E701B019626D}.Debug|Any CPU.Build.0 = Debug|Any CPU {66C6D73C-BADB-4E28-9C83-E701B019626D}.Release|Any CPU.ActiveCfg = Release|Any CPU {66C6D73C-BADB-4E28-9C83-E701B019626D}.Release|Any CPU.Build.0 = Release|Any CPU - {3E23D7B1-7223-45A1-B0C3-7758372986E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3E23D7B1-7223-45A1-B0C3-7758372986E2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3E23D7B1-7223-45A1-B0C3-7758372986E2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3E23D7B1-7223-45A1-B0C3-7758372986E2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/MasstransferExporter/License/LicenseService.cs b/MasstransferExporter/License/LicenseService.cs index 3d200ad..5bbb75e 100644 --- a/MasstransferExporter/License/LicenseService.cs +++ b/MasstransferExporter/License/LicenseService.cs @@ -17,12 +17,11 @@ public class LicenseService { await MessageQueueHelper.Subscribe(Topics.UpdateLicenseEvent, HandleUpdateLicenseEvent); } - - + /// /// 处理接收到的证书更新事件 /// - private static async Task HandleUpdateLicenseEvent(string topic, string license) + public static async Task HandleUpdateLicenseEvent(string topic, string license) { ProcessCommunicator.Subscribe(ProcessTopics.LicenseUpdateEventFeedback, HandleUpdateLicenseEventFeedback); @@ -34,7 +33,7 @@ public class LicenseService /// /// /// - private static async Task HandleUpdateLicenseEventFeedback(string topic, string result) + public static async Task HandleUpdateLicenseEventFeedback(string topic, string result) { await MessageQueueHelper.Publish(Topics.UpdateLicenseEventFeedback, result); } diff --git a/MasstransferInfrastructure/OTA/Client/OTAClient.cs b/MasstransferExporter/OTA/Client/OTAClient.cs similarity index 84% rename from MasstransferInfrastructure/OTA/Client/OTAClient.cs rename to MasstransferExporter/OTA/Client/OTAClient.cs index 707840f..58a0eca 100644 --- a/MasstransferInfrastructure/OTA/Client/OTAClient.cs +++ b/MasstransferExporter/OTA/Client/OTAClient.cs @@ -1,31 +1,45 @@ using System.IO.Compression; +using MasstransferCommon.Model.Constant; +using MasstransferCommunicate.Mqtt; using MasstransferCommon.Utils; -using MasstransferInfrastructure.OTA.Model; +using MasstransferCommunicate.Mqtt.Client; +using MasstransferExporter.OTA.Model; -namespace MasstransferInfrastructure.OTA.Client; +namespace MasstransferExporter.OTA.Client; public class OTAClient { /// - /// 检查更新 + /// 订阅OTA更新 /// - /// - /// - public async Task CheckForUpdate(string updateUrl) + public static async Task ListenOTAUpdateEvent() { - return await ApiClient.GetAsync(updateUrl); + await MessageQueueHelper.Subscribe(Topics.IssuedOTAPackage, HandleUpdateOTAEvent); } /// - /// 下载更新 + /// 查询OTA更新 /// - /// - /// - public async Task DownloadUpdateAsync(string downloadUrl, string filePath) + /// + public static async Task QueryOTAUpdate(string result) { - await ApiClient.DownloadFileAsync(downloadUrl, filePath); + await MessageQueueHelper.Publish(Topics.QueryOTA, result); } + /// + /// OTA更新反馈 + /// + /// + public static async Task OTALicenseUpdateEventFeedback(string resutl) + { + await MessageQueueHelper.Publish(Topics.OTAUpgradeFeedback, resutl); + } + + private static async Task HandleUpdateOTAEvent(string topic, string license) + { + + } + /// /// 备份保存重要文件 /// diff --git a/MasstransferInfrastructure/OTA/Model/UpdateInfo.cs b/MasstransferExporter/OTA/Model/UpdateInfo.cs similarity index 75% rename from MasstransferInfrastructure/OTA/Model/UpdateInfo.cs rename to MasstransferExporter/OTA/Model/UpdateInfo.cs index c1d5bad..856af8c 100644 --- a/MasstransferInfrastructure/OTA/Model/UpdateInfo.cs +++ b/MasstransferExporter/OTA/Model/UpdateInfo.cs @@ -1,4 +1,4 @@ -namespace MasstransferInfrastructure.OTA.Model; +namespace MasstransferExporter.OTA.Model; public class UpdateInfo { diff --git a/MasstransferExporter/OTA/Service/OTAService.cs b/MasstransferExporter/OTA/Service/OTAService.cs new file mode 100644 index 0000000..c35c01c --- /dev/null +++ b/MasstransferExporter/OTA/Service/OTAService.cs @@ -0,0 +1,126 @@ +using MasstransferExporter.OTA.Client; + +namespace MasstransferExporter.OTA.Service; + +public class OTAService +{ + private readonly OTAClient _otaClient; + + private readonly string _appDir; + private readonly string _criticalBackupDir; + private readonly string _criticalSourceLogPath; + private readonly string[] _criticalFileExtension; + private readonly string _previousBackupPath; + private readonly string _updatePackagePath; + + + public OTAService(string appDir, string criticalBackupDir, string criticalSourceLogPath, string[] criticalFileExtension, string previousBackupPath, string updatePackagePath) + { + _otaClient = new OTAClient(); + _appDir = appDir; + _criticalBackupDir = criticalBackupDir; + _criticalSourceLogPath = criticalSourceLogPath; + _criticalFileExtension = criticalFileExtension; + _previousBackupPath = previousBackupPath; + _updatePackagePath = updatePackagePath; + } + + + /// + /// 更新压缩包 + /// + public void Update() + { + try + { + //初始化 + initDir(); + + //备份重要文件 + _otaClient.BackupEssentialFiles(_appDir, _criticalBackupDir, _criticalFileExtension, _criticalSourceLogPath); + + //备份旧版本文件 + _otaClient.CompressDirectory(_appDir, _previousBackupPath); + + try + { + //删除旧版本原文件 + _otaClient.DeleteDirectory(_appDir); + + //解压更新包 + _otaClient.ExtractDirectory(_updatePackagePath, _appDir); + + //恢复重要文件 + _otaClient.RecoverCriticalFiles(_criticalSourceLogPath); + + //删除旧版本备份文件 + _otaClient.DeleteFile(_previousBackupPath); + + //删除更新包 + _otaClient.DeleteFile(_updatePackagePath); + + } + catch (Exception ex) + { + RollBack(); + Console.WriteLine($"更新异常,已回滚: {ex.Message}"); + } + } + catch (Exception ex) + { + Console.WriteLine($"更新异常e: {ex.Message}"); + + //如果重要文件备份已经产生,则删除 + if(Directory.Exists(_criticalBackupDir)) + { + _otaClient.DeleteDirectory(_criticalBackupDir); + } + } + } + + /// + /// 初始化重要文件备份目录 + /// + private void initDir() + { + if (Directory.Exists(_criticalBackupDir)) + { + Directory.Delete(_criticalBackupDir, true); + } + Directory.CreateDirectory(_criticalBackupDir); + + } + + /// + /// 回滚 + /// + private void RollBack() + { + //删除安装过程中创建的文件、目录 + var directoryList = new string[] { _appDir, _criticalBackupDir}; + var filePath = new String[] { _updatePackagePath }; + + foreach (var directory in directoryList) + { + if (Directory.Exists(directory)) + { + _otaClient.DeleteDirectory(directory); + } + } + + foreach (var file in filePath) + { + if (File.Exists(file)) + { + _otaClient.DeleteFile(file); + } + } + + //恢复旧版本文件 + _otaClient.ExtractDirectory(_previousBackupPath, _appDir); + + //删除旧版本备份 + _otaClient.DeleteFile(_previousBackupPath); + + } +} \ No newline at end of file diff --git a/MasstransferExporter/obj/Debug/net7.0/MasstransferExporter.AssemblyInfo.cs b/MasstransferExporter/obj/Debug/net7.0/MasstransferExporter.AssemblyInfo.cs index 783f7fa..25f5d7e 100644 --- a/MasstransferExporter/obj/Debug/net7.0/MasstransferExporter.AssemblyInfo.cs +++ b/MasstransferExporter/obj/Debug/net7.0/MasstransferExporter.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("MasstransferExporter")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c140544af7e52a0669ceafcb39aa5c4e97c5ccae")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a303714a635d3146132582a2408fc8cf76a69947")] [assembly: System.Reflection.AssemblyProductAttribute("MasstransferExporter")] [assembly: System.Reflection.AssemblyTitleAttribute("MasstransferExporter")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/MasstransferExporter/obj/Debug/net7.0/MasstransferExporter.AssemblyInfoInputs.cache b/MasstransferExporter/obj/Debug/net7.0/MasstransferExporter.AssemblyInfoInputs.cache index fd9ad27..0990bae 100644 --- a/MasstransferExporter/obj/Debug/net7.0/MasstransferExporter.AssemblyInfoInputs.cache +++ b/MasstransferExporter/obj/Debug/net7.0/MasstransferExporter.AssemblyInfoInputs.cache @@ -1 +1 @@ -b22264d67cf0b32e10f0e75ab1606fde9dde71a2b835269fbcfcdbfc81d14377 +78895e0730c7e01dfba29760f86535377f37711dd2d831a492fe0a2d3f652707 diff --git a/MasstransferExporter/obj/rider.project.model.nuget.info b/MasstransferExporter/obj/rider.project.model.nuget.info index d8f4e67..315e907 100644 --- a/MasstransferExporter/obj/rider.project.model.nuget.info +++ b/MasstransferExporter/obj/rider.project.model.nuget.info @@ -1 +1 @@ -17234348283873748 \ No newline at end of file +17234348310820990 \ No newline at end of file diff --git a/MasstransferInfrastructure/Http/ApiClient.cs b/MasstransferInfrastructure/Http/ApiClient.cs index 4a8e2c2..fe4e2fc 100644 --- a/MasstransferInfrastructure/Http/ApiClient.cs +++ b/MasstransferInfrastructure/Http/ApiClient.cs @@ -68,20 +68,6 @@ public class ApiClient : IDisposable return await response.Content.ReadFromJsonAsync(); } - /// - /// 异步下载文件 - /// - /// - /// - public static async Task DownloadFileAsync(string url, string filePath) - { - using var response = await Client.GetAsync(url); - response.EnsureSuccessStatusCode(); - - using var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None); - await response.Content.CopyToAsync(fs); - } - public void Dispose() { Client.Dispose(); diff --git a/MasstransferInfrastructure/OTA/Service/OTAService.cs b/MasstransferInfrastructure/OTA/Service/OTAService.cs deleted file mode 100644 index c34ea89..0000000 --- a/MasstransferInfrastructure/OTA/Service/OTAService.cs +++ /dev/null @@ -1,126 +0,0 @@ -using MasstransferInfrastructure.OTA.Client; -using MasstransferInfrastructure.OTA.Model; - -namespace MasstransferInfrastructure.OTA.Service; - -public class OTAService -{ - private readonly OTAClient _otaClient; - - private readonly string appDir; - private readonly string criticalBackupDir; - private readonly string criticalSourceLogPath; - private readonly string[] criticalFileExtension; - private readonly string previousBackupPath; - private readonly string updatePackagePath; - - - public OTAService(string AppDir, string CriticalBackupDir, string CriticalSourceLogPath, string[] CriticalFileExtension, string PreviousBackupPath, string UpdatePackagePath) - { - _otaClient = new OTAClient(); - appDir = AppDir; - criticalBackupDir = CriticalBackupDir; - criticalSourceLogPath = CriticalSourceLogPath; - criticalFileExtension = CriticalFileExtension; - previousBackupPath = PreviousBackupPath; - updatePackagePath = UpdatePackagePath; - } - - /// - /// 更新压缩包 - /// - public void Update() - { - try - { - //初始化 - initDir(); - - //备份重要文件 - _otaClient.BackupEssentialFiles(appDir, criticalBackupDir, criticalFileExtension, criticalSourceLogPath); - - //备份旧版本文件 - _otaClient.CompressDirectory(appDir, previousBackupPath); - - try - { - //删除旧版本原文件 - _otaClient.DeleteDirectory(appDir); - - //解压更新包 - _otaClient.ExtractDirectory(updatePackagePath, appDir); - - //恢复重要文件 - _otaClient.RecoverCriticalFiles(criticalSourceLogPath); - - //删除旧版本备份文件 - _otaClient.DeleteFile(previousBackupPath); - - //删除更新包 - _otaClient.DeleteFile(updatePackagePath); - - } - catch (Exception ex) - { - RollBack(); - Console.WriteLine($"更新异常,已回滚: {ex.Message}"); - } - } - catch (Exception ex) - { - Console.WriteLine($"更新异常e: {ex.Message}"); - - //如果重要文件备份已经产生,则删除 - if(Directory.Exists(criticalBackupDir)) - { - _otaClient.DeleteDirectory(criticalBackupDir); - } - } - } - - /// - /// 初始化重要文件备份目录 - /// - private void initDir() - { - if (Directory.Exists(criticalBackupDir)) - { - Directory.Delete(criticalBackupDir, true); - } - Directory.CreateDirectory(criticalBackupDir); - - } - - /// - /// 回滚 - /// - private void RollBack() - { - //删除安装过程中创建的文件、目录 - var directoryList = new string[] { appDir, criticalBackupDir}; - var filePath = new String[] { updatePackagePath }; - - foreach (var directory in directoryList) - { - if (Directory.Exists(directory)) - { - _otaClient.DeleteDirectory(directory); - } - } - - foreach (var file in filePath) - { - if (File.Exists(file)) - { - _otaClient.DeleteFile(file); - } - } - - //恢复旧版本文件 - _otaClient.ExtractDirectory(previousBackupPath, appDir); - - //删除旧版本备份 - _otaClient.DeleteFile(previousBackupPath); - - } -} \ No newline at end of file diff --git a/UnitTest/OTATest.cs b/UnitTest/OTATest.cs deleted file mode 100644 index 465e678..0000000 --- a/UnitTest/OTATest.cs +++ /dev/null @@ -1,31 +0,0 @@ -using MasstransferInfrastructure.OTA.Service; -namespace UnitTest; - -[TestFixture] -public class OTATest -{ - private string appDir = @"C:\Users\wangkaiyi\Desktop\DVT\OTA-TEST\Old"; - private string criticalBackupDir = @"C:\Users\wangkaiyi\Desktop\DVT\OTA-TEST\CriticalBackup"; - private string criticalSourceLogPath = @"C:\Users\wangkaiyi\Desktop\DVT\OTA-TEST\CriticalBackup\log.txt"; - private string[] criticalFileExtension = new string[] { ".db", ".reg" }; - - private string previousBackupPath = - @"C:\Users\wangkaiyi\Desktop\DVT\OTA-TEST\previousBackup.zip"; - - private string UpdatePackagePath = @"C:\Users\wangkaiyi\Desktop\DVT\OTA-TEST\New.zip"; - - [SetUp] - public void Setup() - { - - } - - [Test] - public void Test1() - { - OTAService _otaService = new OTAService(appDir, criticalBackupDir, criticalSourceLogPath, criticalFileExtension, - previousBackupPath, UpdatePackagePath); - - _otaService.Update(); - } -} \ No newline at end of file diff --git a/UnitTest/UnitTest.csproj b/UnitTest/UnitTest.csproj deleted file mode 100644 index 4bfa2ab..0000000 --- a/UnitTest/UnitTest.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - enable - enable - - false - true - - - - - - - - - - - - - - - - - - -