Exemple #1
0
        public static ExpressionEditor GetExpressionEditor(string expressionPrefix, IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                return(null);
            }

            IWebApplication webApp = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));

            if (webApp == null)
            {
                return(null);
            }

            _Configuration config = webApp.OpenWebConfiguration(true);

            if (config == null)
            {
                return(null);
            }

            CompilationSection sec = (CompilationSection)config.GetSection("system.web/compilation");

            System.Web.Configuration.ExpressionBuilder builder = sec.ExpressionBuilders [expressionPrefix];

            if (builder == null)
            {
                return(null);
            }

            return(GetExpressionEditor(Type.GetType(builder.Type), serviceProvider));
        }
Exemple #2
0
        internal static System.Web.Compilation.ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host)
        {
            if (expressionPrefix.Length == 0)
            {
                if (dataBindingExpressionBuilder == null)
                {
                    dataBindingExpressionBuilder = new DataBindingExpressionBuilder();
                }
                return(dataBindingExpressionBuilder);
            }
            CompilationSection compilationConfig = null;

            if (host != null)
            {
                IWebApplication application = (IWebApplication)host.GetService(typeof(IWebApplication));
                if (application != null)
                {
                    compilationConfig = application.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection;
                }
            }
            if (compilationConfig == null)
            {
                compilationConfig = MTConfigUtil.GetCompilationConfig(virtualPath);
            }
            System.Web.Configuration.ExpressionBuilder builder = compilationConfig.ExpressionBuilders[expressionPrefix];
            if (builder == null)
            {
                throw new HttpParseException(System.Web.SR.GetString("InvalidExpressionPrefix", new object[] { expressionPrefix }));
            }
            Type c = null;

            if (host != null)
            {
                ITypeResolutionService service = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
                if (service != null)
                {
                    c = service.GetType(builder.Type);
                }
            }
            if (c == null)
            {
                c = builder.TypeInternal;
            }
            if (!typeof(System.Web.Compilation.ExpressionBuilder).IsAssignableFrom(c))
            {
                throw new HttpParseException(System.Web.SR.GetString("ExpressionBuilder_InvalidType", new object[] { c.FullName }));
            }
            return((System.Web.Compilation.ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(c));
        }
        public static ExpressionEditor GetExpressionEditor(Type expressionBuilderType, IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            if (expressionBuilderType == null)
            {
                throw new ArgumentNullException("expressionBuilderType");
            }
            ExpressionEditor editor  = null;
            IWebApplication  service = (IWebApplication)serviceProvider.GetService(typeof(IWebApplication));

            if (service != null)
            {
                IDictionary expressionEditorsByTypeCache = GetExpressionEditorsByTypeCache(service);
                if (expressionEditorsByTypeCache != null)
                {
                    editor = (ExpressionEditor)expressionEditorsByTypeCache[expressionBuilderType];
                }
                if (editor != null)
                {
                    return(editor);
                }
                System.Configuration.Configuration configuration = service.OpenWebConfiguration(true);
                if (configuration == null)
                {
                    return(editor);
                }
                CompilationSection          section            = (CompilationSection)configuration.GetSection("system.web/compilation");
                ExpressionBuilderCollection expressionBuilders = section.ExpressionBuilders;
                bool   flag     = false;
                string fullName = expressionBuilderType.FullName;
                foreach (System.Web.Configuration.ExpressionBuilder builder in expressionBuilders)
                {
                    if (string.Equals(builder.Type, fullName, StringComparison.OrdinalIgnoreCase))
                    {
                        editor = GetExpressionEditorInternal(expressionBuilderType, builder.ExpressionPrefix, service, serviceProvider);
                        flag   = true;
                    }
                }
                if (flag)
                {
                    return(editor);
                }
                object[] customAttributes           = expressionBuilderType.GetCustomAttributes(typeof(ExpressionPrefixAttribute), true);
                ExpressionPrefixAttribute attribute = null;
                if (customAttributes.Length > 0)
                {
                    attribute = (ExpressionPrefixAttribute)customAttributes[0];
                }
                if (attribute != null)
                {
                    System.Web.Configuration.ExpressionBuilder buildProvider = new System.Web.Configuration.ExpressionBuilder(attribute.ExpressionPrefix, expressionBuilderType.FullName);
                    configuration = service.OpenWebConfiguration(false);
                    section       = (CompilationSection)configuration.GetSection("system.web/compilation");
                    section.ExpressionBuilders.Add(buildProvider);
                    configuration.Save();
                    editor = GetExpressionEditorInternal(expressionBuilderType, buildProvider.ExpressionPrefix, service, serviceProvider);
                }
            }
            return(editor);
        }
 public void Add(ExpressionBuilder buildProvider)
 {
 }
		public void Add (ExpressionBuilder buildProvider)
		{
			BaseAdd (buildProvider);
		}
 public static ExpressionEditor GetExpressionEditor(Type expressionBuilderType, IServiceProvider serviceProvider)
 {
     if (serviceProvider == null)
     {
         throw new ArgumentNullException("serviceProvider");
     }
     if (expressionBuilderType == null)
     {
         throw new ArgumentNullException("expressionBuilderType");
     }
     ExpressionEditor editor = null;
     IWebApplication service = (IWebApplication) serviceProvider.GetService(typeof(IWebApplication));
     if (service != null)
     {
         IDictionary expressionEditorsByTypeCache = GetExpressionEditorsByTypeCache(service);
         if (expressionEditorsByTypeCache != null)
         {
             editor = (ExpressionEditor) expressionEditorsByTypeCache[expressionBuilderType];
         }
         if (editor != null)
         {
             return editor;
         }
         System.Configuration.Configuration configuration = service.OpenWebConfiguration(true);
         if (configuration == null)
         {
             return editor;
         }
         CompilationSection section = (CompilationSection) configuration.GetSection("system.web/compilation");
         ExpressionBuilderCollection expressionBuilders = section.ExpressionBuilders;
         bool flag = false;
         string fullName = expressionBuilderType.FullName;
         foreach (System.Web.Configuration.ExpressionBuilder builder in expressionBuilders)
         {
             if (string.Equals(builder.Type, fullName, StringComparison.OrdinalIgnoreCase))
             {
                 editor = GetExpressionEditorInternal(expressionBuilderType, builder.ExpressionPrefix, service, serviceProvider);
                 flag = true;
             }
         }
         if (flag)
         {
             return editor;
         }
         object[] customAttributes = expressionBuilderType.GetCustomAttributes(typeof(ExpressionPrefixAttribute), true);
         ExpressionPrefixAttribute attribute = null;
         if (customAttributes.Length > 0)
         {
             attribute = (ExpressionPrefixAttribute) customAttributes[0];
         }
         if (attribute != null)
         {
             System.Web.Configuration.ExpressionBuilder buildProvider = new System.Web.Configuration.ExpressionBuilder(attribute.ExpressionPrefix, expressionBuilderType.FullName);
             configuration = service.OpenWebConfiguration(false);
             section = (CompilationSection) configuration.GetSection("system.web/compilation");
             section.ExpressionBuilders.Add(buildProvider);
             configuration.Save();
             editor = GetExpressionEditorInternal(expressionBuilderType, buildProvider.ExpressionPrefix, service, serviceProvider);
         }
     }
     return editor;
 }
Exemple #7
0
        internal static ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host)
        {
            // If there is no expressionPrefix, it's a v1 style databinding expression
            if (expressionPrefix.Length == 0)
            {
                if (dataBindingExpressionBuilder == null)
                {
                    dataBindingExpressionBuilder = new DataBindingExpressionBuilder();
                }
                return(dataBindingExpressionBuilder);
            }

            CompilationSection config = null;

            // If we are in the designer, we need to access IWebApplication config instead
#if !FEATURE_PAL // FEATURE_PAL does not support designer-based features
            if (host != null)
            {
                IWebApplication webapp = (IWebApplication)host.GetService(typeof(IWebApplication));
                if (webapp != null)
                {
                    config = webapp.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection;
                }
            }
#endif // !FEATURE_PAL

            // If we failed to get config from the designer, fall back on runtime config always
            if (config == null)
            {
                config = MTConfigUtil.GetCompilationConfig(virtualPath);
            }

            System.Web.Configuration.ExpressionBuilder builder = config.ExpressionBuilders[expressionPrefix];
            if (builder == null)
            {
                throw new HttpParseException(SR.GetString(SR.InvalidExpressionPrefix, expressionPrefix));
            }

            Type expressionBuilderType = null;
            if (host != null)
            {
                // If we are in the designer, we have to use the type resolution service
                ITypeResolutionService ts = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
                if (ts != null)
                {
                    expressionBuilderType = ts.GetType(builder.Type);
                }
            }
            if (expressionBuilderType == null)
            {
                expressionBuilderType = builder.TypeInternal;
            }
            Debug.Assert(expressionBuilderType != null, "expressionBuilderType should not be null");

            if (!typeof(ExpressionBuilder).IsAssignableFrom(expressionBuilderType))
            {
                throw new HttpParseException(SR.GetString(SR.ExpressionBuilder_InvalidType, expressionBuilderType.FullName));
            }
            ExpressionBuilder expressionBuilder = (ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(expressionBuilderType);

            return(expressionBuilder);
        }
        protected override object GetElementKey(ConfigurationElement element)
        {
            ExpressionBuilder eb = (ExpressionBuilder)element;

            return(eb.ExpressionPrefix);
        }
 public void Add(ExpressionBuilder buildProvider)
 {
     BaseAdd(buildProvider);
 }