public ActionResult Add() { try { // Lettura parametri tramite cast di tipi GetTemplateObject PostDataArrived = CS.GetPostData <GetTemplateObject>(this.Request); // Lettura connection string ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"]; // Check sulla connection string if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString)) { throw new Exception("ConnectionString not set"); } // Inizializzazione Service dei template TemplateWidget qw = new TemplateWidget(connectionStringSetting.ConnectionString); // Ritorna Json al client con il risultato della chiamata TemplateWidget.Add(GetTemplateObject arg) return(CS.ReturnForJQuery(qw.Add(PostDataArrived))); } catch (Exception ex) { // Ritorna Json al client con messaggio di errore return(CS.ReturnForJQuery(ex.Message)); } }
public ActionResult GetTemplateList() { try { GetTemplateObject PostDataArrived = CS.GetPostData <GetTemplateObject>(this.Request); ConnectionStringSettings connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"]; if (connectionStringSetting == null || string.IsNullOrEmpty(connectionStringSetting.ConnectionString)) { throw new Exception("ConnectionString not set"); } TemplateWidget qw = new TemplateWidget(connectionStringSetting.ConnectionString); return(CS.ReturnForJQuery(qw.Get(PostDataArrived))); } catch (Exception ex) { return(CS.ReturnForJQuery(ex.Message)); } }
/// <summary> /// 获取模块的Html /// </summary> /// <param name="url">模块所在的Url地址</param> /// <param name="path">模块的路径</param> /// <param name="args">模块的参数</param> /// <returns></returns> public virtual string GetWidgetHtml(string url, string path, IDictionary <string, object> args) { // 获取模块的Html之前首先要获取到所在Url的TemplateResult, 模块有可能需要用到返回的变量 var uri = new Uri(url); var pageManager = Application.Ioc.Resolve <VisualPageManager>(); var templateResult = pageManager.GetPageResult(uri.PathAndQuery) as TemplateResult; // 过滤空参数, 无参数时应该等于null args = args.Where(x => x.Value != null && x.Value as string != "") .ToDictionary(x => x.Key, x => x.Value); if (args.Count == 0) { args = null; } // 获取模块的Html // 通过渲染器获取避免读取和写入区域管理器的缓存 var templateManager = Application.Ioc.Resolve <TemplateManager>(); var renderer = Application.Ioc.Resolve <ITemplateWidgetRenderer>(); var context = new DotLiquid.Context(); var widget = new TemplateWidget(path, args); if (templateResult?.TemplateArgument != null) { var arguments = templateResult.TemplateArgument; context.Push(templateManager.CreateHash(arguments)); } var widgetHtml = renderer.Render(context, widget); return(widgetHtml); }
/// <summary> /// 根据单个模块参数添加表单字段 /// </summary> public void AddFormField( FormBuilder form, TemplateWidget widget, IDictionary <string, object> argument) { throw new NotImplementedException(); }
public void GetCacheKey() { var widget = new TemplateWidget("__test"); Assert.Equals(widget.GetCacheKey(), "__test"); widget = new TemplateWidget("__test", new { a = 1 }); Assert.Equals(widget.GetCacheKey(), "__test{\"a\":1}"); }
/// <summary> /// Get cache key for template widget /// </summary> /// <param name="widget">Template widget</param> /// <returns></returns> public static string GetCacheKey(this TemplateWidget widget) { var cacheKey = widget.Path; var argsJson = widget.ArgsJson; if (argsJson != null) { cacheKey += argsJson; } return(cacheKey); }
/// <summary> /// 获取后Html /// </summary> protected override string GetAfterHtml(Context context, TemplateWidget widget) { var firstScope = context.Scopes[0]; var html = "</div>"; var afterHtml = firstScope[AfterHtmlKey] as string; if (!string.IsNullOrEmpty(afterHtml)) { html += afterHtml; } return(html); }
/// <summary> /// 获取前Html /// </summary> protected override string GetBeforeHtml(Context context, TemplateWidget widget) { var firstScope = context.Scopes[0]; var cacheKey = widget.GetCacheKey(); var cssClass = HttpUtils.HtmlEncode(firstScope[CssClassKey]); var style = HttpUtils.HtmlEncode(firstScope[InlineCssKey]); var html = $"<div class='template_widget {cssClass}' data-widget='{cacheKey}' style='{style}'>"; var beforeHtml = firstScope[BeforeHtmlKey] as string; if (!string.IsNullOrEmpty(beforeHtml)) { html += beforeHtml; } return(html); }