1
1
/*
2
- * Copyright (c) 2000, 2020 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2000, 2024 , Oracle and/or its affiliates.
3
3
*
4
4
* Licensed under the Universal Permissive License v 1.0 as shown at
5
- * http ://oss.oracle.com/licenses/upl.
5
+ * https ://oss.oracle.com/licenses/upl.
6
6
*/
7
7
using System ;
8
- using System . Configuration ;
9
-
8
+ using System . Collections ;
9
+ using System . IO ;
10
+ using Microsoft . Extensions . Configuration ;
10
11
using Tangosol . Config ;
12
+ using Tangosol . IO . Resources ;
11
13
12
14
namespace Tangosol . Util
13
15
{
@@ -21,26 +23,54 @@ public class ConfigurationUtils
21
23
/// The name of the configuration element that contains Coherence
22
24
/// configuration settings.
23
25
/// </summary>
24
- private const string CONFIG_SECTION_NAME = "coherence" ;
25
-
26
- // TODO: remove this constant in a future release
27
- private const string _CONFIG_SECTION_NAME = "tangosol-coherence" ;
26
+ private const string CONFIG_SECTION_NAME = "Coherence" ;
28
27
29
28
/// <summary>
30
29
/// Parses the Coherence configuration section within the standard
31
- /// .NET configuration file (App.config or Web.config ).
30
+ /// .NET configuration file (appsettings.json ).
32
31
/// </summary>
33
32
/// <returns>
34
- /// An instance of <see cref="CoherenceConfig"/> created by
35
- /// <see cref="CoherenceConfigHandler"/>.
33
+ /// An instance of <see cref="CoherenceConfig"/>
36
34
/// </returns>
37
35
public static object GetCoherenceConfiguration ( )
38
36
{
39
- // TODO: we still check for the legacy "tangosol-coherence" config
40
- // section for backwards compatibility; this check should be
41
- // removed in a future release
42
- return ConfigurationManager . GetSection ( CONFIG_SECTION_NAME )
43
- ?? ConfigurationManager . GetSection ( _CONFIG_SECTION_NAME ) ;
37
+ IConfiguration cohCfg = new ConfigurationBuilder ( )
38
+ . SetBasePath ( Directory . GetCurrentDirectory ( ) )
39
+ . AddJsonFile ( "appsettings.json" , true )
40
+ . Build ( )
41
+ . GetSection ( CONFIG_SECTION_NAME ) ;
42
+
43
+ CoherenceConfig config = new CoherenceConfig ( ) ;
44
+ string coherenceConfig = cohCfg [ "CoherenceConfig" ] ;
45
+ string cacheConfig = cohCfg [ "CacheConfig" ] ;
46
+ string pofConfig = cohCfg [ "PofConfig" ] ;
47
+ string messagingDebug = cohCfg [ "COHERENCE_MESSAGING_DEBUG" ] ;
48
+
49
+ config . ConfigProperties = new Hashtable ( ) ;
50
+ if ( coherenceConfig != null )
51
+ {
52
+ config . OperationalConfig = ResourceLoader . GetResource ( coherenceConfig ) ;
53
+ }
54
+ if ( cacheConfig != null )
55
+ {
56
+ config . CacheConfig = ResourceLoader . GetResource ( cacheConfig ) ;
57
+ }
58
+ if ( pofConfig != null )
59
+ {
60
+ config . PofConfig = ResourceLoader . GetResource ( pofConfig ) ;
61
+ }
62
+ if ( messagingDebug != null )
63
+ {
64
+ config . ConfigProperties . Add ( "COHERENCE_MESSAGING_DEBUG" , messagingDebug ) ;
65
+ }
66
+
67
+ IConfigurationSection properties = cohCfg . GetSection ( "Properties" ) ;
68
+ foreach ( var property in properties . GetChildren ( ) )
69
+ {
70
+ config . ConfigProperties . Add ( property . Key , property . Value ) ;
71
+ }
72
+
73
+ return config ;
44
74
}
45
75
46
76
/// <summary>
0 commit comments