Пример #1
0
        public ConvertingValidatorResult ValidateImportValue(FieldDescriptor targetField, string value, bool throwOnFailure = false)
        {
            if (targetField.Validate == null || string.IsNullOrWhiteSpace(value)) {
                var result = new ConvertingValidatorResult(targetField, value);
                result.Success(value);
                return result;
            } else {
                var result = new ConvertingValidatorResult(targetField, value);
                targetField.Validate(value, result);
                if (throwOnFailure && !result.IsValid) {
                    throw new Exception(result.Message);
                }

                return result;
            }
        }
Пример #2
0
        public static bool UnitRangeValidator( string value, ConvertingValidatorResult result)
        {
            if (value.IsNumeric()) {
                return result.Success(new UnitRange(Double.Parse(value)));
            }

            var matcher = _UnitRangeSingleUnitsRegex.Match(value);
            if (matcher.Success) {
                var upper = double.Parse(matcher.Groups[1].Value);
                var units = matcher.Groups[2].Value;
                return result.Success(new UnitRange(upper, units));
            }

            matcher = _UnitRangeRegex.Match(value);
            if (matcher.Success) {
                var lower = double.Parse(matcher.Groups[1].Value);
                var upper = double.Parse(matcher.Groups[2].Value);
                string units = null;
                if (matcher.Groups.Count > 2) {
                    units = matcher.Groups[3].Value;
                }
                return result.Success(new UnitRange(upper, lower, units));
            }

            return result.Fail("Invalid number or range. Must be either a number, number and units or a range of numbers with or without units (e.g. 18.2, 18.2 KM, 100-150, 100-150 metres)");
        }
Пример #3
0
        public static bool UTMZoneValidator(string value, ConvertingValidatorResult result)
        {
            if (_UTMZoneRegex.IsMatch(value)) {
                return result.Success(value);
            }

            return result.Fail("Invalid or incorrectly formatted UTM zone. Must include a UTM zone number and Latitude Band letter.");
        }
Пример #4
0
 /// <summary>
 /// Default validator for fields - all values are accepted.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="result"></param>
 public static bool StringValidator(string value, ConvertingValidatorResult result)
 {
     return result.Success(value);
 }
Пример #5
0
        public static bool TimeValidator(string value, ConvertingValidatorResult result)
        {
            if (value.Length < 4) {
                value = value.PadLeft(4, '0');
            }

            var matcher = _TimeRegex.Match(value);
            if (matcher.Success) {
                var time = string.Format("{0}{1}", matcher.Groups[1].Value, matcher.Groups[2].Value);
                return result.Success(Int32.Parse(time));
            }

            return result.Fail("Invalid time format. Times must be either hhmm or hh:mm (24 hour time).");
        }
Пример #6
0
 public static bool IntegerValidator(string value, ConvertingValidatorResult result)
 {
     int i = 0;
     if (Int32.TryParse(value, out i)) {
         return result.Success(i);
     }
     return result.Fail("'{0}' is not an integer", value);
 }
Пример #7
0
 public static bool PositionAreaTypeValidator(string value, ConvertingValidatorResult result)
 {
     int i;
     if (Int32.TryParse(value, out i)) {
         if ( i >= 1 && i <= 3) {
             return result.Success(i);
         } else {
             return result.Fail("Value must be between 1 and 3 (1 = Point/Circle, 2 = Line, 3 = Rectangle)");
         }
     } else {
         return result.Fail("Value must be an integer");
     }
 }
Пример #8
0
        public static bool EllipsoidIndexConverter(string value, ConvertingValidatorResult result)
        {
            if (value.IsNumeric()) {
                int i;
                if (Int32.TryParse(value, out i)) {
                    if (i >= 0 && i < GeoUtils.ELLIPSOIDS.Length) {
                        return result.Success(i);
                    }
                }
            }

            var lngEllipsoid = GeoUtils.GetEllipsoidIndex(value);

            if (lngEllipsoid >= 0) {
                return result.Success(lngEllipsoid);
            }

            return result.Fail("Invalid ellipsoid value. Must be either an ellipsoid name, or and index between 0 and {1}.", GeoUtils.ELLIPSOIDS.Length - 1);
        }
Пример #9
0
        public static bool CoordinateValidator(string value, ConvertingValidatorResult result)
        {
            double? coord = GeoUtils.ParseCoordinate(value);
            if (coord.HasValue) {
                return result.Success(coord.Value);
            }

            return result.Fail("Invalid coordinate format");
        }
Пример #10
0
 public static bool CoordinateTypeValidator(string value, ConvertingValidatorResult result)
 {
     int i;
     if (Int32.TryParse(value, out i)) {
         if ( i >= 1 && i <= 3) {
             return result.Success(i);
         } else {
             return result.Fail("Value must be either 1 or 2 (1 = Latitude and longitude, 2 = UTM)");
         }
     } else {
         return result.Fail("Value must be an integer");
     }
 }
Пример #11
0
        public static bool BooleanValidator(string value, ConvertingValidatorResult result)
        {
            bool b;
            if (Boolean.TryParse(value, out b)) {
                return result.Success(b);
            }

            if ("Y1".Contains(value[0])) {
                return result.Success(true);
            } else if ("N0".Contains(value[0])) {
                return result.Success(false);
            }

            return result.Fail("Must yield a boolean value (e.g. True, False, 0, 1, Y/N)");
        }
Пример #12
0
        public static bool BLDateValidator(string value, ConvertingValidatorResult result)
        {
            String errMsg;

            if (DateUtils.IsValidBLDate(value, out errMsg)) {
                return result.Success(Int32.Parse(value.PadRight(8, '0')));
            } else {
                if (Microsoft.VisualBasic.Information.IsDate(value)) {
                    return result.Success(Int32.Parse(DateUtils.DateStrToBLDate(value)));
                }
            }

            return result.Fail("Invalid date format");
        }