示例#1
0
        public CachedView GetView(string viewPath, string requestedPath, string area, object parameters = null)
        {
            parameters = parameters ?? new Dictionary <string, object>();
            Expander.ExpandView(viewPath, parameters, out string content);
            var cacheKey = GetCachedViewKey(requestedPath, area);

            if (!_parsedTemplateCache.TryGetValue(cacheKey, out CachedView cachedView) || cachedView.Raw != content)
            {
                if (cachedView == null)
                {
                    cachedView = new CachedView();
                    //save it for future
                    _parsedTemplateCache.TryAdd(cacheKey, cachedView);
                }
                try
                {
                    var template = Template.Parse(content);
                    cachedView.Template = template;
                    cachedView.Raw      = content;
                }
                catch (Exception ex)
                {
                    var newEx = new Exception($"Error occured while parsing file. File: {viewPath}", ex);
                    throw newEx;
                }
            }
            return(cachedView);
        }