9
9
using System . Configuration ;
10
10
using System . Diagnostics ;
11
11
using System . IO ;
12
+ using System . Linq ;
12
13
using System . Reflection ;
13
14
14
15
namespace Hocon
@@ -57,6 +58,7 @@ public static Config ParseString(string hocon)
57
58
/// The configuration defined in the configuration file. If the section
58
59
/// "akka" is not found, this returns an empty Config.
59
60
/// </returns>
61
+ [ Obsolete ( "Call the ConfigurationFactory.Default method instead." ) ]
60
62
public static Config Load ( )
61
63
{
62
64
return Load ( "akka" ) ;
@@ -78,14 +80,51 @@ public static Config Load(string sectionName)
78
80
79
81
return config ;
80
82
}
83
+
84
+ /// <summary>
85
+ /// Parses a HOCON file from the filesystem.
86
+ /// </summary>
87
+ /// <param name="filePath">The path to the file.</param>
88
+ /// <returns>A parsed HOCON configuration object.</returns>
89
+ /// <throws>ConfigurationException, when the supplied filePath can't be found.</throws>
90
+ public static Config FromFile ( string filePath )
91
+ {
92
+ if ( File . Exists ( filePath ) )
93
+ {
94
+ return ParseString ( File . ReadAllText ( filePath ) ) ;
95
+ }
96
+
97
+ throw new ConfigurationException ( $ "No HOCON file at { filePath } could be found.") ;
98
+ }
99
+
100
+ public static readonly string [ ] DefaultHoconFilePaths = { "app.conf" , "app.hocon" } ;
101
+
81
102
/// <summary>
82
103
/// Retrieves the default configuration that Akka.NET uses
83
104
/// when no configuration has been defined.
84
105
/// </summary>
85
106
/// <returns>The configuration that contains default values for all options.</returns>
86
107
public static Config Default ( )
87
108
{
88
- return FromResource ( "Default.conf" ) ;
109
+ // attempt to load .hocon files first
110
+ foreach ( var path in DefaultHoconFilePaths . Where ( x => File . Exists ( x ) ) )
111
+ {
112
+ return FromFile ( path ) ;
113
+ }
114
+
115
+ // if we made it this far: no default HOCON files found. Check app.config
116
+ try
117
+ {
118
+ return Load ( "hocon" ) ; // new default
119
+ return Load ( "akka" ) ; // old Akka.NET-specific default
120
+
121
+ }
122
+ catch
123
+ {
124
+
125
+ }
126
+
127
+ return Empty ;
89
128
}
90
129
91
130
/// <summary>
0 commit comments