Esempio n. 1
0
 private static string GetInvalidPropertyValueResource(HttpContextBase httpContext)
 {
     string str = (string)null;
     if (!string.IsNullOrEmpty(ValidationExtensions.ResourceClassKey) && httpContext != null)
         str = httpContext.GetGlobalResourceObject(ValidationExtensions.ResourceClassKey, "InvalidPropertyValue", CultureInfo.CurrentUICulture) as string;
     return str;
 }
        internal static string GetResourceString(HttpContextBase httpContext,
                                                string expression,
                                                string virtualPath,
                                                object[] args)

        {
            ExpressionBuilderContext context = new ExpressionBuilderContext(virtualPath);

            ResourceExpressionBuilder builder = new ResourceExpressionBuilder();

            ResourceExpressionFields fields = (ResourceExpressionFields) builder
                                                                             .ParseExpression(expression,
                                                                                              typeof (string), context);


            if (!string.IsNullOrEmpty(fields.ClassKey))

                return string.Format((string) httpContext.GetGlobalResourceObject(
                                                  fields.ClassKey,
                                                  fields.ResourceKey,
                                                  CultureInfo.CurrentUICulture),
                                     args);


            return string.Format((string) httpContext.GetLocalResourceObject(
                                              virtualPath,
                                              fields.ResourceKey,
                                              CultureInfo.CurrentUICulture),
                                 args);
        }
Esempio n. 3
0
        private static string GetResourceString(HttpContextBase httpContext, string classKey, string resourceKey)
        {
            string value = httpContext.GetGlobalResourceObject(classKey, resourceKey) as string;

            if (string.IsNullOrEmpty(value))
            {
                string message = string.Format("Translation missing for key '{0}' in bundle '{1}' for culture '{2}'.", resourceKey, classKey, Thread.CurrentThread.CurrentCulture);
                throw new ResourceNotFoundException(message);
            }

            return value;
        }
Esempio n. 4
0
        private static string GetResourceString(HttpContextBase httpContext, string expression, string virtualPath, object[] args)
        {
            string result;
            var identity = SqlResourceProvider.GetClassKey(expression);
            if (identity.ClassKey != null)
                result = (string)httpContext.GetGlobalResourceObject(identity.ClassKey, identity.ResourceKey, CultureInfo.CurrentUICulture);
            else
                result = (string)httpContext.GetLocalResourceObject(virtualPath, identity.ResourceKey, CultureInfo.CurrentUICulture);

            return args.Length > 0
                ? string.Format(result, args)
                : result;
        }
        /// <summary>
        /// Gets resource String using specified scope, key and culture.
        /// </summary>
        /// <remarks>
        /// <paramref name="translationMissing"/> handler will be called if resource can not be found.
        /// </remarks>
        /// <param name="context">The http context.</param>
        /// <param name="key">The resource key.</param>
        /// <param name="scope">The localization scope.</param>
        /// <param name="culture">The culture.</param>
        /// <param name="translationMissing">Translation missing fallback.</param>
        /// <returns>Localized String or <paramref name="translationMissing"/> result.</returns>
        public static String GetResourceString(HttpContextBase context, String key, String scope, CultureInfo culture, Func<String, String, String, String> translationMissing)
        {
            if (culture == null)
            {
                culture = CultureHelper.DefaultCulture;
            }

            var result = context.GetGlobalResourceObject(scope, key, culture) as String;
            if (result == null && translationMissing != null)
            {
                result = translationMissing(key, scope, culture.Name);
            }

            return result;
        }
        private static string GetInvalidPropertyValueResource(HttpContextBase httpContext)
        {
            string message = null;
            if (!string.IsNullOrEmpty(System.Web.Mvc.Html.ValidationExtensions.ResourceClassKey) && httpContext != null)
                message = httpContext.GetGlobalResourceObject(System.Web.Mvc.Html.ValidationExtensions.ResourceClassKey, "InvalidPropertyValue", CultureInfo.CurrentUICulture) as string;

            return message ?? "The value '{0}' is invalid.";
        }
Esempio n. 7
0
 private static string GetInvalidPropertyValueResource(HttpContextBase httpContext)
 {
     string str = null;
     if (!string.IsNullOrEmpty(System.Web.Mvc.Html.ValidationExtensions.ResourceClassKey) && (httpContext != null))
     {
         str = httpContext.GetGlobalResourceObject(System.Web.Mvc.Html.ValidationExtensions.ResourceClassKey, "InvalidPropertyValue", CultureInfo.CurrentUICulture) as string;
     }
     return (str ?? SR.GetString("Common_ValueNotValidForProperty"));
 }
 private static string GetInvalidPropertyValueResource(HttpContextBase httpContext)
 {
   string resourceValue = null;
   if (!String.IsNullOrEmpty(ResourceClassKey) && (httpContext != null))
   {
     // If the user specified a ResourceClassKey try to load the resource they specified.
     // If the class key is invalid, an exception will be thrown.
     // If the class key is valid but the resource is not found, it returns null, in which
     // case it will fall back to the MVC default error message.
     resourceValue = httpContext.GetGlobalResourceObject(ResourceClassKey, "InvalidPropertyValue", CultureInfo.CurrentUICulture) as string;
   }
   return resourceValue ?? "Invalid value";
 }