Ejemplo n.º 1
0
        /// <summary>
        /// Performs the validation
        /// </summary>
        /// <param name="requirement">a requirement facility</param>
        /// <param name="submitted">the submission model to be validated</param>
        /// <returns></returns>
        public Facility Validate(Facility requirement, Facility submitted)
        {
            var retFacility = new Facility {Categories = new List<Category>()};
            var sb = new StringBuilder();

            // facility validation is carried out through the validation of:
            // a) local values
            // b) Project
            // c) AssetTypes/Assets
            // d) Zones/Spaces 
            // e) Documents

            if (!requirement.IsClassifiedAsRequirement())
            {
                retFacility.Categories.Add(FailedCat);
                retFacility.Name = "Invalid.";
                retFacility.Description = "Cannot validate submitted facility: requirement file is invalid.";
                return retFacility;
            }

            // a)
            // area units
            if (requirement.AreaUnitsCustom != submitted.AreaUnitsCustom)
            {
                retFacility.AreaUnitsCustom = string.Format("{0} (should be '{1}')", submitted.AreaUnitsCustom, requirement.AreaUnitsCustom);
                sb.AppendFormat("{0} failure: {1}\r\n", "Area units", retFacility.AreaUnitsCustom);
                HasFailures = true;
            }
            else
            {
                retFacility.AreaUnitsCustom = submitted.AreaUnitsCustom;
            }

            // linear units
            if (requirement.LinearUnitsCustom != submitted.LinearUnitsCustom)
            {
                retFacility.LinearUnitsCustom = string.Format("{0} (should be '{1}')", submitted.LinearUnitsCustom, requirement.LinearUnitsCustom);
                sb.AppendFormat("{0} failure: {1}\r\n", "Linear units", retFacility.LinearUnitsCustom);
                HasFailures = true;
            }
            else
            {
                retFacility.LinearUnitsCustom = submitted.LinearUnitsCustom;
            }

            // Volume units
            if (requirement.VolumeUnitsCustom != submitted.VolumeUnitsCustom)
            {
                retFacility.VolumeUnitsCustom = string.Format("{0} (should be '{1}')", submitted.VolumeUnitsCustom, requirement.VolumeUnitsCustom);
                sb.AppendFormat("{0} failure: {1}\r\n", "Volume units", retFacility.VolumeUnitsCustom);
                HasFailures = true;
            }
            else
            {
                retFacility.VolumeUnitsCustom = submitted.VolumeUnitsCustom;
            }

            // Currency units
            if (requirement.CurrencyUnitCustom != submitted.CurrencyUnitCustom)
            {
                retFacility.CurrencyUnitCustom = string.Format("{0} (should be '{1}')", submitted.CurrencyUnitCustom, requirement.CurrencyUnitCustom);
                sb.AppendFormat("{0} failure: {1}\r\n", "Currency units", retFacility.CurrencyUnitCustom);
                HasFailures = true;
            }
            else
            {
                retFacility.CurrencyUnitCustom = submitted.CurrencyUnitCustom;
            }

            if (requirement.Project != null)
            {
                // to be added project level validation here.
                var pv = new ProjectValidator(requirement.Project);
                retFacility.Project = pv.Validate(submitted.Project);

                if (pv.HasFailures)
                {
                    sb.AppendFormat("Validation of Project information fails, see project information for detail.\r\n");
                    HasFailures = true;
                }
            }
            // c) AssetTypes/Assets
            HasFailures |= ValidateAssetTypes(requirement, submitted, retFacility);
            // d) Zones/Spaces
            HasFailures |= ValidateZones(requirement, submitted, retFacility);

            // e) Documents
            HasFailures |= ValidateDocuments(requirement, submitted, retFacility);

            retFacility.Description = sb.ToString();
            retFacility.Categories.Add(HasFailures ? FailedCat : PassedCat);

            return retFacility;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs the validation
        /// </summary>
        /// <param name="requirement">a requirement facility</param>
        /// <param name="submitted">the submission model to be validated</param>
        /// <returns></returns>
        public Facility Validate(Facility requirement, Facility submitted)
        {
            var retFacility = new Facility {
                Categories = new List <Category>()
            };
            var sb = new StringBuilder();

            // facility validation is carried out through the validation of:
            // a) local values
            // b) Project
            // c) AssetTypes/Assets
            // d) Zones/Spaces
            // e) Documents

            if (!requirement.IsClassifiedAsRequirement())
            {
                retFacility.Categories.Add(FailedCat);
                retFacility.Name        = "Invalid.";
                retFacility.Description = "Cannot validate submitted facility: requirement file is invalid.";
                return(retFacility);
            }

            // a)
            // area units
            if (requirement.AreaUnitsCustom != submitted.AreaUnitsCustom)
            {
                retFacility.AreaUnitsCustom = string.Format("{0} (should be '{1}')", submitted.AreaUnitsCustom, requirement.AreaUnitsCustom);
                sb.AppendFormat("{0} failure: {1}\r\n", "Area units", retFacility.AreaUnitsCustom);
                HasFailures = true;
            }
            else
            {
                retFacility.AreaUnitsCustom = submitted.AreaUnitsCustom;
            }

            // linear units
            if (requirement.LinearUnitsCustom != submitted.LinearUnitsCustom)
            {
                retFacility.LinearUnitsCustom = string.Format("{0} (should be '{1}')", submitted.LinearUnitsCustom, requirement.LinearUnitsCustom);
                sb.AppendFormat("{0} failure: {1}\r\n", "Linear units", retFacility.LinearUnitsCustom);
                HasFailures = true;
            }
            else
            {
                retFacility.LinearUnitsCustom = submitted.LinearUnitsCustom;
            }

            // Volume units
            if (requirement.VolumeUnitsCustom != submitted.VolumeUnitsCustom)
            {
                retFacility.VolumeUnitsCustom = string.Format("{0} (should be '{1}')", submitted.VolumeUnitsCustom, requirement.VolumeUnitsCustom);
                sb.AppendFormat("{0} failure: {1}\r\n", "Volume units", retFacility.VolumeUnitsCustom);
                HasFailures = true;
            }
            else
            {
                retFacility.VolumeUnitsCustom = submitted.VolumeUnitsCustom;
            }

            // Currency units
            if (requirement.CurrencyUnitCustom != submitted.CurrencyUnitCustom)
            {
                retFacility.CurrencyUnitCustom = string.Format("{0} (should be '{1}')", submitted.CurrencyUnitCustom, requirement.CurrencyUnitCustom);
                sb.AppendFormat("{0} failure: {1}\r\n", "Currency units", retFacility.CurrencyUnitCustom);
                HasFailures = true;
            }
            else
            {
                retFacility.CurrencyUnitCustom = submitted.CurrencyUnitCustom;
            }

            if (requirement.Project != null)
            {
                // to be added project level validation here.
                var pv = new ProjectValidator(requirement.Project);
                retFacility.Project = pv.Validate(submitted.Project);
                retFacility.Name    = retFacility.Project.Name;

                if (pv.HasFailures)
                {
                    sb.AppendFormat("Validation of Project information fails, see project information for detail.\r\n");
                    HasFailures = true;
                }
            }
            // c) AssetTypes/Assets
            HasFailures |= ValidateAssetTypes(requirement, submitted, retFacility);
            // d) Zones/Spaces
            HasFailures |= ValidateZones(requirement, submitted, retFacility);

            // e) Documents
            HasFailures |= ValidateDocuments(requirement, submitted, retFacility);

            retFacility.Description = sb.ToString();
            retFacility.Categories.Add(HasFailures ? FailedCat : PassedCat);

            return(retFacility);
        }