#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; namespace OSGeo.MapGuide.MaestroAPI.Resource { using Validation; /// /// Interface for validating specific resource types /// public interface IResourceValidator { /// /// Gets the resource type and version this validator supports /// ResourceTypeDescriptor SupportedResourceAndVersion { get; } /// /// Validats the specified resources for common issues associated with this /// resource type /// /// /// The resource to be validated /// Indicates whether to also validate resources this resource depends on /// ValidationIssue[] Validate(ResourceValidationContext context, IResource resource, bool recurse); } /// /// Represents a validation issue collected during validation /// public class ValidationIssue { /// /// Initializes a new instance of the class. /// /// The resource. /// The validation status. /// The validation status code. /// The message. public ValidationIssue(IResource res, ValidationStatus stat, ValidationStatusCode code, string msg) { Check.NotNull(res, "res"); Check.NotEmpty(msg, "msg"); this.Resource = res; this.Status = stat; this.Message = msg; this.StatusCode = code; } /// /// Gets the validation status code /// public ValidationStatusCode StatusCode { get; private set; } /// /// Gets the message for the validation issue /// public string Message { get; private set; } /// /// Gets the status of the validation issue /// public ValidationStatus Status { get; private set; } /// /// Gets the resource this issue pertains to /// public IResource Resource { get; private set; } /// /// Determines whether the specified is equal to this instance. /// /// The to compare with this instance. /// /// true if the specified is equal to this instance; otherwise, false. /// /// /// The parameter is null. /// public override bool Equals(object obj) { if (obj == null) return false; if (!typeof(ValidationIssue).IsAssignableFrom(obj.GetType())) return false; ValidationIssue vi = (ValidationIssue)obj; return this.Resource.ResourceID.Equals(vi.Resource.ResourceID) && this.Message.Equals(vi.Message) && this.Status == vi.Status && this.StatusCode == vi.StatusCode; } /// /// Returns a hash code for this instance. /// /// /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { //http://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-systemobjectgethashcode unchecked { int hash = 17; hash = hash * 23 + this.Resource.ResourceID.GetHashCode(); hash = hash * 23 + this.Message.GetHashCode(); hash = hash * 23 + this.Status.GetHashCode(); hash = hash * 23 + this.StatusCode.GetHashCode(); return hash; } } } /// /// All possible states a validation issue may have /// public enum ValidationStatus { /// /// Indicates that the issue is non-vital, eg. a performance problem /// Information, /// /// Indicates that the issue is likely to cause problems /// Warning, /// /// Indicates that the issue will prevent correct operation of the map /// Error } }