Exemple #1
0
        public void RegisterApplier(Type type, ITypeResolverApplier applier)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (applier == null)
            {
                throw new ArgumentNullException(nameof(applier));
            }

            var context = GetContext(type);

            if (context == null)
            {
                throw new InvalidOperationException(
                          LocalizationServices.Format <ITypeResolverLocalizationModel, DefaultTypeResolverLocalizationModel>(
                              x => x.TypeDescriptionNotFound, type.Name)
                          );
            }

            var applierCallbacks = context.ApplierCallbacks;

            if (applierCallbacks == null)
            {
                applierCallbacks         = new List <ITypeResolverApplier>();
                context.ApplierCallbacks = applierCallbacks;
            }

            applierCallbacks.Add(applier);
        }
Exemple #2
0
        public override bool Validate(object value, out ITranslateResult result)
        {
//            if (value == null)
//            {
//                if (RequiredMode.IsRequired && (RequiredMode.RequiredValidationMode == RequiredValidationModes.InvalidOnDefaultValue))
//                {
//                    error = string.Format(Translator.Translate(Resources.NullValue), FieldName);
//                    return false;
//                }
//                else
//                {
//                    error = Translator.Translate(Resources.ValidValue);
//                    return true;
//                }
//            }

//            string str = ((string)value);
//            if(str.Length == 0)
//            {
//                if (RequiredMode.IsRequired && RequiredMode.RequiredValidationMode == RequiredValidationModes.InvalidOnDefaultValue)
//                {
//                    error = string.Format(Translator.Translate(Resources.NullValue), FieldName);
//                    return false;
//                }
//            }
//            else if (str.Length < MinLength)
//            {
//                error = string.Format(Translator.Translate(Resources.InvalidStringBounds), FieldName, str, MinLength, Translator.Translate(Resources.LessThan));
//                return false;
//            }
//            else if (str.Length > MaxLength)
//            {
//                error = string.Format(Translator.Translate(Resources.InvalidStringBounds), FieldName, str, MaxLength, Translator.Translate(Resources.GreatThan));
//                return false;
//            }
//            else if (!string.IsNullOrWhiteSpace(RegexPattern))
//            {
//                bool regex_result = false;
//                try
//                {
//                    regex_result = Regex.IsMatch(str, RegexPattern);
//                }
//                catch { }
//                if (!regex_result)
//                {
//                    error = string.Format(Translator.Translate(Resources.InvalidStringPattern), FieldName, str);
//                    return false;
//                }
//            }

            result = LocalizationServices.FormatLazy <IValidationLocalization, DefaultValidationLocalization>(x => x.ValidValueString);
            return(true);
        }
Exemple #3
0
        public void RegisterApplier(Type type, object applier)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (applier == null)
            {
                throw new ArgumentNullException(nameof(applier));
            }

            var typeResolverApplier = applier as ITypeResolverApplier;

            if (typeResolverApplier == null)
            {
                throw new InvalidOperationException(
                          LocalizationServices.Format <ITypeResolverLocalizationModel, DefaultTypeResolverLocalizationModel>(
                              x => x.UnknownTypeForEngine, type.Name)
                          );
            }

            Mappings.RegisterApplier(type, typeResolverApplier);
        }
 public UniqueIndexOrPrimaryKeyOrConstriantViolationException()
     : base(LocalizationServices.Format <ISqlExceptionsLocalization, DefaultSqlExceptionsLocalization>(x => x.UniqueIndexOrPrimaryKeyOrConstraintViolation))
 {
 }
Exemple #5
0
 public UniqueIndexOrConstraintViolationException(Exception innerException)
     : base(LocalizationServices.Format <ISqlExceptionsLocalization, DefaultSqlExceptionsLocalization>(x => x.UniqueIndexOrConstraintViolation), innerException)
 {
 }
Exemple #6
0
 public LoginFailedException()
     : base(LocalizationServices.Format <ISqlExceptionsLocalization, DefaultSqlExceptionsLocalization>(x => x.LoginFailed))
 {
 }
 public ForeignKeyViolationException()
     : base(LocalizationServices.Format <ISqlExceptionsLocalization, DefaultSqlExceptionsLocalization>(x => x.ForeignKeyViolation))
 {
 }
Exemple #8
0
 public virtual string GetMessageFor(object value)
 {
     return(Validate(value, out ITranslateResult error)
         ? LocalizationServices.Format <IValidationLocalization, DefaultValidationLocalization>(x => x.ValidValueString)
         : error.GetValue());
 }
Exemple #9
0
 public ConstraintViolationException()
     : base(LocalizationServices.Format <ISqlExceptionsLocalization, DefaultSqlExceptionsLocalization>(x => x.ConstraintViolation))
 {
 }
 public InvalidDatabaseException()
     : base(LocalizationServices.Format <ISqlExceptionsLocalization, DefaultSqlExceptionsLocalization>(x => x.InvalidDatabase))
 {
 }