3
3
using global ::Microsoft . Extensions . Configuration ;
4
4
using global ::Microsoft . Extensions . Logging ;
5
5
using Nacos . V2 ;
6
+ using Nacos . V2 . Utils ;
6
7
using System ;
7
8
using System . Collections . Concurrent ;
8
9
using System . Collections . Generic ;
@@ -14,6 +15,7 @@ internal class NacosV2ConfigurationProvider : ConfigurationProvider, IDisposable
14
15
private readonly NacosV2ConfigurationSource _configurationSource ;
15
16
16
17
private readonly INacosConfigurationParser _parser ;
18
+ private readonly IReadOnlyDictionary < string , INacosConfigurationParser > _parsers ;
17
19
18
20
private readonly INacosConfigService _client ;
19
21
@@ -27,6 +29,7 @@ public NacosV2ConfigurationProvider(NacosV2ConfigurationSource configurationSour
27
29
{
28
30
_configurationSource = configurationSource ;
29
31
_parser = configurationSource . NacosConfigurationParser ;
32
+ _parsers = configurationSource . NacosConfigurationParsers ;
30
33
_configDict = new ConcurrentDictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
31
34
_listenerDict = new Dictionary < string , MsConfigListener > ( ) ;
32
35
@@ -55,6 +58,18 @@ public NacosV2ConfigurationProvider(NacosV2ConfigurationSource configurationSour
55
58
}
56
59
}
57
60
61
+ private INacosConfigurationParser GetParser ( string format )
62
+ {
63
+ if ( format . IsNullOrWhiteSpace ( ) ) return _parser ;
64
+
65
+ if ( _parsers . TryGetValue ( format , out var parser ) )
66
+ {
67
+ return parser ;
68
+ }
69
+
70
+ throw new InvalidOperationException ( "Missing parser for format: " + format ) ;
71
+ }
72
+
58
73
internal IDictionary < string , string > GetData ( ) => Data ;
59
74
60
75
public void Dispose ( )
@@ -92,7 +107,7 @@ public override void Load()
92
107
93
108
_configDict . AddOrUpdate ( $ "{ _configurationSource . GetNamespace ( ) } #{ listener . Group } #{ listener . DataId } ", config , ( x , y ) => config ) ;
94
109
95
- var data = _parser . Parse ( config ) ;
110
+ var data = GetParser ( listener . Format ) . Parse ( config ) ;
96
111
97
112
foreach ( var item in data )
98
113
{
@@ -167,7 +182,7 @@ public void ReceiveConfigInfo(string configInfo)
167
182
continue ;
168
183
}
169
184
170
- var data = _provider . _parser . Parse ( config ) ;
185
+ var data = _provider . GetParser ( listener . Format ) . Parse ( config ) ;
171
186
172
187
foreach ( var item in data )
173
188
{
0 commit comments