@@ -69,7 +69,11 @@ public Settings(object settings, Func<string, string> presetResolver)
69
69
}
70
70
else
71
71
{
72
- throw new ArgumentException ( String . Format ( "File does not exist: {0}" , settingsFilePath ) ) ;
72
+ throw new ArgumentException (
73
+ String . Format (
74
+ CultureInfo . CurrentCulture ,
75
+ Strings . InvalidPath ,
76
+ settingsFilePath ) ) ;
73
77
}
74
78
}
75
79
else
@@ -81,7 +85,7 @@ public Settings(object settings, Func<string, string> presetResolver)
81
85
}
82
86
else
83
87
{
84
- throw new ArgumentException ( "Input object should either be a string or a hashtable" ) ;
88
+ throw new ArgumentException ( Strings . SettingsInvalidType ) ;
85
89
}
86
90
}
87
91
}
@@ -168,29 +172,24 @@ private Dictionary<string, object> GetDictionaryFromHashtable(Hashtable hashtabl
168
172
string key = obj as string ;
169
173
if ( key == null )
170
174
{
171
- // TODO localize
172
- throw new InvalidDataException ( "key not string" ) ;
173
- // writer.WriteError(
174
- // new ErrorRecord(
175
- // new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.KeyNotString, key)),
176
- // Strings.ConfigurationKeyNotAString,
177
- // ErrorCategory.InvalidData,
178
- // hashtable));
179
- // hasError = true;
175
+ throw new InvalidDataException (
176
+ string . Format (
177
+ CultureInfo . CurrentCulture ,
178
+ Strings . KeyNotString ,
179
+ key ) ) ;
180
180
}
181
+
181
182
var valueHashtableObj = hashtable [ obj ] ;
182
183
if ( valueHashtableObj == null )
183
184
{
184
- throw new InvalidDataException ( "wrong hash table value" ) ;
185
- // writer.WriteError(
186
- // new ErrorRecord(
187
- // new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongValueHashTable, valueHashtableObj, key)),
188
- // Strings.WrongConfigurationKey,
189
- // ErrorCategory.InvalidData,
190
- // hashtable));
191
- // hasError = true;
192
- // return null;
185
+ throw new InvalidDataException (
186
+ string . Format (
187
+ CultureInfo . CurrentCulture ,
188
+ Strings . WrongValueHashTable ,
189
+ "" ,
190
+ key ) ) ;
193
191
}
192
+
194
193
var valueHashtable = valueHashtableObj as Hashtable ;
195
194
if ( valueHashtable == null )
196
195
{
@@ -221,17 +220,11 @@ private List<string> GetData(object val, string key)
221
220
if ( val == null )
222
221
{
223
222
throw new InvalidDataException (
224
- String . Format (
225
- "value should be a string or string array for {0} key" ,
223
+ string . Format (
224
+ CultureInfo . CurrentCulture ,
225
+ Strings . WrongValueHashTable ,
226
+ "" ,
226
227
key ) ) ;
227
- // writer.WriteError(
228
- // new ErrorRecord(
229
- // new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongValueHashTable, value, key)),
230
- // Strings.WrongConfigurationKey,
231
- // ErrorCategory.InvalidData,
232
- // profile));
233
- // hasError = true;
234
- // break;
235
228
}
236
229
237
230
List < string > values = new List < string > ( ) ;
@@ -260,21 +253,23 @@ private List<string> GetData(object val, string key)
260
253
}
261
254
else
262
255
{
263
- throw new InvalidDataException ( "array items should be of string type" ) ;
264
- // writer.WriteError(
265
- // new ErrorRecord(
266
- // new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongValueHashTable, val, key)),
267
- // Strings.WrongConfigurationKey,
268
- // ErrorCategory.InvalidData,
269
- // profile));
270
- // hasError = true;
271
- // break;
256
+ throw new InvalidDataException (
257
+ string . Format (
258
+ CultureInfo . CurrentCulture ,
259
+ Strings . WrongValueHashTable ,
260
+ val ,
261
+ key ) ) ;
272
262
}
273
263
}
274
264
}
275
265
else
276
266
{
277
- throw new InvalidDataException ( "array items should be of string type" ) ;
267
+ throw new InvalidDataException (
268
+ string . Format (
269
+ CultureInfo . CurrentCulture ,
270
+ Strings . WrongValueHashTable ,
271
+ val ,
272
+ key ) ) ;
278
273
}
279
274
}
280
275
@@ -285,21 +280,17 @@ private List<string> GetData(object val, string key)
285
280
/// Sets the arguments for consumption by rules
286
281
/// </summary>
287
282
/// <param name="ruleArgs">A hashtable with rule names as keys</param>
288
- private Dictionary < string , Dictionary < string , object > > ConvertToRuleArgumentType ( object ruleArguments )
283
+ private Dictionary < string , Dictionary < string , object > > ConvertToRuleArgumentType ( object ruleArguments )
289
284
{
290
285
var ruleArgs = ruleArguments as Dictionary < string , object > ;
291
286
if ( ruleArgs == null )
292
287
{
293
- throw new ArgumentException (
294
- "input should be a dictionary" ,
295
- "ruleArguments" ) ;
288
+ throw new ArgumentException ( Strings . SettingsInputShouldBeDictionary , nameof ( ruleArguments ) ) ;
296
289
}
297
290
298
291
if ( ruleArgs . Comparer != StringComparer . OrdinalIgnoreCase )
299
292
{
300
- throw new ArgumentException (
301
- "Input dictionary should have OrdinalIgnoreCase comparer." ,
302
- "ruleArguments" ) ;
293
+ throw new ArgumentException ( Strings . SettingsDictionaryShouldBeCaseInsesitive , nameof ( ruleArguments ) ) ;
303
294
}
304
295
305
296
var ruleArgsDict = new Dictionary < string , Dictionary < string , object > > ( StringComparer . OrdinalIgnoreCase ) ;
@@ -308,9 +299,7 @@ private Dictionary<string, Dictionary<string, object>> ConvertToRuleArgumentTyp
308
299
var argsDict = ruleArgs [ rule ] as Dictionary < string , object > ;
309
300
if ( argsDict == null )
310
301
{
311
- throw new ArgumentException (
312
- "input should be a dictionary" ,
313
- "ruleArguments" ) ;
302
+ throw new InvalidDataException ( Strings . SettingsInputShouldBeDictionary ) ;
314
303
}
315
304
ruleArgsDict [ rule ] = argsDict ;
316
305
}
@@ -341,19 +330,25 @@ private void parseSettingsHashtable(Hashtable settingsHashtable)
341
330
break ;
342
331
343
332
case "rules" :
344
- ruleArguments = ConvertToRuleArgumentType ( val ) ;
333
+ try
334
+ {
335
+ ruleArguments = ConvertToRuleArgumentType ( val ) ;
336
+ }
337
+ catch ( ArgumentException argumentException )
338
+ {
339
+ throw new InvalidDataException (
340
+ string . Format ( CultureInfo . CurrentCulture , Strings . WrongValueHashTable , "" , key ) ,
341
+ argumentException ) ;
342
+ }
343
+
345
344
break ;
346
345
347
346
default :
348
- throw new InvalidDataException ( String . Format ( "Invalid key: {0}" , key ) ) ;
349
- // writer.WriteError(
350
- // new ErrorRecord(
351
- // new InvalidDataException(string.Format(CultureInfo.CurrentCulture, Strings.WrongKeyHashTable, key)),
352
- // Strings.WrongConfigurationKey,
353
- // ErrorCategory.InvalidData,
354
- // profile));
355
- // hasError = true;
356
- // break;
347
+ throw new InvalidDataException (
348
+ string . Format (
349
+ CultureInfo . CurrentCulture ,
350
+ Strings . WrongKeyHashTable ,
351
+ key ) ) ;
357
352
}
358
353
}
359
354
}
@@ -368,10 +363,7 @@ private void parseSettingsFile(string settingsFilePath)
368
363
// no hashtable, raise warning
369
364
if ( hashTableAsts . Count ( ) == 0 )
370
365
{
371
- throw new ArgumentException ( "Given file does not contain a hashtable" ) ;
372
- // writer.WriteError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.InvalidProfile, profile)),
373
- // Strings.ConfigurationFileHasNoHashTable, ErrorCategory.ResourceUnavailable, profile));
374
- // hasError = true;
366
+ throw new ArgumentException ( string . Format ( CultureInfo . CurrentCulture , Strings . InvalidProfile , settingsFilePath ) ) ;
375
367
}
376
368
377
369
HashtableAst hashTableAst = hashTableAsts . First ( ) as HashtableAst ;
@@ -384,12 +376,16 @@ private void parseSettingsFile(string settingsFilePath)
384
376
}
385
377
catch ( InvalidOperationException e )
386
378
{
387
- throw new ArgumentException ( "input file has invalid hashtable" , e ) ;
379
+ throw new ArgumentException ( Strings . InvalidProfile , e ) ;
388
380
}
389
381
390
382
if ( hashtable == null )
391
383
{
392
- throw new ArgumentException ( "input file has invalid hashtable" ) ;
384
+ throw new ArgumentException (
385
+ String . Format (
386
+ CultureInfo . CurrentCulture ,
387
+ Strings . InvalidProfile ,
388
+ settingsFilePath ) ) ;
393
389
}
394
390
395
391
parseSettingsHashtable ( hashtable ) ;
0 commit comments