public LanguagesCommand(ITextResourceManager textManager)
 {
     TextManager = textManager;
 }
 private void RegisterTextResources(ITextResourceManager textResourceManager)
 {
     textResourceManager.RegisterKeys(TT2Localisation.Defaults);
     textResourceManager.RegisterKeys(GameEntityLocalisation.Defaults);
 }
Beispiel #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"></see> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.EventArgs"></see> that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            Type         t    = System.Type.GetType(this.Type, true);
            PropertyInfo info = t.GetProperty(_Property);

            object[] attributes = (object[])info.GetCustomAttributes(typeof(BusinessObjectValidationAttribute), false);

            ITextResourceManager resourceManager = null;

            if (!string.IsNullOrEmpty(this.ITextResourceManagerType))
            {
                resourceManager = Activator.CreateInstance(System.Type.GetType(this.ITextResourceManagerType)) as ITextResourceManager;
            }

            // check all attributes
            if (attributes.Length > 0)
            {// at least on attribute exists
                _ValidatorAttribute = attributes[0] as BusinessObjectValidationAttribute;

                if (!string.IsNullOrEmpty(_ValidatorAttribute.Regex))
                {
                    regularExpressionValidator = new RegularExpressionValidator();
                    regularExpressionValidator.ValidationExpression = _ValidatorAttribute.Regex;
                    regularExpressionValidator.ErrorMessage         = (resourceManager != null &&
                                                                       !string.IsNullOrEmpty(_ValidatorAttribute.RegexMessageResourceKey))
                                                                    ? resourceManager.GetResourceText(_ValidatorAttribute.RegexMessageResourceKey)
                                                                    : _ValidatorAttribute.RegexMessage;
                    regularExpressionValidator.ValidationGroup   = this.ValidationGroup;
                    regularExpressionValidator.ControlToValidate = this.ControlToValidate;
                    regularExpressionValidator.Display           = this.Display;
                    regularExpressionValidator.ID = this.ID + REGULAR_EXPRESSION_VALIDATOR_SUFFIX;
                    regularExpressionValidator.EnableClientScript = this.EnableClientScript;
                    this.Controls.Add(regularExpressionValidator);
                }

                if (_ValidatorAttribute.MaxLength >= 0 || _ValidatorAttribute.MinLength >= 0)
                {
                    customStringLengthValidator = new CustomValidator();
                    customStringLengthValidator.ErrorMessage = (resourceManager != null &&
                                                                !string.IsNullOrEmpty(_ValidatorAttribute.OutOfRangeErrorMessageResourceKey))
                                                                    ? resourceManager.GetResourceText(_ValidatorAttribute.OutOfRangeErrorMessageResourceKey)
                                                                    : _ValidatorAttribute.OutOfRangeErrorMessage;
                    customStringLengthValidator.ValidationGroup   = this.ValidationGroup;
                    customStringLengthValidator.ControlToValidate = this.ControlToValidate;
                    customStringLengthValidator.Display           = this.Display;
                    customStringLengthValidator.ID = this.ID + CUSTOM_STRING_LENGTH_VALIDATOR_SUFFIX;
                    customStringLengthValidator.EnableClientScript = this.EnableClientScript;
                    customStringLengthValidator.ValidateEmptyText  = true;
                    customStringLengthValidator.ServerValidate    += new ServerValidateEventHandler(customStringLengthValidator_ServerValidate);
                    this.Controls.Add(customStringLengthValidator);
                }

                if (!string.IsNullOrEmpty(_ValidatorAttribute.MinimumValue) || !string.IsNullOrEmpty(_ValidatorAttribute.MaximumValue))
                {
                    rangeValidator = new RangeValidator();
                    rangeValidator.MinimumValue = _ValidatorAttribute.MinimumValue;
                    rangeValidator.MaximumValue = _ValidatorAttribute.MaximumValue;
                    rangeValidator.ErrorMessage = (resourceManager != null &&
                                                   !string.IsNullOrEmpty(_ValidatorAttribute.OutOfRangeErrorMessageResourceKey))
                                                                    ? resourceManager.GetResourceText(_ValidatorAttribute.OutOfRangeErrorMessageResourceKey)
                                                                    : _ValidatorAttribute.OutOfRangeErrorMessage;
                    rangeValidator.ControlToValidate = this.ControlToValidate;
                    rangeValidator.Display           = this.Display;
                    rangeValidator.ID = this.ID + RANGE_VALIDATOR_SUFFIX;
                    rangeValidator.EnableClientScript = this.EnableClientScript;
                    rangeValidator.Type = this.RangeValidationDataType;
                    this.Controls.Add(rangeValidator);
                }

                if (_ValidatorAttribute.IsRequired)
                {
                    requiredFieldValidator = new RequiredFieldValidator();
                    requiredFieldValidator.ControlToValidate = this.ControlToValidate;
                    requiredFieldValidator.Display           = this.Display;
                    requiredFieldValidator.ErrorMessage      = (resourceManager != null &&
                                                                !string.IsNullOrEmpty(_ValidatorAttribute.IsRequiredMessageResourceKey))
                                                                    ? resourceManager.GetResourceText(_ValidatorAttribute.IsRequiredMessageResourceKey)
                                                                    : _ValidatorAttribute.IsRequiredMessage;
                    requiredFieldValidator.ID = this.ID + REQUIRED_FIELD_VALIDATOR_SUFFIX;
                    requiredFieldValidator.EnableClientScript = this.EnableClientScript;
                    this.Controls.Add(requiredFieldValidator);
                }

                if (!string.IsNullOrEmpty(this.ControlToCompare))
                {
                    compareValidator = new CompareValidator();
                    compareValidator.ControlToCompare  = this.ControlToCompare;
                    compareValidator.ControlToValidate = this.ControlToValidate;
                    compareValidator.Display           = this.Display;
                    compareValidator.ID = this.ID + COMPARE_VALIDATOR_SUFFIX;
                    compareValidator.EnableClientScript = this.EnableClientScript;
                    this.Controls.Add(compareValidator);
                }
            }
        }