diff --git a/Apollo.AspNetCore.Demo/Apollo.AspNetCore.Demo.csproj b/Apollo.AspNetCore.Demo/Apollo.AspNetCore.Demo.csproj index 1f18af7..3e3caad 100644 --- a/Apollo.AspNetCore.Demo/Apollo.AspNetCore.Demo.csproj +++ b/Apollo.AspNetCore.Demo/Apollo.AspNetCore.Demo.csproj @@ -2,6 +2,7 @@ net6 + false diff --git a/Apollo.AspNetCoreHosting/Apollo.AspNetCoreHosting.csproj b/Apollo.AspNetCoreHosting/Apollo.AspNetCoreHosting.csproj index 62c11af..2718c7d 100644 --- a/Apollo.AspNetCoreHosting/Apollo.AspNetCoreHosting.csproj +++ b/Apollo.AspNetCoreHosting/Apollo.AspNetCoreHosting.csproj @@ -11,17 +11,17 @@   直接使用ApolloConfigurationManager请使用Com.Ctrip.Framework.Apollo.Configuration或者Com.Ctrip.Framework.Apollo.ConfigurationManager $(PackageReleaseNotes) - https://raw.githubusercontent.com/apolloconfig/apollo/master/apollo-portal/src/main/resources/static/img/config.png - $(RepositoryUrl)/$(MSBuildProjectName) Microsoft.AspNetCore.Hosting - netstandard2.0 + netcoreapp3.1 $(ApolloVersion).0 + - + + diff --git a/Apollo.ConfigAdapter.Yaml/Apollo.ConfigAdapter.Yaml.csproj b/Apollo.ConfigAdapter.Yaml/Apollo.ConfigAdapter.Yaml.csproj index 8866d6f..e7fd2e8 100644 --- a/Apollo.ConfigAdapter.Yaml/Apollo.ConfigAdapter.Yaml.csproj +++ b/Apollo.ConfigAdapter.Yaml/Apollo.ConfigAdapter.Yaml.csproj @@ -2,8 +2,6 @@ Com.Ctrip.Framework.Apollo.ConfigAdapter.Yaml - https://raw.githubusercontent.com/apolloconfig/apollo/master/apollo-portal/src/main/resources/static/img/config.png - $(RepositoryUrl)/$(MSBuildProjectName) 发布日志请点击打开 https://github.com/apolloconfig/apollo.net/releases 添加对yml和yaml格式的namespace支持,使用YamlConfigAdapter.Register()添加支持。 diff --git a/Apollo.ConfigAdapter.Yaml/YamlConfigurationFileParser.cs b/Apollo.ConfigAdapter.Yaml/YamlConfigurationFileParser.cs index 61b4855..3f6b9f8 100644 --- a/Apollo.ConfigAdapter.Yaml/YamlConfigurationFileParser.cs +++ b/Apollo.ConfigAdapter.Yaml/YamlConfigurationFileParser.cs @@ -5,7 +5,7 @@ namespace Com.Ctrip.Framework.Apollo.ConfigAdapter; internal class YamlConfigurationFileParser { - private readonly IDictionary _data = new SortedDictionary(StringComparer.OrdinalIgnoreCase); + private readonly IDictionary _data = new Dictionary(StringComparer.OrdinalIgnoreCase); private readonly Stack _context = new(); private string _currentPath = ""; @@ -16,12 +16,13 @@ public IDictionary Parse(TextReader reader) var yamlStream = new YamlStream(); yamlStream.Load(reader); - if (yamlStream.Documents.Count > 0 && yamlStream.Documents[0].RootNode is YamlMappingNode mappingNode) - foreach (var node in mappingNode.Children) - if (node.Key is YamlScalarNode ysn && ysn.Value != null) - VisitYamlNode(ysn.Value, node.Value); - else - throw UnsupportedKeyType(node.Key, _currentPath); + if (yamlStream.Documents.Count < 1 || yamlStream.Documents[0].RootNode is not YamlMappingNode mappingNode) return _data; + + foreach (var node in mappingNode.Children) + if (node.Key is YamlScalarNode { Value: { } } ysn) + VisitYamlNode(ysn.Value, node.Value); + else + throw UnsupportedKeyType(node.Key, _currentPath); return _data; } @@ -129,10 +130,6 @@ private void ExitContext() } private static bool IsNullValue(YamlScalarNode yamlValue) => - yamlValue.Style == ScalarStyle.Plain - && (yamlValue.Value == "~" - || yamlValue.Value == null - || yamlValue.Value == "null" - || yamlValue.Value == "Null" - || yamlValue.Value == "NULL"); -} \ No newline at end of file + yamlValue.Style == ScalarStyle.Plain && + yamlValue.Value is "~" or null or "null" or "Null" or "NULL"; +} diff --git a/Apollo.Configuration/Apollo.Configuration.csproj b/Apollo.Configuration/Apollo.Configuration.csproj index d2a0f5b..df231d0 100644 --- a/Apollo.Configuration/Apollo.Configuration.csproj +++ b/Apollo.Configuration/Apollo.Configuration.csproj @@ -10,10 +10,8 @@   直接使用ApolloConfigurationManager请使用Com.Ctrip.Framework.Apollo.Configuration或者Com.Ctrip.Framework.Apollo.ConfigurationManager $(PackageReleaseNotes) - https://raw.githubusercontent.com/apolloconfig/apollo/master/apollo-portal/src/main/resources/static/img/config.png - $(RepositoryUrl)/$(MSBuildProjectName) Com.Ctrip.Framework.Apollo - netstandard2.0 + netstandard2.0;netstandard2.1 $(ApolloVersion).0 @@ -25,7 +23,9 @@ $(PackageReleaseNotes) - + + + diff --git a/Apollo.Configuration/ApolloConfigurationExtensions.cs b/Apollo.Configuration/ApolloConfigurationExtensions.cs index 7f5c362..2e1fa54 100644 --- a/Apollo.Configuration/ApolloConfigurationExtensions.cs +++ b/Apollo.Configuration/ApolloConfigurationExtensions.cs @@ -46,7 +46,7 @@ public static IApolloConfigurationBuilder AddNamespace(this IApolloConfiguration public static IApolloConfigurationBuilder AddNamespace(this IApolloConfigurationBuilder builder, string @namespace, string? sectionKey, ConfigFileFormat format = ConfigFileFormat.Properties) { if (string.IsNullOrWhiteSpace(@namespace)) throw new ArgumentNullException(nameof(@namespace)); - if (format < ConfigFileFormat.Properties || format > ConfigFileFormat.Txt) throw new ArgumentOutOfRangeException(nameof(format), format, $"最小值{ConfigFileFormat.Properties},最大值{ConfigFileFormat.Txt}"); + if (format is < ConfigFileFormat.Properties or > ConfigFileFormat.Txt) throw new ArgumentOutOfRangeException(nameof(format), format, $"最小值{ConfigFileFormat.Properties},最大值{ConfigFileFormat.Txt}"); if (format != ConfigFileFormat.Properties) @namespace += "." + format.GetString(); diff --git a/Apollo.Configuration/ApolloOptions.cs b/Apollo.Configuration/ApolloOptions.cs index 9ccc851..70f5889 100644 --- a/Apollo.Configuration/ApolloOptions.cs +++ b/Apollo.Configuration/ApolloOptions.cs @@ -84,7 +84,22 @@ public virtual string? MetaServer public IDictionary Meta { get; set; } = new Dictionary(StringComparer.OrdinalIgnoreCase); - public Func? HttpMessageHandlerFactory { get; set; } + private HttpMessageHandler _handler = new HttpClientHandler(); + + public HttpMessageHandler HttpMessageHandler + { + get => _handler; + set => Interlocked.Exchange(ref _handler, value).Dispose(); + } + + [Obsolete("请使用HttpMessageHandler", true)] + public Func HttpMessageHandlerFactory + { + get => () => _handler; + set => HttpMessageHandler = value(); + } public ICacheFileProvider CacheFileProvider { get; set; } = new LocalPlaintextCacheFileProvider(); -} \ No newline at end of file + + public void Dispose() => _handler.Dispose(); +} diff --git a/Apollo.Configuration/Logging/MelLogging.cs b/Apollo.Configuration/Logging/MelLogging.cs new file mode 100644 index 0000000..838164f --- /dev/null +++ b/Apollo.Configuration/Logging/MelLogging.cs @@ -0,0 +1,21 @@ +using Microsoft.Extensions.Logging; + +namespace Com.Ctrip.Framework.Apollo.Logging; + +public static class MelLogging +{ + public static void UseMel(ILoggerFactory loggerFactory) => LogManager.LogFactory = logger => + (level, msg, ex) => loggerFactory.CreateLogger(logger).Log(Convert(level), ex, msg); + + private static Microsoft.Extensions.Logging.LogLevel Convert(LogLevel level) => level switch + { + LogLevel.Trace => Microsoft.Extensions.Logging.LogLevel.Trace, + LogLevel.Debug => Microsoft.Extensions.Logging.LogLevel.Debug, + LogLevel.Info => Microsoft.Extensions.Logging.LogLevel.Information, + LogLevel.Warn => Microsoft.Extensions.Logging.LogLevel.Warning, + LogLevel.Error => Microsoft.Extensions.Logging.LogLevel.Error, + LogLevel.Fatal => Microsoft.Extensions.Logging.LogLevel.Critical, + _ => Microsoft.Extensions.Logging.LogLevel.None + }; +} + diff --git a/Apollo.Configuration/README.md b/Apollo.Configuration/README.md index 044209d..4bfe7ff 100644 --- a/Apollo.Configuration/README.md +++ b/Apollo.Configuration/README.md @@ -209,7 +209,7 @@ services.ConfigureJsonValue(/*name, */config.GetSection("somePrefix:Jso + .ConfigureAppConfiguration(builder => + { + var apollo = builder.Build().GetSection("apollo").Get(); -+ apollo.HttpMessageHandlerFactory = () => new HttpClientHandler ++ apollo.HttpMessageHandler = new HttpClientHandler + { + UseProxy = true, + Proxy = new WebProxy(new Uri("http://代理地址")) diff --git a/Apollo.ConfigurationManager.Tests/ConfigurationBuilderTest.cs b/Apollo.ConfigurationManager.Tests/ConfigurationBuilderTest.cs index 439e595..87d16aa 100644 --- a/Apollo.ConfigurationManager.Tests/ConfigurationBuilderTest.cs +++ b/Apollo.ConfigurationManager.Tests/ConfigurationBuilderTest.cs @@ -12,7 +12,7 @@ public void AppSettingsSectionBuilderTest() => [Fact] public void ConnectionStringsSectionBuilderTest() => - Assert.Equal("asdfasdf", System.Configuration.ConfigurationManager.ConnectionStrings["abc"]?.ConnectionString); + Assert.Equal("Test connection string", System.Configuration.ConfigurationManager.ConnectionStrings["abc"]?.ConnectionString); [Fact] public void NodeReplaceSectionBuilderTest() diff --git a/Apollo.ConfigurationManager.Tests/TestConfig.cs b/Apollo.ConfigurationManager.Tests/TestConfig.cs index 4604316..03c0759 100644 --- a/Apollo.ConfigurationManager.Tests/TestConfig.cs +++ b/Apollo.ConfigurationManager.Tests/TestConfig.cs @@ -39,5 +39,5 @@ public bool TryGetProperty(string key, [NotNullWhen(true)] out string? value) => public IEnumerable GetPropertyNames() => _dict.Keys; - public event ConfigChangeEvent ConfigChanged = default!; + public event ConfigChangeEvent? ConfigChanged = default; } diff --git a/Apollo.ConfigurationManager/Apollo.ConfigurationManager.csproj b/Apollo.ConfigurationManager/Apollo.ConfigurationManager.csproj index 45535ee..5346c80 100644 --- a/Apollo.ConfigurationManager/Apollo.ConfigurationManager.csproj +++ b/Apollo.ConfigurationManager/Apollo.ConfigurationManager.csproj @@ -10,11 +10,10 @@   直接使用ApolloConfigurationManager请使用Com.Ctrip.Framework.Apollo.Configuration或者Com.Ctrip.Framework.Apollo.ConfigurationManager $(PackageReleaseNotes) - $(RepositoryUrl)/$(MSBuildProjectName) $(PackageTags) ConfigurationBuilder ConfigurationManager Com.Ctrip.Framework.Apollo net471;net45;net40;netstandard2.0;netstandard2.1 - $(ApolloVersion).3 + $(ApolloVersion).0 diff --git a/Apollo.ConfigurationManager/README.md b/Apollo.ConfigurationManager/README.md index 74b6c43..7f4d9f5 100644 --- a/Apollo.ConfigurationManager/README.md +++ b/Apollo.ConfigurationManager/README.md @@ -260,7 +260,7 @@ apollo.net项目中有多个样例客户端的项目: 在读取任何配置之前执行如下代码 ``` C# -ConfigUtil.UseHttpMessageHandlerFactory(() => new HttpClientHandler +ConfigUtil.UseHttpMessageHandler(new HttpClientHandler { UseProxy = true, Proxy = new WebProxy(new Uri("http://代理地址")) diff --git a/Apollo.ConfigurationManager/Util/ConfigUtil.cs b/Apollo.ConfigurationManager/Util/ConfigUtil.cs index bf8c54a..3daa3c4 100644 --- a/Apollo.ConfigurationManager/Util/ConfigUtil.cs +++ b/Apollo.ConfigurationManager/Util/ConfigUtil.cs @@ -10,7 +10,7 @@ namespace Com.Ctrip.Framework.Apollo.Util; public class ConfigUtil : IApolloOptions { public static NameValueCollection? AppSettings { get; set; } - private static Func? _httpMessageHandlerFactory; + private static HttpMessageHandler _handler = new HttpClientHandler(); private static ICacheFileProvider? _cacheFileProvider; private static readonly Func> Logger = () => LogManager.CreateLogger(typeof(ConfigUtil)); @@ -161,13 +161,20 @@ private void InitRefreshInterval() public string LocalCacheDir => GetAppConfig(nameof(LocalCacheDir)) ?? Path.Combine(ConfigConsts.DefaultLocalCacheDir, AppId); - public Func? HttpMessageHandlerFactory => _httpMessageHandlerFactory; - public bool EnablePlaceholder => bool.TryParse(GetAppConfig(nameof(EnablePlaceholder)), out var enablePlaceholder) && enablePlaceholder; public ICacheFileProvider CacheFileProvider => _cacheFileProvider ??= new LocalPlaintextCacheFileProvider(); - public static void UseHttpMessageHandlerFactory(Func factory) => Interlocked.CompareExchange(ref _httpMessageHandlerFactory, factory, null); + public HttpMessageHandler HttpMessageHandler => _handler; + + public static void UseHttpMessageHandler(HttpMessageHandler handler) => + Interlocked.Exchange(ref _handler, handler).Dispose(); + + [Obsolete("请使用UseHttpMessageHandler", true)] + public static void UseHttpMessageHandlerFactory(Func factory) => + UseHttpMessageHandler(factory()); public static void UseCacheFileProvider(ICacheFileProvider cacheFileProvider) => Interlocked.CompareExchange(ref _cacheFileProvider, cacheFileProvider, null); + + public void Dispose() { } } diff --git a/Apollo.ExtensionsHosting/Apollo.ExtensionsHosting.csproj b/Apollo.ExtensionsHosting/Apollo.ExtensionsHosting.csproj index edc64e1..4a51e72 100644 --- a/Apollo.ExtensionsHosting/Apollo.ExtensionsHosting.csproj +++ b/Apollo.ExtensionsHosting/Apollo.ExtensionsHosting.csproj @@ -10,16 +10,15 @@   直接使用ApolloConfigurationManager请使用Com.Ctrip.Framework.Apollo.Configuration或者Com.Ctrip.Framework.Apollo.ConfigurationManager $(PackageReleaseNotes) - https://raw.githubusercontent.com/apolloconfig/apollo/master/apollo-portal/src/main/resources/static/img/config.png - $(RepositoryUrl)/$(MSBuildProjectName) Microsoft.Extensions.Hosting - netstandard2.0 + netstandard2.0;netstandard2.1 $(ApolloVersion).0 - + + diff --git a/Apollo.OpenApi.DependencyInjection/Apollo.OpenApi.DependencyInjection.csproj b/Apollo.OpenApi.DependencyInjection/Apollo.OpenApi.DependencyInjection.csproj index 88d373a..1e1251e 100644 --- a/Apollo.OpenApi.DependencyInjection/Apollo.OpenApi.DependencyInjection.csproj +++ b/Apollo.OpenApi.DependencyInjection/Apollo.OpenApi.DependencyInjection.csproj @@ -4,8 +4,6 @@ Com.Ctrip.Framework.Apollo.OpenApi.DependencyInjection 携程Apollo的OpenApi客户端,入口接口IOpenApiFactory - https://raw.githubusercontent.com/apolloconfig/apollo/master/apollo-portal/src/main/resources/static/img/config.png - $(RepositoryUrl)/$(MSBuildProjectName) netstandard2.0 2.1.0 Com.Ctrip.Framework.Apollo.OpenApi diff --git a/Apollo.OpenApi.Tests/Apollo.OpenApi.Tests.csproj b/Apollo.OpenApi.Tests/Apollo.OpenApi.Tests.csproj index a735638..6d34aab 100644 --- a/Apollo.OpenApi.Tests/Apollo.OpenApi.Tests.csproj +++ b/Apollo.OpenApi.Tests/Apollo.OpenApi.Tests.csproj @@ -14,8 +14,6 @@ - - diff --git a/Apollo.OpenApi/Apollo.OpenApi.csproj b/Apollo.OpenApi/Apollo.OpenApi.csproj index ae21120..da4e587 100644 --- a/Apollo.OpenApi/Apollo.OpenApi.csproj +++ b/Apollo.OpenApi/Apollo.OpenApi.csproj @@ -4,15 +4,13 @@ Com.Ctrip.Framework.Apollo.OpenApi 携程Apollo的OpenApi客户端,入口接口IOpenApiFactory - https://raw.githubusercontent.com/apolloconfig/apollo/master/apollo-portal/src/main/resources/static/img/config.png - $(RepositoryUrl)/$(MSBuildProjectName) net40;net45;netstandard2.0 2.1.0 Com.Ctrip.Framework.Apollo.OpenApi - + diff --git a/Apollo.Tests/ConfigExtensionsTest.cs b/Apollo.Tests/ConfigExtensionsTest.cs index fb1f322..5d442fe 100644 --- a/Apollo.Tests/ConfigExtensionsTest.cs +++ b/Apollo.Tests/ConfigExtensionsTest.cs @@ -22,7 +22,7 @@ private class FakeConfig : IConfig { private readonly IReadOnlyDictionary _data; - public event ConfigChangeEvent ConfigChanged = default!; + public event ConfigChangeEvent? ConfigChanged = default; public FakeConfig(IReadOnlyDictionary data) => _data = data; @@ -30,4 +30,4 @@ private class FakeConfig : IConfig public bool TryGetProperty(string key, [NotNullWhen(true)] out string? value) => _data.TryGetValue(key, out value); } -} \ No newline at end of file +} diff --git a/Apollo.Tests/ConfigServiceLocatorTest.cs b/Apollo.Tests/ConfigServiceLocatorTest.cs index 9f3aaf3..c558611 100644 --- a/Apollo.Tests/ConfigServiceLocatorTest.cs +++ b/Apollo.Tests/ConfigServiceLocatorTest.cs @@ -16,6 +16,7 @@ public async Task MetaServerTest() moq.SetupGet(o => o.MetaServer).Returns("http://106.54.227.205:8080/"); moq.SetupGet(o => o.ConfigServer).Returns(Array.Empty()); moq.SetupGet(o => o.Timeout).Returns(5000); + moq.SetupGet(o => o.HttpMessageHandler).Returns(new HttpClientHandler()); var options = moq.Object; @@ -42,4 +43,4 @@ public async Task ConfigServerTest() Assert.Equal(1, services.Count); Assert.Equal(options.ConfigServer.FirstOrDefault(), services[0].HomepageUrl); } -} \ No newline at end of file +} diff --git a/Apollo.sln b/Apollo.sln index 24ab2bd..34245be 100644 --- a/Apollo.sln +++ b/Apollo.sln @@ -18,6 +18,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .travis.yml = .travis.yml azure-pipelines.yml = azure-pipelines.yml Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets PackAllProject.ps1 = PackAllProject.ps1 README.md = README.md EndProjectSection diff --git a/Apollo/Apollo.csproj b/Apollo/Apollo.csproj index 4f6d44e..c5368d7 100644 --- a/Apollo/Apollo.csproj +++ b/Apollo/Apollo.csproj @@ -10,8 +10,6 @@   直接使用ApolloConfigurationManager请使用Com.Ctrip.Framework.Apollo.Configuration或者Com.Ctrip.Framework.Apollo.ConfigurationManager $(PackageReleaseNotes) - https://raw.githubusercontent.com/apolloconfig/apollo/master/apollo-portal/src/main/resources/static/img/config.png - $(RepositoryUrl)/$(MSBuildProjectName) Com.Ctrip.Framework.Apollo net40;net45;netstandard2.0;netstandard2.1 $(ApolloVersion).0 diff --git a/Apollo/ConfigAdapter/JsonConfigurationParser.cs b/Apollo/ConfigAdapter/JsonConfigurationParser.cs index a3b0236..a83becd 100644 --- a/Apollo/ConfigAdapter/JsonConfigurationParser.cs +++ b/Apollo/ConfigAdapter/JsonConfigurationParser.cs @@ -8,7 +8,7 @@ internal class JsonConfigurationParser { private JsonConfigurationParser() { } - private readonly IDictionary _data = new SortedDictionary(StringComparer.OrdinalIgnoreCase); + private readonly IDictionary _data = new Dictionary(StringComparer.OrdinalIgnoreCase); private readonly Stack _context = new(); private string _currentPath = string.Empty; @@ -105,4 +105,4 @@ private void ExitContext() _context.Pop(); _currentPath = ConfigurationPath.Combine(_context.Reverse()); } -} \ No newline at end of file +} diff --git a/Apollo/IApolloOptions.cs b/Apollo/IApolloOptions.cs index 01901f2..3b7efc3 100644 --- a/Apollo/IApolloOptions.cs +++ b/Apollo/IApolloOptions.cs @@ -3,7 +3,7 @@ namespace Com.Ctrip.Framework.Apollo; -public interface IApolloOptions +public interface IApolloOptions : IDisposable { string AppId { get; } /// @@ -42,7 +42,7 @@ public interface IApolloOptions string? LocalCacheDir { get; } - Func? HttpMessageHandlerFactory { get; } + HttpMessageHandler HttpMessageHandler { get; } ICacheFileProvider CacheFileProvider { get; } } diff --git a/Apollo/IConfig.cs b/Apollo/IConfig.cs index 68c2640..23a53ce 100644 --- a/Apollo/IConfig.cs +++ b/Apollo/IConfig.cs @@ -26,5 +26,5 @@ public interface IConfig /// /// Config change event subscriber /// - event ConfigChangeEvent ConfigChanged; -} \ No newline at end of file + event ConfigChangeEvent? ConfigChanged; +} diff --git a/Apollo/Internals/AbstractConfig.cs b/Apollo/Internals/AbstractConfig.cs index a35aef4..bbd53b6 100644 --- a/Apollo/Internals/AbstractConfig.cs +++ b/Apollo/Internals/AbstractConfig.cs @@ -8,7 +8,7 @@ namespace Com.Ctrip.Framework.Apollo.Internals; public abstract class AbstractConfig : IConfig { private static readonly Func> Logger = () => LogManager.CreateLogger(typeof(AbstractConfig)); - public event ConfigChangeEvent ConfigChanged = default!; + public event ConfigChangeEvent? ConfigChanged; private static readonly TaskFactory ExecutorService; static AbstractConfig() => ExecutorService = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(5)); @@ -22,37 +22,30 @@ protected void FireConfigChange(IDictionary actualChanges) protected void FireConfigChange(IReadOnlyDictionary actualChanges) #endif { - if (ConfigChanged != null) + if (ConfigChanged is not { } configChanged) return; + + foreach (var @delegate in configChanged.GetInvocationList()) { - foreach (var @delegate in ConfigChanged.GetInvocationList()) + var handlerCopy = (ConfigChangeEvent)@delegate; + ExecutorService.StartNew(() => { - var handlerCopy = (ConfigChangeEvent)@delegate; - ExecutorService.StartNew(() => + try { - try - { - handlerCopy(this, new ConfigChangeEventArgs(this, actualChanges)); - } - catch (Exception ex) - { - Logger().Error($"Failed to invoke config change handler {(handlerCopy.Target == null ? handlerCopy.Method.Name : $"{handlerCopy.Target.GetType()}.{handlerCopy.Method.Name}")}", ex); - } - }); - } + handlerCopy(this, new ConfigChangeEventArgs(this, actualChanges)); + } + catch (Exception ex) + { + Logger().Error($"Failed to invoke config change handler {(handlerCopy.Target == null ? handlerCopy.Method.Name : $"{handlerCopy.Target.GetType()}.{handlerCopy.Method.Name}")}", ex); + } + }); } } - protected ICollection CalcPropertyChanges(Properties previous, Properties current) + protected ICollection CalcPropertyChanges(Properties? previous, Properties? current) { - if (previous == null) - { - previous = new Properties(); - } + previous ??= new Properties(); - if (current == null) - { - current = new Properties(); - } + current ??= new Properties(); var previousKeys = previous.GetPropertyNames(); var currentKeys = current.GetPropertyNames(); diff --git a/Apollo/Internals/LocalFileConfigRepository.cs b/Apollo/Internals/LocalFileConfigRepository.cs index 96b9c3e..26fa3f2 100644 --- a/Apollo/Internals/LocalFileConfigRepository.cs +++ b/Apollo/Internals/LocalFileConfigRepository.cs @@ -28,7 +28,7 @@ public LocalFileConfigRepository(string @namespace, _options = configUtil; var ext = Path.GetExtension(@namespace); - if (ext != null && ext.Length > 1 && Enum.TryParse(ext.Substring(1), true, out ConfigFileFormat format)) Format = format; + if (ext is { Length: > 1 } && Enum.TryParse(ext.Substring(1), true, out ConfigFileFormat format)) Format = format; PrepareConfigCacheDir(); } @@ -207,4 +207,4 @@ private string AssembleLocalCacheFile(string baseDir, string namespaceName) return Path.Combine(baseDir, fileName); } -} \ No newline at end of file +} diff --git a/Apollo/Util/Http/HttpUtil.cs b/Apollo/Util/Http/HttpUtil.cs index 0fdd9ab..d02719e 100644 --- a/Apollo/Util/Http/HttpUtil.cs +++ b/Apollo/Util/Http/HttpUtil.cs @@ -4,15 +4,9 @@ namespace Com.Ctrip.Framework.Apollo.Util.Http; public class HttpUtil : IDisposable { - private readonly HttpMessageHandler _httpMessageHandler; private readonly IApolloOptions _options; - public HttpUtil(IApolloOptions options) - { - _options = options; - - _httpMessageHandler = _options.HttpMessageHandlerFactory == null ? new HttpClientHandler() : _options.HttpMessageHandlerFactory(); - } + public HttpUtil(IApolloOptions options) => _options = options; public Task> DoGetAsync(Uri url) => DoGetAsync(url, _options.Timeout); @@ -27,7 +21,10 @@ public async Task> DoGetAsync(Uri url, int timeout) #else using var cts = new CancellationTokenSource(timeout); #endif - var httpClient = new HttpClient(_httpMessageHandler, false) { Timeout = TimeSpan.FromMilliseconds(timeout > 0 ? timeout : _options.Timeout) }; + var httpClient = new HttpClient(_options.HttpMessageHandler, false) + { + Timeout = TimeSpan.FromMilliseconds(timeout > 0 ? timeout : _options.Timeout) + }; if (!string.IsNullOrWhiteSpace(_options.Secret)) foreach (var header in Signature.BuildHttpHeaders(url, _options.AppId, _options.Secret!)) @@ -56,7 +53,7 @@ public async Task> DoGetAsync(Uri url, int timeout) throw e; } - public void Dispose() => _httpMessageHandler.Dispose(); + public void Dispose() => _options.Dispose(); private static async Task Timeout(Task task, int millisecondsDelay, CancellationTokenSource cts) { diff --git a/Directory.Build.props b/Directory.Build.props index b66811d..99c05f7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@  - 2.5 + 2.6 ..\Apollo.snk 2.0.0 True @@ -13,7 +13,8 @@ enable True $(NoWarn);CS0414;CS0436;CS1591 - apollo configcenter configuration ctrip + icon.png + apollo configcenter configuration ctripicon.png git https://github.com/apolloconfig/apollo.net/tree/main true @@ -29,9 +30,11 @@ + + - + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000..2dfea17 --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,7 @@ + + + + $(RepositoryUrl)/$(MSBuildProjectName) + + + diff --git a/PackAllProject.ps1 b/PackAllProject.ps1 index a4ff985..0c864e1 100644 --- a/PackAllProject.ps1 +++ b/PackAllProject.ps1 @@ -1,4 +1,13 @@ function FindMSBuild () { + if ($null -eq $env:OS) { + try { + return (Get-Command msbuild).Source; + } + catch { + return $null; + } + } + foreach ($program in ("C:\Program Files", "C:\Program Files (x86)")) { foreach ($vs in (Get-ChildItem ($program + "\Microsoft Visual Studio"))) { foreach ($vsv in (Get-ChildItem $vs.FullName)) { @@ -16,16 +25,32 @@ if (-not(Test-Path .packages)) { mkdir .packages } +foreach ($csproj in (Get-ChildItem -r -filter *.csproj)) { + $dir = "$([System.IO.Path]::GetDirectoryName($csproj.FullName))\bin\Release"; + if (Test-Path $dir) { + Remove-Item -Recurse -Force $dir; + } +} + $MSBuild = FindMSBuild -& "$MSBuild" /r /m /v:m /p:Configuration=Release +if ($null -eq $MSBuild) { + dotnet build -c Release +} +else { + & "$MSBuild" /r /m /v:m /p:Configuration=Release +} foreach ($csproj in (Get-ChildItem -r -filter *.csproj)) { - $nupkg = Get-ChildItem "$([System.IO.Path]::GetDirectoryName($csproj.FullName))\bin\Release" | - Where-Object { $_.Name.Endswith(".symbols.nupkg") } | - Sort-Object -Property LastWriteTime -Descending | - Select-Object -First 1; + $dir = "$([System.IO.Path]::GetDirectoryName($csproj.FullName))\bin\Release"; + if (Test-Path $dir) { + + $nupkg = Get-ChildItem "$([System.IO.Path]::GetDirectoryName($csproj.FullName))\bin\Release" | + Where-Object { $_.Name.Endswith(".symbols.nupkg") } | + Sort-Object -Property LastWriteTime -Descending | + Select-Object -First 1; - if ($null -ne $nupkg) { - Copy-Item $nupkg.VersionInfo.FIleName (".packages\" + $nupkg.Name) -Force + if ($null -ne $nupkg) { + Copy-Item $nupkg.VersionInfo.FIleName (".packages\" + $nupkg.Name) -Force + } } } diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..bf428f6 Binary files /dev/null and b/icon.png differ