comparison API/Objects/Requirement/RequirementHandler.cs @ 361:8781e53c59bb

Re #345: Add failure message to requirements * Return message for each failure (don't stop at first one)
author IBBoard <dev@ibboard.co.uk>
date Sun, 01 May 2011 14:45:56 +0000
parents 47712a323cf2
children 506af4cbe3f5
comparison
equal deleted inserted replaced
360:777725613edb 361:8781e53c59bb
1 // This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard 1 // This file (RequirementHandler.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
2 // 2 //
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. 3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
4 using System; 4 using System;
5 using System.Collections.Generic;
5 6
6 namespace IBBoard.WarFoundry.API.Objects.Requirement 7 namespace IBBoard.WarFoundry.API.Objects.Requirement
7 { 8 {
8 /// <summary> 9 /// <summary>
9 /// The requirement handler that tests the validity of armies. 10 /// The requirement handler that tests the validity of armies.
14 { 15 {
15 } 16 }
16 17
17 public static Validation ValidateArmy (Army army) 18 public static Validation ValidateArmy (Army army)
18 { 19 {
20 ICollection<string> ignored;
21 return ValidateArmy(army, out ignored);
22 }
23
24 public static Validation ValidateArmy (Army army, out ICollection<string> failureMessages)
25 {
19 Validation result = Validation.Passed; 26 Validation result = Validation.Passed;
27 failureMessages = new List<string>();
20 28
21 foreach (IRequirement requirement in army.GetRequirements()) 29 foreach (IRequirement requirement in army.GetRequirements())
22 { 30 {
23 if (!Validates.AsOkay(requirement.ValidatesArmy(army))) 31 if (!Validates.AsOkay(requirement.ValidatesArmy(army)))
24 { 32 {
25 result = Validation.Failed; 33 result = Validation.Failed;
26 break; 34 failureMessages.Add(requirement.GetValidationMessage(army));
27 } 35 }
28 } 36 }
29 37
30 return result; 38 return result;
31 } 39 }