protected override bool EvaluateIsValid()
        {
            if (string.IsNullOrWhiteSpace(BingMapRestUrl))
            {
                throw new ArgumentNullException(BingMapRestUrl);
            }

            if (string.IsNullOrWhiteSpace(BingMapKey))
            {
                throw new ArgumentNullException(BingMapKey);
            }

            var query = GetControlValidationValue(ControlToValidate);

            var bingMapLookup = new BingMapLookup(BingMapRestUrl, BingMapKey, UserLocation, IncludeNeighborhood ?? 0);

            return(bingMapLookup.IsLocationValid(query));
        }
Exemple #2
0
        protected override void InstantiateValidatorsIn(Control container)
        {
            if (Metadata.IsRequired || Metadata.WebFormForceFieldIsRequired)
            {
                container.Controls.Add(new RequiredFieldValidator
                {
                    ID = string.Format("RequiredFieldValidator{0}", ControlID),
                    ControlToValidate = ControlID,
                    ValidationGroup   = ValidationGroup,
                    Display           = ValidatorDisplay,
                    ErrorMessage      = ValidationSummaryMarkup((String.IsNullOrWhiteSpace(Metadata.RequiredFieldValidationErrorMessage) ? (Metadata.Messages == null || !Metadata.Messages.ContainsKey("Required")) ? ResourceManager.GetString("Required_Field_Error").FormatWith(Metadata.Label) : Metadata.Messages["Required"].FormatWith(Metadata.Label) : Metadata.RequiredFieldValidationErrorMessage)),
                    Text = Metadata.ValidationText,
                });
            }

            if (PortalSettings.Instance.BingMapsSupported && Metadata.ControlStyle == WebFormMetadata.ControlStyle.GeolocationLookupValidator)
            {
                var locationValidator = new CustomValidator
                {
                    ID = string.Format("GeolocationValidator{0}", ControlID),
                    ControlToValidate = ControlID,
                    ValidationGroup   = ValidationGroup,
                    Display           = ValidatorDisplay.None,
                    ErrorMessage      = ValidationSummaryMarkup((String.IsNullOrWhiteSpace(Metadata.GeolocationValidatorErrorMessage) ? ResourceManager.GetString("Invalid_Error").FormatWith(Metadata.Label) : Metadata.GeolocationValidatorErrorMessage))
                };

                var bingLookup = new BingMapLookup();

                locationValidator.ServerValidate += bingLookup.LocationServerValidate;

                container.Controls.Add(locationValidator);
            }

            if (!string.IsNullOrWhiteSpace(Metadata.ValidationRegularExpression))
            {
                container.Controls.Add(new RegularExpressionValidator
                {
                    ID = string.Format("RegularExpressionValidator{0}", ControlID),
                    ControlToValidate = ControlID,
                    ValidationGroup   = ValidationGroup,
                    ErrorMessage      = ValidationSummaryMarkup((String.IsNullOrWhiteSpace(Metadata.ValidationRegularExpressionErrorMessage) ? ResourceManager.GetString("Invalid_Error").FormatWith(Metadata.Label) : Metadata.ValidationRegularExpressionErrorMessage)),
                    Text = "*",
                    ValidationExpression = Metadata.ValidationRegularExpression
                });
            }

            if (Metadata.MaxLength > 0)
            {
                var maxLengthValidator = new CustomValidator
                {
                    ID = $"MaximumLengthValidator{ControlID}",
                    ControlToValidate = ControlID,
                    ValidationGroup   = ValidationGroup,
                    ErrorMessage      = ValidationSummaryMarkup(ResourceManager.GetString("MaxLength_Validation_Error").FormatWith(Metadata.Label, Metadata.MaxLength)),
                    Text = "*"
                };

                maxLengthValidator.ServerValidate += MaxLengthValidate;

                container.Controls.Add(maxLengthValidator);
            }

            this.InstantiateCustomValidatorsIn(container);
        }