From 704e2b440011ecd2f93b2d86a51d355496aa4f51 Mon Sep 17 00:00:00 2001 From: Materal Date: Tue, 15 Oct 2024 16:37:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=9B=B4=E6=96=B0=E5=8C=85=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- InstallTool.bat | 4 +- Materal/Packable.props | 2 +- .../Materal.Tools.Command.csproj | 3 +- .../Program.MateralPublish.cs | 65 --- .../Program.MateralVersion.cs | 51 -- .../Properties/launchSettings.json | 2 +- .../Src/Materal.Tools.Core/DIExtensions.cs | 4 - .../MateralPublish/IMateralProject.cs | 36 -- .../MateralPublish/IMateralPublishService.cs | 40 -- .../MateralProjects/BaseMateralProject.cs | 462 ------------------ .../MateralProjects/Level0/MateralProject.cs | 11 - .../Level0/MateralToolsProject.cs | 11 - .../Level1/ContextCacheProject.cs | 12 - .../MateralProjects/Level1/LoggerProject.cs | 11 - .../MateralProjects/Level2/EventBusProject.cs | 11 - .../Level2/OscillatorProject.cs | 11 - .../MateralProjects/Level2/TTAProject.cs | 11 - .../Level4/MergeBlockProject.cs | 11 - .../MateralProjects/Level5/GatewayProject.cs | 11 - .../MateralProjects/Level5/RCProject.cs | 11 - .../MateralPublish/MateralPublishService.cs | 139 ------ .../MateralVersion/IMateralVersionService.cs | 29 -- .../MateralVersion/MateralVersionService.cs | 247 ---------- .../Pages/MateralPublishPage.xaml | 48 -- .../Pages/MateralPublishPage.xaml.cs | 17 - .../Pages/MateralVersionPage.xaml | 23 - .../Pages/MateralVersionPage.xaml.cs | 17 - Materal/Src/Materal.Tools.WinUI/PostBuild.bat | 2 +- .../ViewModels/MateralProjectViewModel.cs | 19 - .../ViewModels/MateralPublishViewModel.cs | 98 ---- .../ViewModels/MateralVersionViewModel.cs | 52 -- .../ViewModels/SolutionNotOpenedViewModel.cs | 2 +- .../MateralMergeBlockVSIX/source.extension.cs | 2 +- .../source.extension.vsixmanifest | 2 +- .../Src/MateralToolsVSIX/source.extension.cs | 2 +- .../source.extension.vsixmanifest | 2 +- ...l\345\214\205\347\274\223\345\255\230.ps1" | 4 +- RC/Directory.Packages.props | 1 - .../RC.Authority.Repository.csproj | 6 +- ...Repository.cs => RCCacheRepositoryImpl.cs} | 0 .../{RCRepository.cs => RCRepositoryImpl.cs} | 0 .../RC.EnvironmentServer.Application.csproj | 1 - 42 files changed, 19 insertions(+), 1474 deletions(-) delete mode 100644 Materal/Src/Materal.Tools.Command/Program.MateralPublish.cs delete mode 100644 Materal/Src/Materal.Tools.Command/Program.MateralVersion.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/IMateralProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/IMateralPublishService.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/BaseMateralProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level0/MateralProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level0/MateralToolsProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level1/ContextCacheProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level1/LoggerProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/EventBusProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/OscillatorProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/TTAProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level4/MergeBlockProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level5/GatewayProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level5/RCProject.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralPublish/MateralPublishService.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralVersion/IMateralVersionService.cs delete mode 100644 Materal/Src/Materal.Tools.Core/MateralVersion/MateralVersionService.cs delete mode 100644 Materal/Src/Materal.Tools.WinUI/Pages/MateralPublishPage.xaml delete mode 100644 Materal/Src/Materal.Tools.WinUI/Pages/MateralPublishPage.xaml.cs delete mode 100644 Materal/Src/Materal.Tools.WinUI/Pages/MateralVersionPage.xaml delete mode 100644 Materal/Src/Materal.Tools.WinUI/Pages/MateralVersionPage.xaml.cs delete mode 100644 Materal/Src/Materal.Tools.WinUI/ViewModels/MateralProjectViewModel.cs delete mode 100644 Materal/Src/Materal.Tools.WinUI/ViewModels/MateralPublishViewModel.cs delete mode 100644 Materal/Src/Materal.Tools.WinUI/ViewModels/MateralVersionViewModel.cs rename RC/RC.Core/RC.Core.Repository/{RCCacheRepository.cs => RCCacheRepositoryImpl.cs} (100%) rename RC/RC.Core/RC.Core.Repository/{RCRepository.cs => RCRepositoryImpl.cs} (100%) diff --git a/InstallTool.bat b/InstallTool.bat index e1f0e4d47..83f7cc95c 100644 --- a/InstallTool.bat +++ b/InstallTool.bat @@ -1,3 +1,3 @@ -dotnet tool update -g --add-source .\nupkgs Materal.Tools.Command -dotnet tool update -g --add-source .\nupkgs Materal.Logger.LoggerTrace +dotnet tool update -g --add-source .\NugetPackages Materal.Tools.Command +dotnet tool update -g --add-source .\NugetPackages Materal.Logger.LoggerTrace pause \ No newline at end of file diff --git a/Materal/Packable.props b/Materal/Packable.props index 048a88ba2..997fabd29 100644 --- a/Materal/Packable.props +++ b/Materal/Packable.props @@ -9,7 +9,7 @@ Materal Materal zh-CN - 1.1.77 + 1.1.78 https://github.com/MateralCMX/Materal README.md LICENSE diff --git a/Materal/Src/Materal.Tools.Command/Materal.Tools.Command.csproj b/Materal/Src/Materal.Tools.Command/Materal.Tools.Command.csproj index bca0f5bc1..a20b059c7 100644 --- a/Materal/Src/Materal.Tools.Command/Materal.Tools.Command.csproj +++ b/Materal/Src/Materal.Tools.Command/Materal.Tools.Command.csproj @@ -3,12 +3,13 @@ Exe net6.0;net8.0 + true Materal工具 Materal命令行工具 MateralTools - + diff --git a/Materal/Src/Materal.Tools.Command/Program.MateralPublish.cs b/Materal/Src/Materal.Tools.Command/Program.MateralPublish.cs deleted file mode 100644 index b67e0fca3..000000000 --- a/Materal/Src/Materal.Tools.Command/Program.MateralPublish.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Materal.Tools.Core.MateralPublish; -using Microsoft.Extensions.DependencyInjection; -using System.CommandLine; -using SubCommand = System.CommandLine.Command; - -namespace Materal.Tools.Command -{ - public partial class Program - { - /// - /// 添加MateralPublish命令 - /// - /// - [AddSubCommand] - public void AddMateralPublishCommand(RootCommand rootCommand) - { - SubCommand command = new("MateralPublish", "发布Materal项目"); - - Option pathOption = new("--Path", "指定路径"); - pathOption.AddAlias("-p"); - pathOption.IsRequired = false; - pathOption.SetDefaultValue(null); - command.AddOption(pathOption); - - Option versionOption = new("--Version", "指定路径"); - versionOption.AddAlias("-v"); - versionOption.IsRequired = false; - versionOption.SetDefaultValue(null); - command.AddOption(versionOption); - - command.SetHandler(MateralPublishAsync, pathOption, versionOption); - rootCommand.AddCommand(command); - } - private async Task MateralPublishAsync(string? path, string? version) - { - if (string.IsNullOrWhiteSpace(path)) - { - path = Environment.CurrentDirectory; - } - IMateralPublishService service = _serviceProvider.GetRequiredService(); - DirectoryInfo directoryInfo = new(path); - DirectoryInfo rootDirectoryInfo = service.GetMateralProjectRootPath(directoryInfo.FullName); - version ??= service.GetNowVersion(rootDirectoryInfo.FullName); - ICollection allProjects = service.GetAllProjects(); - if (directoryInfo.FullName == rootDirectoryInfo.FullName)//发布所有项目 - { - await service.PublishAsync(directoryInfo.FullName, version, allProjects); - } - else if (directoryInfo.Parent?.FullName == rootDirectoryInfo.FullName && directoryInfo.Name.StartsWith("Level"))//发布一个等级的项目 - { - int level = Convert.ToInt32(directoryInfo.Name[5..]); - ICollection levelProjects = allProjects.Where(m => m.Level == level).ToList(); - await service.PublishAsync(rootDirectoryInfo.FullName, version, levelProjects); - } - else if (directoryInfo.Parent?.Parent?.FullName == rootDirectoryInfo.FullName)//发布一个独立的项目 - { - string name = directoryInfo.Name; - int level = Convert.ToInt32(directoryInfo.Parent.Name[5..]); - IMateralProject? project = allProjects.FirstOrDefault(m => m.Level == level && m.Name == name); - if (project is null) return; - await service.PublishAsync(rootDirectoryInfo.FullName, version, [project]); - } - } - } -} diff --git a/Materal/Src/Materal.Tools.Command/Program.MateralVersion.cs b/Materal/Src/Materal.Tools.Command/Program.MateralVersion.cs deleted file mode 100644 index 4f19073d0..000000000 --- a/Materal/Src/Materal.Tools.Command/Program.MateralVersion.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Materal.Tools.Core.MateralVersion; -using Microsoft.Extensions.DependencyInjection; -using System.CommandLine; -using SubCommand = System.CommandLine.Command; - -namespace Materal.Tools.Command -{ - public partial class Program - { - /// - /// 添加MateralVersion命令 - /// - /// - [AddSubCommand] - public void AddMateralVersionCommand(RootCommand rootCommand) - { - SubCommand command = new("MateralVersion", "更改Materal的版本"); - - Option pathOption = new("--Path", "指定路径"); - pathOption.AddAlias("-p"); - pathOption.IsRequired = false; - pathOption.SetDefaultValue(null); - command.AddOption(pathOption); - - Option versionOption = new("--Version", "指定版本"); - versionOption.AddAlias("-v"); - versionOption.IsRequired = false; - versionOption.SetDefaultValue(null); - command.AddOption(versionOption); - - command.SetHandler(MateralVersion, pathOption, versionOption); - rootCommand.AddCommand(command); - } - private void MateralVersion(string? path, string? version) - { - if (string.IsNullOrWhiteSpace(path)) - { - path = Environment.CurrentDirectory; - } - IMateralVersionService service = _serviceProvider.GetRequiredService(); - if (string.IsNullOrWhiteSpace(version)) - { - service.UpdateVersionAsync(path); - } - else - { - service.UpdateVersionAsync(path, version); - } - } - } -} diff --git a/Materal/Src/Materal.Tools.Command/Properties/launchSettings.json b/Materal/Src/Materal.Tools.Command/Properties/launchSettings.json index 55daa7e32..0d9bce5e4 100644 --- a/Materal/Src/Materal.Tools.Command/Properties/launchSettings.json +++ b/Materal/Src/Materal.Tools.Command/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Materal.Tools.Command": { "commandName": "Project", - "commandLineArgs": "MateralPublish" + "commandLineArgs": "ProjectClear" } } } \ No newline at end of file diff --git a/Materal/Src/Materal.Tools.Core/DIExtensions.cs b/Materal/Src/Materal.Tools.Core/DIExtensions.cs index d58d5061c..993f469cf 100644 --- a/Materal/Src/Materal.Tools.Core/DIExtensions.cs +++ b/Materal/Src/Materal.Tools.Core/DIExtensions.cs @@ -1,8 +1,6 @@ using Materal.Tools.Core.ChangeEncoding; using Materal.Tools.Core.LFConvert; using Materal.Tools.Core.Logger; -using Materal.Tools.Core.MateralPublish; -using Materal.Tools.Core.MateralVersion; using Materal.Tools.Core.ProjectClear; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -23,8 +21,6 @@ public static IServiceCollection AddMateralTools(this IServiceCollection service { services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); #region AddLogger services.AddLogging(builder => diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/IMateralProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/IMateralProject.cs deleted file mode 100644 index 5fe11e1c1..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/IMateralProject.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace Materal.Tools.Core.MateralPublish -{ - /// - /// Materal项目 - /// - public interface IMateralProject - { - /// - /// 等级 - /// - int Level { get; } - /// - /// 位序 - /// - int Index { get; } - /// - /// 名称 - /// - string Name { get; } - /// - /// 获取根目录信息 - /// - /// - /// - DirectoryInfo GetRootDirectoryInfo(DirectoryInfo projectDirectoryInfo); - /// - /// 发布 - /// - /// - /// - /// - /// - /// - Task PublishAsync(DirectoryInfo projectDirectoryInfo, string version, DirectoryInfo? nugetDirectoryInfo = null, DirectoryInfo? publishDirectoryInfo = null); - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/IMateralPublishService.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/IMateralPublishService.cs deleted file mode 100644 index 67654939f..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/IMateralPublishService.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace Materal.Tools.Core.MateralPublish -{ - /// - /// Materal发布服务 - /// - public interface IMateralPublishService - { - /// - /// 获取所有项目 - /// - /// - ICollection GetAllProjects(); - /// - /// 获得当前版本号 - /// - /// - /// - string GetNowVersion(string projectPath); - /// - /// 发布 - /// - /// - /// - /// - /// - Task PublishAsync(string projectPath, string version, ICollection projects); - /// - /// 是Materal项目路径 - /// - /// - /// - bool IsMateralProjectPath(string projectPath); - /// - /// 获得Materal项目根路径 - /// - /// - /// - DirectoryInfo GetMateralProjectRootPath(string projectPath); - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/BaseMateralProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/BaseMateralProject.cs deleted file mode 100644 index 41a45c295..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/BaseMateralProject.cs +++ /dev/null @@ -1,462 +0,0 @@ -using Microsoft.Extensions.Logging; -using System.Diagnostics; -using System.Text; -using System.Xml; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects -{ - /// - /// 基础Materal项目 - /// - public abstract class BaseMateralProject : IMateralProject - { - /// - /// 等级 - /// - public int Level { get; } - /// - /// 位序 - /// - public int Index { get; } - /// - /// 名称 - /// - public string Name { get; } - /// - /// 日志对象 - /// - protected ILogger? Logger { get; } - /// - /// 构造方法 - /// - /// - /// - /// - /// - public BaseMateralProject(int level, int index, string name, ILoggerFactory? loggerFactory = null) - { - Level = level; - Index = index; - Name = name; - Logger = loggerFactory?.CreateLogger(GetType()); - } - /// - /// 获得根目录信息 - /// - /// - /// - public DirectoryInfo GetRootDirectoryInfo(DirectoryInfo projectDirectoryInfo) - { - string rootPath = Path.Combine(projectDirectoryInfo.FullName, $"Level{Level}", Name); - DirectoryInfo rootDirectoryInfo = new(rootPath); - return rootDirectoryInfo; - } - /// - /// 发布 - /// - /// - /// - /// - /// - /// - public virtual async Task PublishAsync(DirectoryInfo projectDirectoryInfo, string version, DirectoryInfo? nugetDirectoryInfo = null, DirectoryInfo? publishDirectoryInfo = null) - { - nugetDirectoryInfo ??= Path.Combine(projectDirectoryInfo.FullName, "Nupkgs").GetNewDirectoryInfo(); - publishDirectoryInfo ??= Path.Combine(projectDirectoryInfo.FullName, "Publish").GetNewDirectoryInfo(); - DirectoryInfo rootDirectoryInfo = GetRootDirectoryInfo(projectDirectoryInfo); - await UpdateVersionAsync(version, rootDirectoryInfo); - await PackageAsync(rootDirectoryInfo, nugetDirectoryInfo); - await PublishAsync(rootDirectoryInfo, publishDirectoryInfo); - } - #region 版本更新 - /// - /// 更新版本 - /// - /// - /// - /// - protected virtual async Task UpdateVersionAsync(string version, DirectoryInfo directoryInfo) - { - if (!directoryInfo.Exists) throw new ToolsException($"{directoryInfo.FullName}不存在"); - FileInfo? csprojFileInfo = directoryInfo.GetFiles().FirstOrDefault(m => m.Extension == ".csproj"); - FileInfo? vsixmanifestFileInfo = directoryInfo.GetFiles().FirstOrDefault(m => m.Name == "source.extension.vsixmanifest"); - if (vsixmanifestFileInfo != null) - { - await UpdateVsixVersionAsync(version, vsixmanifestFileInfo); - } - else if (csprojFileInfo != null) - { - await UpdateCsprojVersionAsync(version, csprojFileInfo); - } - else - { - IEnumerable subDirectoryInfos = directoryInfo.GetDirectories(); - foreach (DirectoryInfo subDirectoryInfo in subDirectoryInfos) - { - await UpdateVersionAsync(version, subDirectoryInfo); - } - } - } - /// - /// 更新版本 - /// - /// - /// - /// - protected virtual async Task UpdateVsixVersionAsync(string version, FileInfo fileInfo) - { - string projectName = Path.GetFileNameWithoutExtension(fileInfo.Name); - XmlDocument xmlDocument = new(); - xmlDocument.Load(fileInfo.FullName); - XmlNamespaceManager nsmgr = new(xmlDocument.NameTable); - nsmgr.AddNamespace("vsx", "http://schemas.microsoft.com/developer/vsx-schema/2011"); - XmlNode identityNode = xmlDocument.SelectSingleNode("//vsx:Identity", nsmgr) ?? throw new ToolsException($"{fileInfo.FullName}文件格式错误"); - if (identityNode.Attributes is null || identityNode.Attributes.Count <= 0) return; - XmlAttribute? versionAttribute = identityNode.Attributes["Version"]; - if (versionAttribute is null) return; - if (!versionAttribute.Value.StartsWith(version)) - { - string newVersion = $"{version}.1"; - Logger?.LogInformation($"正在更新{projectName}版本到{newVersion}"); - versionAttribute.Value = newVersion; - } - string xmlContent = xmlDocument.GetFormatXmlContent(); - xmlContent = xmlContent.Trim(); - await File.WriteAllTextAsync(fileInfo.FullName, xmlContent, Encoding.UTF8); - } - /// - /// 更新版本 - /// - /// - /// - /// - protected virtual async Task UpdateCsprojVersionAsync(string version, FileInfo fileInfo) - { - string projectName = Path.GetFileNameWithoutExtension(fileInfo.Name); - XmlDocument xmlDocument = new(); - xmlDocument.Load(fileInfo.FullName); - XmlNode? projectNode = xmlDocument.SelectSingleNode("//Project"); - if (projectNode is null) return; - foreach (XmlNode node in projectNode.ChildNodes) - { - switch (node.Name) - { - case "PropertyGroup": - UpdateCsprojPropertyGroupVersion(projectName, version, node); - break; - case "ItemGroup": - UpdateCsprojItemGroupVersion(projectName, version, node); - break; - } - } - string xmlContent = xmlDocument.GetFormatXmlContent(); - xmlContent = xmlContent.StartsWith(" xmlContent[(xmlContent.IndexOf("?>", StringComparison.Ordinal) + 2)..], - false => xmlContent - }; - xmlContent = xmlContent.Trim(); - await File.WriteAllTextAsync(fileInfo.FullName, xmlContent, Encoding.UTF8); - } - /// - /// 更新Csproj PropertyGroup版本 - /// - /// - /// - /// - protected virtual void UpdateCsprojPropertyGroupVersion(string projectName, string version, XmlNode node) - { - foreach (XmlNode childNode in node.ChildNodes) - { - if (childNode.Name != "Version") continue; - if (childNode.InnerText == version) return; - Logger?.LogInformation($"正在更新{projectName}版本到{version}"); - childNode.InnerText = version; - return; - } - } - /// - /// 更新Csproj PropertyGroup版本 - /// - /// - /// - /// - protected virtual void UpdateCsprojItemGroupVersion(string projectName, string version, XmlNode node) - { - foreach (XmlNode childNode in node.ChildNodes) - { - if (childNode.Name != "PackageReference" || childNode.Attributes is null || childNode.Attributes.Count <= 0) continue; - XmlAttribute? nameAttribute = childNode.Attributes["Include"]; - if (nameAttribute is null || (!nameAttribute.Value.StartsWith("Materal.") && !nameAttribute.Value.StartsWith("RC."))) continue; - XmlAttribute? versionAttribute = childNode.Attributes["Version"]; - if (versionAttribute is null) continue; - if (versionAttribute.Value == version) return; - Logger?.LogInformation($"正在更新{projectName}->{nameAttribute.Value}的版本到{version}"); - versionAttribute.Value = version; - return; - } - } - #endregion - #region 打包 - /// - /// 打包 - /// - /// - /// - /// - protected virtual async Task PackageAsync(DirectoryInfo directoryInfo, DirectoryInfo nugetDirectoryInfo) - { - if (!directoryInfo.Exists) throw new ToolsException($"{directoryInfo.FullName}不存在"); - FileInfo? csprojFileInfo = directoryInfo.GetFiles().FirstOrDefault(m => m.Extension == ".csproj"); - if (csprojFileInfo != null) - { - if (!CanPackage(csprojFileInfo)) return; - await PackageAsync(csprojFileInfo, nugetDirectoryInfo); - } - else - { - IEnumerable subDirectoryInfos = directoryInfo.GetDirectories(); - foreach (DirectoryInfo subDirectoryInfo in subDirectoryInfos) - { - await PackageAsync(subDirectoryInfo, nugetDirectoryInfo); - } - } - } - /// - /// 打包 - /// - /// - /// - protected virtual bool CanPackage(FileInfo fileInfo) - { - if (!fileInfo.Exists) return false; - XmlDocument xmlDocument = new(); - xmlDocument.Load(fileInfo.FullName); - XmlNode? isPackableNode = xmlDocument.SelectSingleNode("//Project//PropertyGroup//IsPackable"); - if (isPackableNode is null) return false; - if (!string.IsNullOrWhiteSpace(isPackableNode.InnerText) && isPackableNode.InnerText.Equals("true", StringComparison.OrdinalIgnoreCase)) return true; - return false; - } - /// - /// 打包 - /// - /// - /// - /// - protected virtual async Task PackageAsync(FileInfo fileInfo, DirectoryInfo nugetDirectoryInfo) - { - string projectName = Path.GetFileNameWithoutExtension(fileInfo.Name); - CmdHelper cmdHelper = new(); - string[] cmds = GetPackageCommand(fileInfo, nugetDirectoryInfo); - Logger?.LogInformation($"正在打包{projectName}..."); - cmdHelper.OutputDataReceived += CmdHelper_OutputDataReceived; - cmdHelper.ErrorDataReceived += CmdHelper_ErrorDataReceived; - await cmdHelper.RunCmdCommandsAsync(cmds); - Logger?.LogInformation($"{projectName}打包完毕"); - } - - /// - /// 获得发布命令 - /// - /// - /// - /// - protected virtual string[] GetPackageCommand(FileInfo fileInfo, DirectoryInfo nugetDirectoryInfo) - => [$"msbuild {fileInfo.FullName} /t:restore", - $"msbuild {fileInfo.FullName} /t:pack /t:Rebuild /p:Configuration=Release /p:PackageOutputPath={nugetDirectoryInfo}"]; - #endregion - #region 发布 - /// - /// 发布 - /// - /// - /// - /// - protected virtual async Task PublishAsync(DirectoryInfo directoryInfo, DirectoryInfo publishDirectoryInfo) - { - if (!directoryInfo.Exists) throw new ToolsException($"{directoryInfo.FullName}不存在"); - FileInfo? csprojFileInfo = directoryInfo.GetFiles().FirstOrDefault(m => m.Extension == ".csproj"); - if (csprojFileInfo != null) - { - if (CanPublish(csprojFileInfo)) - { - await PublishAsync(csprojFileInfo, publishDirectoryInfo); - } - else if (CanPublishVSIX(csprojFileInfo)) - { - await PublishVSIXAsync(csprojFileInfo, publishDirectoryInfo); - } - } - else - { - IEnumerable subDirectoryInfos = directoryInfo.GetDirectories(); - foreach (DirectoryInfo subDirectoryInfo in subDirectoryInfos) - { - await PublishAsync(subDirectoryInfo, publishDirectoryInfo); - } - } - } - /// - /// 能否发布 - /// - /// - /// - protected virtual bool CanPublish(FileInfo fileInfo) - { - if (!fileInfo.Exists) return false; - XmlDocument xmlDocument = new(); - xmlDocument.Load(fileInfo.FullName); - XmlNode? isPublishNode = xmlDocument.SelectSingleNode("//Project//PropertyGroup//IsPublish"); - if (isPublishNode is null) return false; - if (!string.IsNullOrWhiteSpace(isPublishNode.InnerText) && isPublishNode.InnerText.Equals("true", StringComparison.OrdinalIgnoreCase)) return true; - return false; - } - /// - /// 发布 - /// - /// - /// - /// - protected virtual async Task PublishAsync(FileInfo fileInfo, DirectoryInfo publishDirectoryInfo) - { - string projectName = Path.GetFileNameWithoutExtension(fileInfo.Name); - CmdHelper cmdHelper = new(); - string[] cmds = GetPublishCommand(fileInfo, publishDirectoryInfo); - Logger?.LogInformation($"正在发布{projectName}..."); - cmdHelper.OutputDataReceived += CmdHelper_OutputDataReceived; - cmdHelper.ErrorDataReceived += CmdHelper_ErrorDataReceived; - await cmdHelper.RunCmdCommandsAsync(cmds); - Logger?.LogInformation($"{projectName}发布完毕"); - } - /// - /// 获得发布命令 - /// - /// - /// - /// - protected virtual string[] GetPublishCommand(FileInfo fileInfo, DirectoryInfo publishDirectoryInfo) - { - List cmds = [$"msbuild {fileInfo.FullName} /t:restore",]; - XmlDocument xmlDocument = new(); - xmlDocument.Load(fileInfo.FullName); - XmlNode? targetFrameworksNode = xmlDocument.SelectSingleNode("//Project//PropertyGroup//TargetFrameworks"); - if (targetFrameworksNode is null) - { - cmds.Add(GetPublishCommand(fileInfo, publishDirectoryInfo, null)); - } - else - { - string[] targets = targetFrameworksNode.InnerText.Split(';'); - foreach (string target in targets) - { - cmds.Add(GetPublishCommand(fileInfo, publishDirectoryInfo, target)); - } - } - return [.. cmds]; - } - /// - /// 获得发布命令 - /// - /// - /// - /// - /// - protected virtual string GetPublishCommand(FileInfo fileInfo, DirectoryInfo publishDirectoryInfo, string? targetFrameworks) - { - string projectName = Path.GetFileNameWithoutExtension(fileInfo.Name); - StringBuilder cmdBuilder = new(); - cmdBuilder.Append($"msbuild {fileInfo.FullName} /t:Rebuild /p:Configuration=Release"); - DirectoryInfo publishProjectDirectoryInfo = Path.Combine(publishDirectoryInfo.FullName, projectName).GetNewDirectoryInfo(); - if (!string.IsNullOrWhiteSpace(targetFrameworks)) - { - publishProjectDirectoryInfo = Path.Combine(publishProjectDirectoryInfo.FullName, targetFrameworks).GetNewDirectoryInfo(); - cmdBuilder.Append($" /p:TargetFramework={targetFrameworks}"); - } - string? publishPath = publishProjectDirectoryInfo.FullName; - cmdBuilder.Append($" /p:OutputPath={publishPath}"); - string cmd = cmdBuilder.ToString(); - return cmd; - } - /// - /// 能否发布VS插件 - /// - /// - /// - protected virtual bool CanPublishVSIX(FileInfo fileInfo) - { - if (!fileInfo.Exists || fileInfo.Directory is null || !fileInfo.Directory.GetFiles().Any(m => m.Name == "source.extension.vsixmanifest")) return false; - XmlDocument xmlDocument = new(); - xmlDocument.Load(fileInfo.FullName); - XmlNamespaceManager nsmgr = new(xmlDocument.NameTable); - nsmgr.AddNamespace("vsx", "http://schemas.microsoft.com/developer/msbuild/2003"); - XmlNode? isPublishNode = xmlDocument.SelectSingleNode("//vsx:IsPublish", nsmgr); - if (isPublishNode is null) return false; - if (!string.IsNullOrWhiteSpace(isPublishNode.InnerText) && isPublishNode.InnerText.Equals("true", StringComparison.OrdinalIgnoreCase)) return true; - return false; - } - /// - /// 发布VS插件 - /// - /// - /// - /// - protected virtual async Task PublishVSIXAsync(FileInfo fileInfo, DirectoryInfo publishDirectoryInfo) - { - string projectName = Path.GetFileNameWithoutExtension(fileInfo.Name); - CmdHelper cmdHelper = new(); - DirectoryInfo publishProjectDirectoryInfo = Path.Combine(publishDirectoryInfo.FullName, projectName).GetNewDirectoryInfo(); - string[] cmds = GetPublishVSIXCommand(fileInfo, publishProjectDirectoryInfo); - Logger?.LogInformation($"正在发布VS插件{projectName}..."); - cmdHelper.OutputDataReceived += CmdHelper_OutputDataReceived; - cmdHelper.ErrorDataReceived += CmdHelper_ErrorDataReceived; - await cmdHelper.RunCmdCommandsAsync(cmds); - FileInfo vsixFileInfo = new(Path.Combine(publishProjectDirectoryInfo.FullName, $"{projectName}.vsix")); - if (!vsixFileInfo.Exists) throw new ToolsException($"{vsixFileInfo.FullName}不存在"); - vsixFileInfo.MoveTo(Path.Combine(publishDirectoryInfo.FullName, vsixFileInfo.Name)); - publishProjectDirectoryInfo.Delete(true); - Logger?.LogInformation($"VS插件{projectName}发布完毕"); - } - /// - /// 获得发布命令 - /// - /// - /// - /// - protected virtual string[] GetPublishVSIXCommand(FileInfo fileInfo, DirectoryInfo publishDirectoryInfo) - => [$"msbuild {fileInfo.FullName} /t:restore", - $"msbuild {fileInfo.FullName} /t:Rebuild /p:Configuration=Release /p:OutputPath={publishDirectoryInfo.FullName}"]; - #endregion - /// - /// 输出错误 - /// - /// - /// - private void CmdHelper_ErrorDataReceived(object sender, DataReceivedEventArgs e) - { - if (string.IsNullOrWhiteSpace(e.Data)) return; - Logger?.LogError(e.Data); - } - /// - /// 输出数据 - /// - /// - /// - private void CmdHelper_OutputDataReceived(object sender, DataReceivedEventArgs e) - { - if (string.IsNullOrWhiteSpace(e.Data)) return; - LogLevel logLevel = LogLevel.Information; - if (!string.IsNullOrWhiteSpace(e.Data)) - { - if (e.Data.Contains(" error ", StringComparison.OrdinalIgnoreCase)) - { - logLevel = LogLevel.Error; - } - else if (e.Data.Contains(" warning ", StringComparison.OrdinalIgnoreCase)) - { - logLevel = LogLevel.Warning; - } - } - Logger?.Log(logLevel, e.Data); - } - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level0/MateralProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level0/MateralProject.cs deleted file mode 100644 index d73142174..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level0/MateralProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level0 -{ - /// - /// Materal项目 - /// - public class MateralProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(0, 1, "Materal", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level0/MateralToolsProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level0/MateralToolsProject.cs deleted file mode 100644 index 21f1ac8ed..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level0/MateralToolsProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level0 -{ - /// - /// MateralTools项目 - /// - public class MateralToolsProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(0, 0, "Materal.Tools", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level1/ContextCacheProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level1/ContextCacheProject.cs deleted file mode 100644 index b7368a6c4..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level1/ContextCacheProject.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level1 -{ - /// - /// 上下文缓存项目 - /// - /// - public class ContextCacheProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(1, 1, "Materal.ContextCache", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level1/LoggerProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level1/LoggerProject.cs deleted file mode 100644 index 817c0ce03..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level1/LoggerProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level1 -{ - /// - /// 日志项目 - /// - public class LoggerProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(1, 0, "Materal.Logger", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/EventBusProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/EventBusProject.cs deleted file mode 100644 index 19210aaaa..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/EventBusProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level2 -{ - /// - /// 事件总线 - /// - public class EventBusProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(2, 1, "Materal.EventBus", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/OscillatorProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/OscillatorProject.cs deleted file mode 100644 index 415024cb4..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/OscillatorProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level2 -{ - /// - /// 调度器 - /// - public class OscillatorProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(2, 2, "Materal.Oscillator", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/TTAProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/TTAProject.cs deleted file mode 100644 index 28ac82073..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level2/TTAProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level2 -{ - /// - /// TTA框架 - /// - public class TTAProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(2, 0, "Materal.ThreeTierArchitecture", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level4/MergeBlockProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level4/MergeBlockProject.cs deleted file mode 100644 index d5e474b04..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level4/MergeBlockProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level4 -{ - /// - /// MergeBlock - /// - public class MergeBlockProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(4, 0, "Materal.MergeBlock", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level5/GatewayProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level5/GatewayProject.cs deleted file mode 100644 index 37f2d8b38..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level5/GatewayProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level5 -{ - /// - /// 网关 - /// - public class GatewayProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(5, 0, "Materal.Gateway", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level5/RCProject.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level5/RCProject.cs deleted file mode 100644 index bb631b573..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralProjects/Level5/RCProject.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish.MateralProjects.Level5 -{ - /// - /// RC项目 - /// - public class RCProject(ILoggerFactory? loggerFactory = null) : BaseMateralProject(5, 1, "RC", loggerFactory) - { - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralPublishService.cs b/Materal/Src/Materal.Tools.Core/MateralPublish/MateralPublishService.cs deleted file mode 100644 index 813dd6d2b..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralPublish/MateralPublishService.cs +++ /dev/null @@ -1,139 +0,0 @@ -using Microsoft.Extensions.Logging; - -namespace Materal.Tools.Core.MateralPublish -{ - /// - /// Materal发布服务 - /// - public class MateralPublishService(ILoggerFactory? loggerFactory = null) : IMateralPublishService - { - private readonly ILogger? _logger = loggerFactory?.CreateLogger(); - /// - /// 获得所有项目 - /// - /// - /// - public ICollection GetAllProjects() - { - Type baseProjectType = typeof(IMateralProject); - List allProjectTypes = baseProjectType.Assembly.GetTypes().Where(m => !m.IsAbstract && m.IsAssignableTo(baseProjectType)).ToList(); - List _projects = []; - foreach (Type projectType in allProjectTypes) - { - ConstructorInfo? constructorInfo = projectType.GetConstructor([typeof(ILoggerFactory)]) ?? throw new ToolsException("未找到构造函数"); - object projectObj = constructorInfo.Invoke([loggerFactory]); - if (projectObj is not IMateralProject projectModel) throw new ToolsException("类型不是IMateralProject"); - _projects.Add(projectModel); - } - _projects = [.. _projects.OrderBy(m => m.Level).ThenBy(m => m.Index).ThenBy(m => m.Name)]; - return _projects; - } - /// - /// 获得当前版本号 - /// - /// - /// - /// - public string GetNowVersion(string projectPath) - { - DirectoryInfo projectDirectoryInfo = GetMateralProjectRootPath(projectPath); - if (!projectDirectoryInfo.Exists) throw new ToolsException($"\"{projectDirectoryInfo}\"文件夹不存在"); - string csprojFilePath = Path.Combine(projectDirectoryInfo.FullName, "Level0", "Materal", "Src", "Materal.Abstractions", "Materal.Abstractions.csproj"); - FileInfo csprojFileInfo = new(csprojFilePath); - if (!csprojFileInfo.Exists) throw new ToolsException($"\"{csprojFileInfo.FullName}\"不存在"); - string[] codeContent = File.ReadAllLines(csprojFileInfo.FullName); - const string versionStartCode = ""; - const string versionEndCode = ""; - foreach (string code in codeContent) - { - string tempCode = code.Trim(); - if (tempCode.StartsWith(versionStartCode)) - { - int endStartIndex = tempCode.IndexOf(versionEndCode); - string result = tempCode[versionStartCode.Length..endStartIndex]; - return result; - } - } - throw new ToolsException("未找到版本号"); - } - /// - /// 获得Materal项目根路径 - /// - /// - /// - /// - public DirectoryInfo GetMateralProjectRootPath(string projectPath) - { - DirectoryInfo? projectDirectoryInfo = new(projectPath); - if (!projectDirectoryInfo.Exists) throw new ToolsException($"\"{projectDirectoryInfo}\"文件夹不存在"); - string csprojFilePath = Path.Combine(projectDirectoryInfo.FullName, "Level0", "Materal", "Src", "Materal.Abstractions", "Materal.Abstractions.csproj"); - FileInfo csprojFileInfo = new(csprojFilePath); - if (csprojFileInfo.Exists) return projectDirectoryInfo; - projectDirectoryInfo = projectDirectoryInfo.Parent; - if (projectDirectoryInfo is null) throw new ToolsException("未找到Materal项目根路径"); - csprojFilePath = Path.Combine(projectDirectoryInfo.FullName, "Level0", "Materal", "Src", "Materal.Abstractions", "Materal.Abstractions.csproj"); - csprojFileInfo = new(csprojFilePath); - if (csprojFileInfo.Exists) return projectDirectoryInfo; - projectDirectoryInfo = projectDirectoryInfo.Parent; - if (projectDirectoryInfo is null) throw new ToolsException("未找到Materal项目根路径"); - csprojFilePath = Path.Combine(projectDirectoryInfo.FullName, "Level0", "Materal", "Src", "Materal.Abstractions", "Materal.Abstractions.csproj"); - csprojFileInfo = new(csprojFilePath); - if (csprojFileInfo.Exists) return projectDirectoryInfo; - throw new ToolsException("未找到Materal项目根路径"); - } - /// - /// 是Materal项目路径 - /// - /// - /// - /// - public bool IsMateralProjectPath(string projectPath) - { - try - { - GetMateralProjectRootPath(projectPath); - return true; - } - catch - { - return false; - } - } - - /// - /// 发布 - /// - /// - /// - /// - /// - public async Task PublishAsync(string projectPath, string version, ICollection projects) - { - _logger?.LogInformation("开始发布..."); - ClearNugetPackages(); - DirectoryInfo projectDirectoryInfo = new(projectPath); - foreach (IMateralProject project in projects) - { - _logger?.LogInformation($"开始发布{project.Name}..."); - await project.PublishAsync(projectDirectoryInfo, version); - _logger?.LogInformation($"{project.Name}发布完毕"); - } - _logger?.LogInformation("发布完毕"); - } - private void ClearNugetPackages() - { - _logger?.LogInformation($"开始清理包缓存..."); - string nugetPackagesPath = Environment.GetEnvironmentVariable("NUGET_PACKAGES") ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); - DirectoryInfo nugetDirectoryInfo = new(nugetPackagesPath); - if (!nugetDirectoryInfo.Exists) return; - DirectoryInfo[] directoryInfos = nugetDirectoryInfo.GetDirectories(); - foreach (DirectoryInfo directoryInfo in directoryInfos) - { - if (!directoryInfo.Name.StartsWith("materal.") && !directoryInfo.Name.StartsWith("rc.")) continue; - _logger?.LogInformation($"删除包缓存:{directoryInfo.FullName}"); - directoryInfo.Delete(true); - } - _logger?.LogInformation($"包缓存清理完毕"); - } - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralVersion/IMateralVersionService.cs b/Materal/Src/Materal.Tools.Core/MateralVersion/IMateralVersionService.cs deleted file mode 100644 index 09236e382..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralVersion/IMateralVersionService.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace Materal.Tools.Core.MateralVersion -{ - /// - /// Materal版本服务 - /// - public interface IMateralVersionService - { - /// - /// 更新版本 - /// - /// - /// - /// - Task UpdateVersionAsync(string projectPath, string[]? nugetPaths = null); - /// - /// 更新版本 - /// - /// - /// - /// - Task UpdateVersionAsync(string projectPath, string version); - /// - /// 获得当前版本 - /// - /// - /// - Task GetNowVersionAsync(string[]? nugetPaths = null); - } -} diff --git a/Materal/Src/Materal.Tools.Core/MateralVersion/MateralVersionService.cs b/Materal/Src/Materal.Tools.Core/MateralVersion/MateralVersionService.cs deleted file mode 100644 index fe48e983c..000000000 --- a/Materal/Src/Materal.Tools.Core/MateralVersion/MateralVersionService.cs +++ /dev/null @@ -1,247 +0,0 @@ -using Microsoft.Extensions.Logging; -using System.Net; -using System.Text; -using System.Xml; - -namespace Materal.Tools.Core.MateralVersion -{ - /// - /// Materal版本服务 - /// - public class MateralVersionService(ILogger? logger = null) : IMateralVersionService - { - private readonly string[] _defaultNugetPaths = { - "https://nuget.gudianbustu.com/nuget/", - @"E:\Project\Materal\Materal\Nupkgs" - }; - private const string _materalID = "Materal.Abstractions"; - private readonly HttpClient _httpClient = new(); - /// - /// 更新版本 - /// - /// - /// - /// - public async Task UpdateVersionAsync(string projectPath, string[]? nugetPaths = null) - { - logger?.LogInformation("正在获取最新的Materal版本..."); - string version = await GetNowVersionAsync(nugetPaths); - logger?.LogInformation($"最新的Materal版本为{version}"); - await UpdateVersionAsync(projectPath, version); - } - /// - /// 更新版本 - /// - /// - /// - /// - public async Task UpdateVersionAsync(string projectPath, string version) - { - logger?.LogInformation($"开始更新Materal版本到{version}..."); - DirectoryInfo directoryInfo = new(projectPath); - await UpdateVersionAsync(version, directoryInfo); - logger?.LogInformation("Materal版本更新完毕"); - } - /// - /// 更新版本 - /// - /// - /// - /// - protected virtual async Task UpdateVersionAsync(string version, DirectoryInfo directoryInfo) - { - if (!directoryInfo.Exists) throw new ToolsException($"{directoryInfo.FullName}不存在"); - FileInfo? csprojFileInfo = directoryInfo.GetFiles().FirstOrDefault(m => m.Extension == ".csproj"); - if (csprojFileInfo != null) - { - await UpdateCsprojVersionAsync(version, csprojFileInfo); - } - else - { - IEnumerable subDirectoryInfos = directoryInfo.GetDirectories(); - foreach (DirectoryInfo subDirectoryInfo in subDirectoryInfos) - { - await UpdateVersionAsync(version, subDirectoryInfo); - } - } - } - /// - /// 更新版本 - /// - /// - /// - /// - protected virtual async Task UpdateCsprojVersionAsync(string version, FileInfo fileInfo) - { - string projectName = Path.GetFileNameWithoutExtension(fileInfo.Name); - XmlDocument xmlDocument = new(); - xmlDocument.Load(fileInfo.FullName); - XmlNode? projectNode = xmlDocument.SelectSingleNode("//Project"); - if (projectNode is null) return; - foreach (XmlNode node in projectNode.ChildNodes) - { - if (node.Name != "ItemGroup") continue; - UpdateCsprojItemGroupVersion(projectName, version, node); - } - string xmlContent = xmlDocument.GetFormatXmlContent(); - xmlContent = xmlContent.StartsWith(" xmlContent[(xmlContent.IndexOf("?>", StringComparison.Ordinal) + 2)..], - false => xmlContent - }; - xmlContent = xmlContent.Trim(); - await File.WriteAllTextAsync(fileInfo.FullName, xmlContent, Encoding.UTF8); - } - /// - /// 更新Csproj PropertyGroup版本 - /// - /// - /// - /// - protected virtual void UpdateCsprojItemGroupVersion(string projectName, string version, XmlNode node) - { - foreach (XmlNode childNode in node.ChildNodes) - { - if (childNode.Name != "PackageReference" || childNode.Attributes is null || childNode.Attributes.Count <= 0) continue; - XmlAttribute? nameAttribute = childNode.Attributes["Include"]; - if (nameAttribute is null || (!nameAttribute.Value.StartsWith("Materal.") && !nameAttribute.Value.StartsWith("RC."))) continue; - XmlAttribute? versionAttribute = childNode.Attributes["Version"]; - if (versionAttribute is null) continue; - if (versionAttribute.Value == version) continue; - logger?.LogInformation($"正在更新{projectName}->{nameAttribute.Value}的版本到{version}"); - versionAttribute.Value = version; - } - } - /// - /// 获得当前版本 - /// - /// - /// - /// - public async Task GetNowVersionAsync(string[]? nugetPaths = null) - { - string? version = null; - nugetPaths ??= _defaultNugetPaths; - foreach (string nugetPath in nugetPaths) - { - try - { - string tempVersion = await GetNowVersionAsync(nugetPath); - if (string.IsNullOrWhiteSpace(version)) - { - version = tempVersion; - } - else - { - version = GetMaxVersion(version, tempVersion); - } - } - catch - { - } - } - if (string.IsNullOrWhiteSpace(version)) throw new ToolsException("未找到Nuget包"); - return version; - } - /// - /// 获得当前版本 - /// - /// - /// - /// - private async Task GetNowVersionAsync(string nugetPath) - { - if (nugetPath.StartsWith("http")) - { - return await GetNowVersionByServerAsync(nugetPath); - } - else - { - return GetNowVersionByLocal(nugetPath); - } - } - /// - /// 通过本地获得当前版本 - /// - /// - /// - private static string GetNowVersionByLocal(string nugegtPath) - { - DirectoryInfo directoryInfo = new(nugegtPath); - if (!directoryInfo.Exists) throw new ToolsException($"{nugegtPath}不存在"); - FileInfo[] files = directoryInfo.GetFiles($"{_materalID}.*.nupkg"); - string? version = null; - foreach (FileInfo file in files) - { - string tempVersion = file.Name[(_materalID.Length + 1)..^6]; - if (version is null) - { - version = tempVersion; - } - else - { - version = GetMaxVersion(version, tempVersion); - } - } - if (version is null) throw new ToolsException($"获取版本失败"); - return version; - } - /// - /// 通过服务器获得当前版本 - /// - /// - /// - private async Task GetNowVersionByServerAsync(string nugetUrl) - { - string url = $"{nugetUrl}Packages"; - HttpRequestMessage httpRequestMessage = new() - { - RequestUri = new Uri(url), - Method = HttpMethod.Get - }; - HttpResponseMessage httpResponseMessage = await _httpClient.SendAsync(httpRequestMessage); - if (httpResponseMessage.StatusCode != HttpStatusCode.OK) throw new Exception($"[{httpResponseMessage.StatusCode}]访问Nuget服务器失败"); - using MemoryStream memoryStream = new(); - await httpResponseMessage.Content.CopyToAsync(memoryStream); - byte[] buffer = memoryStream.ToArray(); - string httpResponseResult = Encoding.UTF8.GetString(buffer); - XmlDocument xmlDocument = new(); - xmlDocument.LoadXml(httpResponseResult); - XmlNamespaceManager nsmgr = new(xmlDocument.NameTable); - nsmgr.AddNamespace("vsx", "http://www.w3.org/2005/Atom"); - XmlNodeList? entryNodes = xmlDocument.SelectNodes("//vsx:entry", nsmgr); - if (entryNodes is null) throw new Exception($"未在Nuget服务器上找到包{_materalID}"); - string? version = null; - foreach (XmlNode item in entryNodes) - { - string? value = item.FirstChild?.InnerText; - if (string.IsNullOrWhiteSpace(value)) continue; - value = value[$"{nugetUrl}Packages(Id='".Length..]; - string id = value[.._materalID.Length]; - if (id != _materalID) continue; - version = GetMaxVersion(value[(id.Length + 11)..^2], version); - } - if (string.IsNullOrWhiteSpace(version)) throw new Exception($"未在Nuget服务器上找到包{_materalID}"); - return version; - } - /// - /// 获得最大版本号 - /// - /// - /// - /// - public static string GetMaxVersion(string version1, string? version2) - { - if (version2 is null || string.IsNullOrEmpty(version2)) return version1; - int[] version1s = version1.Split('.').Select(m => Convert.ToInt32(m)).ToArray(); - int[] version2s = version2.Split('.').Select(m => Convert.ToInt32(m)).ToArray(); - int length = version1s.Length > version2s.Length ? version2s.Length : version1s.Length; - for (int i = 0; i < length; i++) - { - if (version1s[i] > version2s[i]) return version1; - if (version2s[i] > version1s[i]) return version2; - } - return version1s.Length >= version2s.Length ? version1 : version2; - } - } -} diff --git a/Materal/Src/Materal.Tools.WinUI/Pages/MateralPublishPage.xaml b/Materal/Src/Materal.Tools.WinUI/Pages/MateralPublishPage.xaml deleted file mode 100644 index fe8bfe1fe..000000000 --- a/Materal/Src/Materal.Tools.WinUI/Pages/MateralPublishPage.xaml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - -