예제 #1
0
        /// <summary>
        /// Applies a default configuration.
        /// </summary>
        private static void ConfigureDefault()
        {
            CompilerServiceFactory = new DefaultCompilerServiceFactory();
            var service = CompilerServiceFactory.CreateCompilerService();

            DefaultTemplateService = new TemplateService(service);
        }
        public TemplateServiceConfiguration()
        {
            Activator = new DefaultActivator();
            CompilerServiceFactory = new DefaultCompilerServiceFactory();
            EncodedStringFactory   = new HtmlEncodedStringFactory();

#if !RAZOR4
#pragma warning disable 0618 // Backwards Compat.
            CodeInspectors = new List <ICodeInspector>();
#pragma warning restore 0618 // Backwards Compat.
#endif

            ReferenceResolver = new UseCurrentAssembliesReferenceResolver();
            CachingProvider   = new DefaultCachingProvider();
            TemplateManager   =
                new DelegateTemplateManager();

            Namespaces = new HashSet <string>
            {
                "System",
                "System.Collections.Generic",
                "System.Linq"
            };

            var config = RazorEngineConfigurationSection.GetConfiguration();
            Language = (config == null)
                           ? Language.CSharp
                           : config.DefaultLanguage;
        }
        public TemplateServiceConfiguration()
        {
            Activator = new DefaultActivator();
            CompilerServiceFactory = new DefaultCompilerServiceFactory();
            EncodedStringFactory = new HtmlEncodedStringFactory();
            
#if !RAZOR4
#pragma warning disable 0618 // Backwards Compat.
            CodeInspectors = new List<ICodeInspector>();
#pragma warning restore 0618 // Backwards Compat.
#endif

            ReferenceResolver = new UseCurrentAssembliesReferenceResolver();
            CachingProvider = new DefaultCachingProvider();
            TemplateManager =
                new DelegateTemplateManager();

            Namespaces = new HashSet<string>
                             {
                                 "System", 
                                 "System.Collections.Generic", 
                                 "System.Linq"
                             };
            
            var config = RazorEngineConfigurationSection.GetConfiguration();
            Language = (config == null)
                           ? Language.CSharp
                           : config.DefaultLanguage;
        }
예제 #4
0
        /// <summary>
        /// Configures the templating engine.
        /// </summary>
        private static void Configure()
        {
            var config = RazorEngineConfigurationSection.GetConfiguration();

            if (config != null)
            {
                if (!string.IsNullOrWhiteSpace(config.Factory))
                {
                    SetCompilerServiceFactory(config.Factory);
                }
                else
                {
                    CompilerServiceFactory = new DefaultCompilerServiceFactory();
                }

                if (config.TemplateServices.Count > 0)
                {
                    string @default = string.IsNullOrWhiteSpace(config.TemplateServices.Default)
                                          ? null
                                          : config.TemplateServices.Default;

                    foreach (TemplateServiceConfigurationElement serviceConfig in config.TemplateServices)
                    {
                        string name    = serviceConfig.Name;
                        var    service = ConfigurationServices.CreateTemplateService(serviceConfig);;
                        ConfigurationServices.AddNamespaces(service, config.Namespaces);

                        if (name == @default)
                        {
                            DefaultTemplateService = service;
                        }

                        Services.Add(name, service);
                    }
                }

                if (DefaultTemplateService == null)
                {
                    DefaultTemplateService = new TemplateService(CompilerServiceFactory.CreateCompilerService());
                    ConfigurationServices.AddNamespaces(DefaultTemplateService, config.Namespaces);
                }

                if (!string.IsNullOrWhiteSpace(config.Activator))
                {
                    DefaultTemplateService.SetActivator(ConfigurationServices.CreateInstance <IActivator>(config.Activator));
                }
            }
            else
            {
                ConfigureDefault();
            }
        }
        /// <summary>
        /// Initialises a new instance of <see cref="DefaultTemplateServiceConfiguration"/>.
        /// </summary>
        public DefaultTemplateServiceConfiguration()
        {
            Activator = new DefaultActivator();
            CompilerServiceFactory = new DefaultCompilerServiceFactory();
            EncodedStringFactory = new HtmlEncodedStringFactory();

            Namespaces = new HashSet<string>
                             {
                                 "System",
                                 "System.Collections.Generic",
                                 "System.Linq"
                             };

            var config = RazorEngineConfigurationSection.GetConfiguration();
            Language = (config == null)
                           ? Language.CSharp
                           : config.DefaultLanguage;
        }
