private long RunStressTests(ITemplateCache templateCache)
        {
            long started = DateTime.Now.Ticks;

            string currentFolder = Path.GetDirectoryName(Environment.CurrentDirectory);
            string templatePath = Path.Combine(currentFolder, "../templates/hbmx/storefront.template.html");
            ImpressionEngine ie = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../templates/hbmx/contact.template.html");
            ie = ImpressionEngine.Create(templatePath, new PropertyBag());

            templatePath = Path.Combine(currentFolder, "../templates/hbmx/account.template.html");
            ie = ImpressionEngine.Create(templatePath, new PropertyBag());

            templatePath = Path.Combine(currentFolder, "../templates/hbmx/productlist-category.template.html");
            ie = ImpressionEngine.Create(templatePath, new PropertyBag());

            templatePath = Path.Combine(currentFolder, "../templates/hbmx/custompage.template.html");
            ie = ImpressionEngine.Create(templatePath, new PropertyBag());

            templatePath = Path.Combine(currentFolder, "../templates/hbmx/product.template.html");
            ie = ImpressionEngine.Create(templatePath, new PropertyBag());

            templatePath = Path.Combine(currentFolder, "../templates/hbmx/cart.template.html");
            ie = ImpressionEngine.Create(templatePath, new PropertyBag());

            templatePath = Path.Combine(currentFolder, "../templates/hbmx/yourinfo.template.html");
            ie = ImpressionEngine.Create(templatePath, new PropertyBag());

            templatePath = Path.Combine(currentFolder, "../templates/hbmx/payment.template.html");
            ie = ImpressionEngine.Create(templatePath, new PropertyBag());

            long elapsed = DateTime.Now.Ticks - started;
            return elapsed;
        }
Example #2
0
 public Template(string body, Dictionary<string, Type> globalsTypes, List<Assembly> referencedAssemblies)
 {
     _body = body;
     _globalsTypes = globalsTypes;
     _referencedAssemblies = referencedAssemblies;
     _templateCache = DefaultTemplateCache;
     Culture = CultureInfo.InvariantCulture;
 }
Example #3
0
 public Template(string body, Dictionary <string, Type> globalsTypes, List <Assembly> referencedAssemblies)
 {
     _body                 = body;
     _globalsTypes         = globalsTypes;
     _referencedAssemblies = referencedAssemblies;
     _templateCache        = DefaultTemplateCache;
     Culture               = CultureInfo.InvariantCulture;
 }
        public RazorTemplateEngine(RazorTemplateEngineConfiguration configuration)
        {
            Contract.Requires <ArgumentNullException>(configuration != null);

            _compiler         = configuration.CodeLanguage.GetCompiler();
            _cache            = configuration.CachePolicy.GetCache <Type>();
            _activator        = new TemplateActivator(configuration.TemplateFactory);
            _resourceProvider = configuration.ResourceProvider;
            _cacheExpiration  = configuration.CacheExpiration;
        }
        public static String GetOrAdd(this ITemplateCache cache, Expression <Func <HelperResult> > sourceFactory)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (sourceFactory == null)
            {
                throw new ArgumentNullException("sourceFactory");
            }

            var templateName = ExpressionHelper.GetMethodInfo(sourceFactory).Name;

            return(cache.GetOrAdd(templateName, (Func <String>)(() => sourceFactory.Compile()().ToString())));
        }
Example #6
0
        public ImpressionEngine(ITemplateParser templateParser, IReflector reflector, ITemplateCache templateCache)
        {
            if (templateParser == null)
            {
                throw new ArgumentNullException("templateParser");
            }
            if (reflector == null)
            {
                throw new ArgumentNullException("reflector");
            }

            // save a local pointer
            this.templateParser = templateParser;
            this.reflector      = reflector;
            this.templateCache  = templateCache;
        }
        public RazorTemplateEngine(IResourceProvider resourceProvider, ITemplateFactory templateFactory)
        {
            Contract.Requires <ArgumentNullException>(resourceProvider != null);
            Contract.Requires <ArgumentNullException>(templateFactory != null);

            var configuration = new RazorTemplateEngineConfiguration
            {
                ResourceProvider = resourceProvider,
                TemplateFactory  = templateFactory
            };

            _compiler         = configuration.CodeLanguage.GetCompiler();
            _cache            = configuration.CachePolicy.GetCache <Type>();
            _activator        = new TemplateActivator(configuration.TemplateFactory);
            _resourceProvider = configuration.ResourceProvider;
            _cacheExpiration  = configuration.CacheExpiration;
        }
