public async Task<Type> GetModelTypeFromTemplateAsync(TemplateInfo templateInfo)
        {
            var hash = string.Concat("template_", templateInfo.Id);
            CacheEntry entry;

            JSchema schema;
            int hashCode;
            if (_cacheProvider.TryGet(hash, out entry))
            {
                if (entry.ETag.Equals(templateInfo.ETag, StringComparison.Ordinal))
                    return entry.Result;

                schema = await _schemaProvider.GetSchemaFromTemplateAsync(templateInfo).ConfigureAwait(false);
                hashCode = schema.ToString().GetHashCode();

                if (entry.SchemaHash == hashCode)
                    return entry.Result;
            }
            else
            {
                schema = await _schemaProvider.GetSchemaFromTemplateAsync(templateInfo).ConfigureAwait(false);
                hashCode = schema.ToString().GetHashCode();                
            }

            var result = _generator.Compile(schema);
            _cacheProvider.Set(hash, new CacheEntry { Result = result, SchemaHash = hashCode, ETag = templateInfo.ETag }, DateTimeOffset.Now.AddHours(24));

            return result;
        }
		private static string GetSkinName(TemplateInfo templateInfo)
		{
			var parts = templateInfo.Id.Split('-');
			if (parts.Length > 1)
				return parts[parts.Length - 1];

			return string.Empty;
		}
        public Task<JSchema> GetSchemaFromTemplateAsync(TemplateInfo template)
        {
            var hash = string.Concat("template_", template.Id, template.ETag);

            Task<JSchema> schema;
            if (_cacheProvider.TryGet(hash, out schema))
                return schema;

            var result = _adaptee.GetSchemaFromTemplateAsync(template);
            _cacheProvider.Set(hash, result, DateTimeOffset.Now.AddHours(24));

            return result;
        }
        public async Task<Type> GetModelTypeFromTemplateAsync(TemplateInfo templateInfo)
        {
            var schema = await _schemaProvider.GetSchemaFromTemplateAsync(templateInfo).ConfigureAwait(false);
            var typeName = string.Format("{0}.{1}.{2},{3}", _rootNamespace, _namingRule.GetNamespaceName(schema), _namingRule.GetClassName(schema, string.Empty), _assemblyName);

            try
            {
                return Type.GetType(typeName, true);
            }
            catch (TypeLoadException)
            {
                return null;
            }
        }
Beispiel #5
0
        private async Task <ViewEngineResult> GetViewResult(string controllerName, string viewName)
        {
            TemplateInfo templateInfo     = null;
            var          moduleDefinition = await _moduleRepository.GetModuleDefinitionByIdAsync(viewName).ConfigureAwait(false);

            if (moduleDefinition == null)
            {
                moduleDefinition = await _moduleRepository.GetModuleDefinitionByIdAsync(controllerName).ConfigureAwait(false);
            }

            if (moduleDefinition != null)
            {
                templateInfo = moduleDefinition.DefaultTemplate;
            }

            if (templateInfo == null)
            {
                templateInfo = await _templateRepository.GetTemplateAsync(viewName).ConfigureAwait(false);
            }

            if (templateInfo == null)
            {
                templateInfo = await _templateRepository.GetTemplateAsync(controllerName).ConfigureAwait(false);
            }

            if (templateInfo != null)
            {
                var modelType = await _modelTypeProvider.GetModelTypeFromTemplateAsync(templateInfo).ConfigureAwait(false);

                if (modelType == null)
                {
                    modelType = typeof(object);
                }

                var view = await _viewEngine.CreateViewAsync(templateInfo, modelType).ConfigureAwait(false);

                if (view != null)
                {
                    return(new ViewEngineResult(new TerrificViewAdapter(CreateAdapter(view), ResolveContext), this));
                }
            }

            return(new ViewEngineResult(new[] { viewName, controllerName }));
        }
Beispiel #6
0
        private static TemplateItemModel GetView(string section, TemplateInfo m)
        {
            var schemaUrl = string.Format("/{0}schema/{1}", section, m.Id);
            var templateUrl = string.Format("/{0}{1}", section, m.Id);
            var templateId = m.Id;

            return new TemplateItemModel
            {
                Text = m.Id,
                Url = string.Format("/web/module?id={0}&app={1}", m.Id, section),
                SchemaUrl = schemaUrl
            };
        }
Beispiel #7
0
 public static Task<IView> CreateViewAsync(this IViewEngine viewEngine, TemplateInfo templateInfo)
 {
     return viewEngine.CreateViewAsync(templateInfo, typeof (object));
 }
			public Task<Type> GetModelTypeFromTemplateAsync(TemplateInfo templateInfo)
			{
				return Task.FromResult<Type>(typeof(object));
			}
Beispiel #9
0
 public ModuleDefinition(string id, TemplateInfo defaultTemplate, IReadOnlyDictionary<string, TemplateInfo> skins)
 {
     Id = id;
     DefaultTemplate = defaultTemplate;
     Skins = skins;
 }
Beispiel #10
0
 public static Task <IView> CreateViewAsync(this IViewEngine viewEngine, TemplateInfo templateInfo)
 {
     return(viewEngine.CreateViewAsync(templateInfo, typeof(object)));
 }
 public ModuleDefinition(string id, TemplateInfo defaultTemplate, IReadOnlyDictionary <string, TemplateInfo> skins)
 {
     Id = id;
     DefaultTemplate = defaultTemplate;
     Skins           = skins;
 }