Exemple #1
0
        private 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));
        }
Exemple #2
0
        protected virtual IDictionary <string, object> GetResourceStrings(IEnumerable <string> keys, string path)
        {
            if (keys == null)
            {
                return(null);
            }

            Dictionary <string, object> res = new Dictionary <string, object>();

            foreach (string key in keys)
            {
                ResourceExpressionFields fields = ResourceExpressionBuilder.ParseExpression(key);
                if (fields == null)
                {
                    continue;
                }

                object value;
                try
                {
                    bool isLocal = String.IsNullOrEmpty(fields.ClassKey);
                    if (!isLocal && fields.ClassKey.IndexOf(Path.AltDirectorySeparatorChar) >= 0)
                    {
                        path    = fields.ClassKey;
                        isLocal = true;
                    }

                    if (isLocal)
                    {
                        string lookupPath = ResourceHandler.EnsureAppAbsolute(path).TrimStart('~');
                        value = HttpContext.GetLocalResourceObject(lookupPath, fields.ResourceKey);
                    }
                    else
                    {
                        value = HttpContext.GetGlobalResourceObject(fields.ClassKey, fields.ResourceKey);
                    }
                }
                catch (Exception ex)
                {
                    value = "$$" + ex.Message + "$$";
                }

                if (value == null)
                {
                    continue;
                }
                res[GetKey(fields, path)] = value;
            }

            return(res);
        }
        public override object EvaluateExpression(string expression, object parseTimeData, Type propertyType, IServiceProvider serviceProvider)
        {
            System.Web.Compilation.ResourceExpressionFields fields;
            IResourceProvider provider;

            if (parseTimeData is System.Web.Compilation.ResourceExpressionFields)
            {
                fields = (System.Web.Compilation.ResourceExpressionFields)parseTimeData;
            }
            else
            {
                fields = ResourceExpressionBuilder.ParseExpression(expression);
            }
            if (string.IsNullOrEmpty(fields.ResourceKey))
            {
                return(null);
            }
            object obj2 = null;
            DesignTimeResourceProviderFactory designTimeResourceProviderFactory = ControlDesigner.GetDesignTimeResourceProviderFactory(serviceProvider);

            if (string.IsNullOrEmpty(fields.ClassKey))
            {
                provider = designTimeResourceProviderFactory.CreateDesignTimeLocalResourceProvider(serviceProvider);
            }
            else
            {
                provider = designTimeResourceProviderFactory.CreateDesignTimeGlobalResourceProvider(serviceProvider, fields.ClassKey);
            }
            if (provider != null)
            {
                obj2 = provider.GetObject(fields.ResourceKey, CultureInfo.InvariantCulture);
            }
            if (obj2 != null)
            {
                Type c = obj2.GetType();
                if (!propertyType.IsAssignableFrom(c))
                {
                    TypeConverter converter = TypeDescriptor.GetConverter(propertyType);
                    if ((converter != null) && converter.CanConvertFrom(c))
                    {
                        return(converter.ConvertFrom(obj2));
                    }
                }
            }
            return(obj2);
        }
Exemple #4
0
        public static string GetStringByExpression(this SenseNetResourceManager resourceManager, string expression)
        {
            if (string.IsNullOrEmpty(expression))
            {
                return(expression);
            }

            if (!expression.StartsWith(SenseNetResourceManager.ResourceStartKey) ||
                !expression.EndsWith(SenseNetResourceManager.ResourceEndKey))
            {
                return(null);
            }

            expression = expression.Replace(" ", "");
            expression = expression.Replace(SenseNetResourceManager.ResourceStartKey, "");
            expression = expression.Replace(SenseNetResourceManager.ResourceEndKey, "");

            if (expression.Contains("Resources:"))
            {
                expression = expression.Remove(expression.IndexOf("Resources:", StringComparison.Ordinal), 10);
            }

            var expressionFields = ResourceExpressionBuilder.ParseExpression(expression);

            if (expressionFields == null)
            {
                var context = HttpContext.Current;
                var msg     = $"{expression} is not a valid string resource format.";
                if (context == null)
                {
                    throw new ApplicationException(msg);
                }
                return(string.Format(msg));
            }

            return(resourceManager.GetString(expressionFields.ClassKey, expressionFields.ResourceKey));
        }
        private static string GetResourceString(HttpContextBase httpContext, string expression, string virtualPath, object[] args)
        {
            var context = new ExpressionBuilderContext(virtualPath);
            var builder = new ResourceExpressionBuilder();
            var fields  = (ResourceExpressionFields)builder.ParseExpression("LanguageResource, " + expression, typeof(string), context);

            string text;

            if (!string.IsNullOrEmpty(fields.ClassKey))
            {
                text = (string)httpContext.GetGlobalResourceObject(fields.ClassKey, fields.ResourceKey, CultureInfo.CurrentUICulture);
            }
            else
            {
                text = (string)httpContext.GetLocalResourceObject(virtualPath, fields.ResourceKey, CultureInfo.CurrentUICulture);
            }

            if (String.IsNullOrEmpty(text))
            {
                return(String.Empty);
            }

            return(String.Format(text, args));
        }
Exemple #6
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="value"></param>
 /// <param name="path"></param>
 protected internal ResourceJbstExtension(string value, string path)
     : base(value, path)
 {
     this.ResKey = ResourceExpressionBuilder.ParseExpression(this.Value);
 }