Esempio n. 1
0
        public async Task <ITemplatePage> CompileTemplateAsync(string key)
        {
            TemplateCacheItem item = CacheManager.GetItem("TemplatePage", key,
                                                          Compiler, FactoryProvider).Convert <TemplateCacheItem>();
            Func <ITemplatePage> templateFactory = item.TemplatePageFactory;

            ITemplatePage templatePage = templateFactory();

            templatePage.DisableEncoding = Options.DisableEncoding;
            return(templatePage);
            //if (IsCachingEnabled)
            //{
            //    var cacheLookupResult = Cache.RetrieveTemplate(key);
            //    if (cacheLookupResult.Success)
            //    {
            //        return cacheLookupResult.Template.TemplatePageFactory();
            //    }
            //}

            //CompiledTemplateDescriptor templateDescriptor = await Compiler.CompileAsync(key);
            //Func<ITemplatePage> templateFactory = FactoryProvider.CreateFactory(templateDescriptor);

            //if (IsCachingEnabled)
            //{
            //    Cache.CacheTemplate(
            //        key,
            //        templateFactory,
            //        templateDescriptor.ExpirationToken);
            //}

            //return templateFactory();
        }
        public override object Create(string key, params object[] args)
        {
            var compiler        = ObjectUtil.QueryObject <IRazorTemplateCompiler>(args);
            var factoryProvider = ObjectUtil.QueryObject <ITemplateFactoryProvider>(args);

            CompiledTemplateDescriptor templateDescriptor =
                Task.Run(async() => await compiler.CompileAsync(key)).GetAwaiter().GetResult();
            Func <ITemplatePage> templateFactory = factoryProvider.CreateFactory(templateDescriptor);

            TemplateCacheItem item = new TemplateCacheItem(key, templateFactory, templateDescriptor.ExpirationToken);

            return(item);
        }