#region Disclaimer / License // Copyright (C) 2010, Jackie Ng // http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie@gmail.com // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // #endregion using System; using System.Collections.Generic; using System.Text; using OSGeo.MapGuide.MaestroAPI.Resource; using OSGeo.MapGuide.MaestroAPI; namespace OSGeo.MapGuide.MaestroAPI.Resource.Validation { /// /// A "bucket" class that filters out redundant validation messages /// public class ValidationResultSet { //HACK: Abusing the Key component of Dictionary because there is no //Set collection in .net fx 2.0! private Dictionary> _issues; /// /// Initializes a new instance of the class. /// public ValidationResultSet() { _issues = new Dictionary>(); } /// /// Initializes a new instance of the class. /// /// The issues. public ValidationResultSet(IEnumerable issues) : this() { Check.NotNull(issues, "issues"); AddIssues(issues); } /// /// Gets the resource IDs /// /// The resource IDs. public string[] ResourceIDs { get { return new List(_issues.Keys).ToArray(); } } /// /// Gets the issues for resource. /// /// The resource id. /// public ICollection GetIssuesForResource(string resourceId) { Check.NotEmpty(resourceId, "resourceId"); if (_issues.ContainsKey(resourceId)) return _issues[resourceId].Keys; return new List(); } /// /// Gets the issues for resource. /// /// The resource id. /// Type of the stat. /// public ICollection GetIssuesForResource(string resourceId, ValidationStatus statType) { var issues = new List(); foreach (var issue in GetIssuesForResource(resourceId)) { if (issue.Status == statType) issues.Add(issue); } return issues; } /// /// Gets all issues. /// /// public ValidationIssue[] GetAllIssues() { var issues = new List(); foreach (string resId in _issues.Keys) { issues.AddRange(_issues[resId].Keys); } return issues.ToArray(); } /// /// Adds the issue. /// /// The issue. public void AddIssue(ValidationIssue issue) { Check.NotNull(issue, "issue"); Check.NotNull(issue.Resource, "issue.Resource"); Check.NotEmpty(issue.Resource.ResourceID, "issue.Resource.ResourceID"); if (!_issues.ContainsKey(issue.Resource.ResourceID)) _issues[issue.Resource.ResourceID] = new Dictionary(); _issues[issue.Resource.ResourceID][issue] = issue; } /// /// Adds the issues. /// /// The issues. public void AddIssues(IEnumerable issues) { if (issues == null) return; foreach (var issue in issues) { AddIssue(issue); } } } }