Example #8
0
        public RazorMailMessageFactory(ITemplateResolver templateResolver, Type templateBase, Func <Type, object> dependencyResolver, ITemplateCache templateCache)
        {
            if (templateResolver == null)
            {
                throw new ArgumentNullException("templateResolver");
            }
            if (templateCache == null)
            {
                throw new ArgumentNullException("templateCache");
            }
            if (templateBase == null)
            {
                throw new ArgumentNullException("templateBase");
            }

            _templateResolver = templateResolver;
            _templateCache    = templateCache;

            var templateServiceConfiguration = new TemplateServiceConfiguration
            {
                // Layout resolver for razor engine
                // Once resolved, the layout will be cached by the razor engine, so the resolver is called only once during the lifetime of this factory
                // However, we want the ability to cache the layout even when the factory is instatiated multiple times
                Resolver = new DelegateTemplateResolver(layoutName =>
                {
                    var layout = _templateCache.Get(layoutName);

                    if (layout == null)
                    {
                        layout = _templateResolver.ResolveLayout(layoutName);
                        _templateCache.Add(layoutName, layout);
                    }
                    return(layout);
                }),

                // Set view base class
                BaseTemplateType = templateBase
            };

            if (dependencyResolver != null)
            {
                templateServiceConfiguration.Activator = new Activators.Activator(dependencyResolver);
            }

            _templateService = new TemplateService(templateServiceConfiguration);
        }
Example #9
0
        public static ImpressionEngine Create(string templatePath, IPropertyBag bag, ITemplateCache templateCache)
        {
            // create container and register it, in itself
            IContainer container = new Container();

            container.Register <IContainer>(delegate { return(container); });

            // singleton objects, only create once
            IReflector    reflector    = null;
            IFilterRunner filterRunner = null;
            ITagFactory   tagFactory   = null;

            container.Register <ITemplateCache>(delegate { return(templateCache); });
            container.Register <IReflector>(delegate { if (reflector == null)
                                                       {
                                                           reflector = new Reflector();
                                                       }
                                                       return(reflector); });
            container.Register <IFilterRunner>(delegate { if (filterRunner == null)
                                                          {
                                                              filterRunner = new FilterRunner();
                                                          }
                                                          return(filterRunner); });
            container.Register <ITagFactory>(delegate { if (tagFactory == null)
                                                        {
                                                            tagFactory = container.Resolve <TagFactory>();
                                                        }
                                                        return(tagFactory); });

            // instance scoped, create new each time
            container.Register <ITemplateParser, TemplateParser>();

            ImpressionEngine ie = container.Resolve <ImpressionEngine>();

            if (!string.IsNullOrEmpty(templatePath))
            {
                ie.LoadTemplate(templatePath, true);
            }

            if (bag != null)
            {
                ie.LoadBag(bag);
            }

            return(ie);
        }
        public static String GetOrAdd(this ITemplateCache cache, String templateName, Func <HelperResult> sourceFactory)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (templateName == null)
            {
                throw new ArgumentNullException("templateName");
            }
            if (sourceFactory == null)
            {
                throw new ArgumentNullException("sourceFactory");
            }

            return(cache.GetOrAdd(templateName, (Func <String>)(() => sourceFactory().ToString())));
        }
Example #11
0
        private long RunStressTests(ITemplateCache templateCache)
        {
            long started = DateTime.Now.Ticks;

            string           currentFolder = Path.GetDirectoryName(Environment.CurrentDirectory);
            string           templatePath  = Path.Combine(currentFolder, "../hbmx/storefront.template.html");
            ImpressionEngine ie            = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../hbmx/contact.template.html");
            ie           = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../hbmx/account.template.html");
            ie           = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../hbmx/productlist-category.template.html");
            ie           = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../hbmx/custompage.template.html");
            ie           = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../hbmx/product.template.html");
            ie           = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../hbmx/cart.template.html");
            ie           = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../hbmx/yourinfo.template.html");
            ie           = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            templatePath = Path.Combine(currentFolder, "../hbmx/payment.template.html");
            ie           = ImpressionEngine.Create(templatePath, new PropertyBag(), templateCache);

            long elapsed = DateTime.Now.Ticks - started;

            return(elapsed);
        }
Example #12
0
        public static ImpressionEngine Create(string templatePath, IPropertyBag bag, ITemplateCache templateCache)
        {
            // create container and register it, in itself
            IContainer container = new Container();
            container.Register<IContainer>(delegate { return container; });

            // singleton objects, only create once
            IReflector reflector = null;
            IFilterRunner filterRunner = null;
            ITagFactory tagFactory = null;

            container.Register<ITemplateCache>(delegate { return templateCache; });
            container.Register<IReflector>( delegate { if (reflector == null) reflector = new Reflector(); return reflector; } );
            container.Register<IFilterRunner>(delegate { if (filterRunner == null) filterRunner = new FilterRunner(); return filterRunner; });
            container.Register<ITagFactory>(delegate { if (tagFactory == null) tagFactory = container.Resolve<TagFactory>(); return tagFactory; });

            // instance scoped, create new each time
            container.Register<ITemplateParser, TemplateParser>();

            ImpressionEngine ie = container.Resolve<ImpressionEngine>();
            if (!string.IsNullOrEmpty(templatePath)) {
                ie.LoadTemplate(templatePath, true);
            }

            if (bag != null) {
                ie.LoadBag(bag);
            }

            return ie;
        }
Example #13
0
        public ImpressionEngine(ITemplateParser templateParser, IReflector reflector, ITemplateCache templateCache)
        {
            if (templateParser == null)
                throw new ArgumentNullException("templateParser");
            if (reflector == null)
                throw new ArgumentNullException("reflector");

            // save a local pointer
            this.templateParser = templateParser;
            this.reflector = reflector;
            this.templateCache = templateCache;
        }