예제 #6
0
        /// <summary>
        /// Initialises a new instance of <see cref="TemplateServiceConfiguration"/>.
        /// </summary>
        public TemplateServiceConfiguration()
        {
            Activator = new DefaultActivator();
            CompilerServiceFactory = new DefaultCompilerServiceFactory();
            EncodedStringFactory   = new HtmlEncodedStringFactory();
            CodeInspectors         = new List <ICodeInspector>();

            Namespaces = new HashSet <string>
            {
                "System",
                "System.Collections.Generic",
                "System.Linq"
            };

            var config = RazorEngineConfigurationSection.GetConfiguration();

            Language = (config == null)
                           ? Language.CSharp
                           : config.DefaultLanguage;
        }
        public RazorViewServiceConfiguration(Registration <IRazorViewLoader> razorViewLoaderRegistration)
        {
            if (razorViewLoaderRegistration == null)
            {
                throw new ArgumentNullException(nameof(razorViewLoaderRegistration));
            }

            RazorViewLoader        = razorViewLoaderRegistration;
            CompilerServiceFactory = new DefaultCompilerServiceFactory();
            EncodedStringFactory   = new HtmlEncodedStringFactory();
            CachingProvider        = new DefaultCachingProvider();
            Namespaces             = new HashSet <string>()
            {
                "System",
                "System.Collections.Generic",
                "System.Linq"
            };
            RazorEngineConfigurationSection configuration = RazorEngineConfigurationSection.GetConfiguration();

            Language = configuration?.DefaultLanguage ?? Language.CSharp;
        }
예제 #8
0
파일: Razor.cs 프로젝트: dbshell/dbshell
        /// <summary>
        /// Configures the templating engine.
        /// </summary>
        private static void Configure()
        {
            var config = RazorEngineConfigurationSection.GetConfiguration();
            if (config != null)
            {
                if (!string.IsNullOrWhiteSpace(config.Factory))
                    SetCompilerServiceFactory(config.Factory);
                else
                    CompilerServiceFactory = new DefaultCompilerServiceFactory();

                if (config.TemplateServices.Count > 0)
                {
                    string @default = string.IsNullOrWhiteSpace(config.TemplateServices.Default)
                                          ? null
                                          : config.TemplateServices.Default;

                    foreach (TemplateServiceConfigurationElement serviceConfig in config.TemplateServices)
                    {
                        string name = serviceConfig.Name;
                        var service = ConfigurationServices.CreateTemplateService(serviceConfig);;
                        ConfigurationServices.AddNamespaces(service, config.Namespaces);

                        if (name == @default)
                            DefaultTemplateService = service;

                        Services.Add(name, service);
                    }
                }

                if (DefaultTemplateService == null)
                    DefaultTemplateService = new TemplateService(CompilerServiceFactory.CreateCompilerService());

                if (!string.IsNullOrWhiteSpace(config.Activator))
                    DefaultTemplateService.SetActivator(ConfigurationServices.CreateInstance<IActivator>(config.Activator));
            }
            else
            {
                ConfigureDefault();
            }
        }
예제 #9
0
파일: Razor.cs 프로젝트: dbshell/dbshell
        /// <summary>
        /// Applies a default configuration.
        /// </summary>
        private static void ConfigureDefault()
        {
            CompilerServiceFactory = new DefaultCompilerServiceFactory();
            var service = CompilerServiceFactory.CreateCompilerService();

            DefaultTemplateService = new TemplateService(service);
        }