@@ -69,7 +69,11 @@ public Settings(object settings, Func<string, string> presetResolver)
6969 }
7070 else
7171 {
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 ) ) ;
7377 }
7478 }
7579 else
@@ -81,7 +85,7 @@ public Settings(object settings, Func<string, string> presetResolver)
8185 }
8286 else
8387 {
84- throw new ArgumentException ( "Input object should either be a string or a hashtable" ) ;
88+ throw new ArgumentException ( Strings . SettingsInvalidType ) ;
8589 }
8690 }
8791 }
@@ -168,29 +172,24 @@ private Dictionary<string, object> GetDictionaryFromHashtable(Hashtable hashtabl
168172 string key = obj as string ;
169173 if ( key == null )
170174 {
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 ) ) ;
180180 }
181+
181182 var valueHashtableObj = hashtable [ obj ] ;
182183 if ( valueHashtableObj == null )
183184 {
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 ) ) ;
193191 }
192+
194193 var valueHashtable = valueHashtableObj as Hashtable ;
195194 if ( valueHashtable == null )
196195 {
@@ -221,17 +220,11 @@ private List<string> GetData(object val, string key)
221220 if ( val == null )
222221 {
223222 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+ "" ,
226227 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;
235228 }
236229
237230 List < string > values = new List < string > ( ) ;
@@ -260,21 +253,23 @@ private List<string> GetData(object val, string key)
260253 }
261254 else
262255 {
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 ) ) ;
272262 }
273263 }
274264 }
275265 else
276266 {
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 ) ) ;
278273 }
279274 }
280275
@@ -285,21 +280,17 @@ private List<string> GetData(object val, string key)
285280 /// Sets the arguments for consumption by rules
286281 /// </summary>
287282 /// <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 )
289284 {
290285 var ruleArgs = ruleArguments as Dictionary < string , object > ;
291286 if ( ruleArgs == null )
292287 {
293- throw new ArgumentException (
294- "input should be a dictionary" ,
295- "ruleArguments" ) ;
288+ throw new ArgumentException ( Strings . SettingsInputShouldBeDictionary , nameof ( ruleArguments ) ) ;
296289 }
297290
298291 if ( ruleArgs . Comparer != StringComparer . OrdinalIgnoreCase )
299292 {
300- throw new ArgumentException (
301- "Input dictionary should have OrdinalIgnoreCase comparer." ,
302- "ruleArguments" ) ;
293+ throw new ArgumentException ( Strings . SettingsDictionaryShouldBeCaseInsesitive , nameof ( ruleArguments ) ) ;
303294 }
304295
305296 var ruleArgsDict = new Dictionary < string , Dictionary < string , object > > ( StringComparer . OrdinalIgnoreCase ) ;
@@ -308,9 +299,7 @@ private Dictionary<string, Dictionary<string, object>> ConvertToRuleArgumentTyp
308299 var argsDict = ruleArgs [ rule ] as Dictionary < string , object > ;
309300 if ( argsDict == null )
310301 {
311- throw new ArgumentException (
312- "input should be a dictionary" ,
313- "ruleArguments" ) ;
302+ throw new InvalidDataException ( Strings . SettingsInputShouldBeDictionary ) ;
314303 }
315304 ruleArgsDict [ rule ] = argsDict ;
316305 }
@@ -341,19 +330,25 @@ private void parseSettingsHashtable(Hashtable settingsHashtable)
341330 break ;
342331
343332 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+
345344 break ;
346345
347346 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 ) ) ;
357352 }
358353 }
359354 }
@@ -368,10 +363,7 @@ private void parseSettingsFile(string settingsFilePath)
368363 // no hashtable, raise warning
369364 if ( hashTableAsts . Count ( ) == 0 )
370365 {
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 ) ) ;
375367 }
376368
377369 HashtableAst hashTableAst = hashTableAsts . First ( ) as HashtableAst ;
@@ -384,12 +376,16 @@ private void parseSettingsFile(string settingsFilePath)
384376 }
385377 catch ( InvalidOperationException e )
386378 {
387- throw new ArgumentException ( "input file has invalid hashtable" , e ) ;
379+ throw new ArgumentException ( Strings . InvalidProfile , e ) ;
388380 }
389381
390382 if ( hashtable == null )
391383 {
392- throw new ArgumentException ( "input file has invalid hashtable" ) ;
384+ throw new ArgumentException (
385+ String . Format (
386+ CultureInfo . CurrentCulture ,
387+ Strings . InvalidProfile ,
388+ settingsFilePath ) ) ;
393389 }
394390
395391 parseSettingsHashtable ( hashtable ) ;
0 commit comments