Example #1
0
        public async Task <IView> CreateViewAsync(TemplateInfo templateInfo, Type modelType)
        {
            if (templateInfo == null)
            {
                return(null);
            }

            var hash = string.Concat("template_", templateInfo.Id, templateInfo.ETag, modelType.FullName);

            IView view;

            if (!_cacheProvider.TryGet(hash, out view))
            {
                string content;
                using (var reader = new StreamReader(templateInfo.Open()))
                {
                    content = await reader.ReadToEndAsync().ConfigureAwait(false);
                }

                var helperHandlers = _helperHandlerFactory.Create().ToArray();
                var viewEngine     = new VeilEngine(helperHandlers, _memberLocator);
                if (modelType == typeof(object))
                {
                    view = CreateNonGenericView(templateInfo.Id, content, viewEngine);
                }
                else
                {
                    view = (IView)typeof(VeilViewEngine).GetMethod("CreateView", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(modelType).Invoke(null, new object[] { templateInfo.Id, content, viewEngine });
                }

                _cacheProvider.Set(hash, view, DateTimeOffset.Now.AddHours(24));
            }

            return(view);
        }
 public void Generate(TemplateInfo templateInfo, IClientContext clientContext, IClientModel clientModel)
 {
     using (var stream = new StreamReader(templateInfo.Open()))
     {
         GenerateForTemplate(templateInfo.Id, stream.ReadToEnd(), clientContext, clientModel);
     }
 }
        public Task<JSchema> GetSchemaFromTemplateAsync(TemplateInfo template)
        {
            var extractor = new SchemaExtractor(new HandlebarsParser());
            var helperHandlers = _helperHandlerFactory != null ? _helperHandlerFactory.Create().ToArray() : null;

            // TODO: Use async
            var schema = extractor.Run(template.Id, new StreamReader(template.Open()), _memberLocator, helperHandlers);
            if (schema != null && string.IsNullOrEmpty(schema.Title))
                schema.Title = string.Concat(template.Id, "Model");

            return Task.FromResult(schema);
        }
Example #4
0
        public Task <JSchema> GetSchemaFromTemplateAsync(TemplateInfo template)
        {
            var extractor      = new SchemaExtractor(new HandlebarsParser());
            var helperHandlers = _helperHandlerFactory != null?_helperHandlerFactory.Create().ToArray() : null;

            // TODO: Use async
            var schema = extractor.Run(template.Id, new StreamReader(template.Open()), _memberLocator, helperHandlers);

            if (schema != null && string.IsNullOrEmpty(schema.Title))
            {
                schema.Title = string.Concat(template.Id, "Model");
            }

            return(Task.FromResult(schema));
        }