public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { var model = GetModel(scopeArgs); var memberExprEnumerator = GetMemberExprEnumerator(model); if (IsNested) { //Write Markdown foreach (var item in memberExprEnumerator) { scopeArgs[this.EnumeratorName] = item; base.Write(instance, textWriter, scopeArgs); } } else { //Buffer Markdown output before converting and writing HTML var sw = StringWriterCacheAlt.Allocate(); foreach (var item in memberExprEnumerator) { scopeArgs[this.EnumeratorName] = item; base.Write(instance, sw, scopeArgs); } var markdown = StringWriterCacheAlt.ReturnAndFree(sw); var renderedMarkup = Transform(markdown); textWriter.Write(renderedMarkup); } }
public void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { foreach (var block in Blocks) { block.Write(instance, textWriter, scopeArgs); } }
//TODO: DRY IT protected void WriteElseStatement(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { if (IsNested) { //Write Markdown foreach (var templateBlock in ElseChildBlocks) { templateBlock.Write(instance, textWriter, scopeArgs); } } else { //Buffer Markdown output before converting and writing HTML var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { foreach (var templateBlock in ElseChildBlocks) { templateBlock.Write(instance, sw, scopeArgs); } } var markdown = sb.ToString(); var html = Transform(markdown); textWriter.Write(html); } }
public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { var paramValues = GetParamValues(scopeArgs); var result = Evaluator.Evaluate(instance, CodeGenMethodName, paramValues.ToArray()); if (result == null) { return; } string strResult; var mvcString = result as MvcHtmlString; if (mvcString != null) { WriteRawHtml = true; strResult = mvcString.ToHtmlString(); } else { strResult = result as string ?? Convert.ToString(result); } if (!WriteRawHtml) { strResult = HttpUtility.HtmlEncode(strResult); } textWriter.Write(strResult); }
private void WriteInternal(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { foreach (var templateBlock in ChildBlocks) { templateBlock.Write(instance, textWriter, scopeArgs); } }
public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { //Resolve and add to ScopeArgs var resultCondition = Evaluate <object>(scopeArgs, true); scopeArgs[varName] = resultCondition; }
public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { var model = GetModel(scopeArgs); var memberExprEnumerator = GetMemberExprEnumerator(model); if (IsNested) { //Write Markdown foreach (var item in memberExprEnumerator) { scopeArgs[this.EnumeratorName] = item; base.Write(instance, textWriter, scopeArgs); } } else { //Buffer Markdown output before converting and writing HTML var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { foreach (var item in memberExprEnumerator) { scopeArgs[this.EnumeratorName] = item; base.Write(instance, sw, scopeArgs); } } var markdown = sb.ToString(); var renderedMarkup = Transform(markdown); textWriter.Write(renderedMarkup); } }
public void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { lock (readWriteLock) { while (isBusy) { Monitor.Wait(readWriteLock); } } if (TextBlocks == null || VarRefBlocks == null) { throw new InvalidDataException("Template has not been Initialized."); } for (var i = 0; i < TextBlocks.Length; i++) { var textBlock = TextBlocks[i]; var varName = VarRefBlocks[i]; if (varName != null) { object varValue; if (scopeArgs.TryGetValue(varName, out varValue)) { textWriter.Write(varValue); } } textWriter.Write(textBlock); } }
/// <summary>Writes the specified instance.</summary> /// /// <param name="instance"> The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs"> The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { object value = null; scopeArgs.TryGetValue(varName, out value); if (value == null) return; textWriter.Write(value); }
/// <summary>Writes the specified instance.</summary> /// /// <param name="instance"> The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs"> The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { //Don't output anything, capture all output and store it in scopeArgs[SectionName] var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { base.Write(instance, sw, scopeArgs); } var markdown = sb.ToString(); var renderedMarkup = Transform(markdown); scopeArgs[SectionName] = MvcHtmlString.Create(renderedMarkup); }
public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { object value = null; scopeArgs.TryGetValue(varName, out value); if (value == null) { return; } textWriter.Write(value); }
public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { //Don't output anything, capture all output and store it in scopeArgs[SectionName] var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { base.Write(instance, sw, scopeArgs); } var markdown = sb.ToString(); var renderedMarkup = Transform(markdown); scopeArgs[SectionName] = MvcHtmlString.Create(renderedMarkup); }
/// <summary>Writes the specified instance.</summary> /// /// <param name="instance"> The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs"> The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { var resultCondition = Evaluate<bool>(scopeArgs); if (resultCondition) { WriteStatement(instance, textWriter, scopeArgs); } else { if (ElseStatement != null && this.ElseChildBlocks.Length > 0) { WriteElseStatement(instance, textWriter, scopeArgs); } } }
public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { var resultCondition = Evaluate <bool>(scopeArgs); if (resultCondition) { WriteStatement(instance, textWriter, scopeArgs); } else { if (ElseStatement != null && this.ElseChildBlocks.Length > 0) { WriteElseStatement(instance, textWriter, scopeArgs); } } }
public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { object memberExprValue; if (!scopeArgs.TryGetValue(this.varName, out memberExprValue)) { if (staticValueFn != null) { var strValue = this.staticValueFn(); textWriter.Write(PclExportClient.Instance.HtmlEncode(strValue)); } else { textWriter.Write(this.memberExpr); } return; } if (memberExprValue == null) { return; } try { if (memberExprValue is MvcHtmlString) { textWriter.Write(memberExprValue); return; } if (valueFn == null) { InitializeValueFn(memberExprValue); } var strValue = this.ReferencesSelf ? Convert.ToString(memberExprValue) : valueFn(memberExprValue); textWriter.Write(PclExportClient.Instance.HtmlEncode(strValue)); } catch (Exception ex) { Log.Error("MemberExprBlock: " + ex.Message, ex); } }
protected void WriteStatement(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { if (IsNested) { //Write Markdown WriteInternal(instance, textWriter, scopeArgs); } else { //Buffer Markdown output before converting and writing HTML var sw = StringWriterCacheAlt.Allocate(); WriteInternal(instance, sw, scopeArgs); var markdown = StringWriterCacheAlt.ReturnAndFree(sw); var html = Transform(markdown); textWriter.Write(html); } }
/// <summary>Writes the specified instance.</summary> /// /// <param name="instance"> The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs"> The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { object memberExprValue; if (!scopeArgs.TryGetValue(this.varName, out memberExprValue)) { if (staticValueFn != null) { var strValue = this.staticValueFn(); textWriter.Write(HttpUtility.HtmlEncode(strValue)); } else { textWriter.Write(this.memberExpr); } return; } if (memberExprValue == null) return; try { if (memberExprValue is MvcHtmlString) { textWriter.Write(memberExprValue); return; } if (valueFn == null) { InitializeValueFn(memberExprValue); } var strValue = this.ReferencesSelf ? Convert.ToString(memberExprValue) : valueFn(memberExprValue); textWriter.Write(HttpUtility.HtmlEncode(strValue)); } catch (Exception ex) { Log.Error("MemberExprBlock: " + ex.Message, ex); } }
/// <summary> /// Writes the specified instance. /// </summary> /// <param name="instance">The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs">The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { var paramValues = GetParamValues(scopeArgs); var result = Evaluator.Evaluate(instance, CodeGenMethodName, paramValues.ToArray()); if (result == null) return; string strResult; var mvcString = result as MvcHtmlString; if (mvcString != null) { WriteRawHtml = true; strResult = mvcString.ToHtmlString(); } else { strResult = result as string ?? Convert.ToString(result); } if (!WriteRawHtml) strResult = HttpUtility.HtmlEncode(strResult); textWriter.Write(strResult); }
/// <summary>Writes the specified instance.</summary> /// /// <param name="instance"> The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs"> The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { var model = GetModel(scopeArgs); var memberExprEnumerator = GetMemberExprEnumerator(model); if (IsNested) { //Write Markdown foreach (var item in memberExprEnumerator) { scopeArgs[this.EnumeratorName] = item; base.Write(instance, textWriter, scopeArgs); } } else { //Buffer Markdown output before converting and writing HTML var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { foreach (var item in memberExprEnumerator) { scopeArgs[this.EnumeratorName] = item; base.Write(instance, sw, scopeArgs); } } var markdown = sb.ToString(); var renderedMarkup = Transform(markdown); textWriter.Write(renderedMarkup); } }
/// <summary>Writes the specified instance.</summary> /// /// <param name="instance"> The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs"> The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { WriteInternal(instance, textWriter, scopeArgs); }
public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs) { }
private void WriteInternal(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { foreach (var templateBlock in ChildBlocks) { templateBlock.Write(instance, textWriter, scopeArgs); } }
/// <summary> /// Writes the statement. /// </summary> /// <param name="instance">The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs">The scope arguments.</param> protected void WriteStatement(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { if (IsNested) { //Write Markdown WriteInternal(instance, textWriter, scopeArgs); } else { //Buffer Markdown output before converting and writing HTML var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { WriteInternal(instance, sw, scopeArgs); } var markdown = sb.ToString(); var html = Transform(markdown); textWriter.Write(html); } }
public abstract void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary <string, object> scopeArgs);
/// <summary>Writes the specified instance.</summary> /// /// <param name="instance"> The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs"> The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { textWriter.Write(Content); }
public void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { lock (readWriteLock) { while (isBusy) Monitor.Wait(readWriteLock); } if (TextBlocks == null || VarRefBlocks == null) throw new InvalidDataException("Template has not been Initialized."); for (var i = 0; i < TextBlocks.Length; i++) { var textBlock = TextBlocks[i]; var varName = VarRefBlocks[i]; if (varName != null) { object varValue; if (scopeArgs.TryGetValue(varName, out varValue)) { textWriter.Write(varValue); } } textWriter.Write(textBlock); } }
/// <summary>Writes the specified instance.</summary> /// /// <param name="instance"> The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs"> The scope arguments.</param> public override void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { //Resolve and add to ScopeArgs var resultCondition = Evaluate<object>(scopeArgs, true); scopeArgs[varName] = resultCondition; }
/// <summary> /// Writes the else statement. /// </summary> /// <param name="instance">The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs">The scope arguments.</param> protected void WriteElseStatement(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs) { //TODO: DRY IT if (IsNested) { //Write Markdown foreach (var templateBlock in ElseChildBlocks) { templateBlock.Write(instance, textWriter, scopeArgs); } } else { //Buffer Markdown output before converting and writing HTML var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { foreach (var templateBlock in ElseChildBlocks) { templateBlock.Write(instance, sw, scopeArgs); } } var markdown = sb.ToString(); var html = Transform(markdown); textWriter.Write(html); } }
public void Write(TextWriter textWriter, PageContext pageContext) { if (textWriter == null) { throw new ArgumentNullException("textWriter"); } if (pageContext == null) { pageContext = new PageContext(this, new Dictionary <string, object>(), true); } var blocks = pageContext.RenderHtml ? this.HtmlBlocks : this.MarkdownBlocks; if (Interlocked.Increment(ref timesRun) == 1) { lock (readWriteLock) { try { isBusy = true; this.ExecutionContext.BaseType = Markdown.MarkdownBaseType; this.ExecutionContext.TypeProperties = Markdown.MarkdownGlobalHelpers; pageContext.MarkdownPage = this; var initHtmlContext = pageContext.Create(this, true); var initMarkdownContext = pageContext.Create(this, false); foreach (var block in this.HtmlBlocks) { lastBlockProcessed = block; block.DoFirstRun(initHtmlContext); } foreach (var block in this.MarkdownBlocks) { lastBlockProcessed = block; block.DoFirstRun(initMarkdownContext); } this.evaluator = this.ExecutionContext.Build(); foreach (var block in this.HtmlBlocks) { lastBlockProcessed = block; block.AfterFirstRun(evaluator); } foreach (var block in this.MarkdownBlocks) { lastBlockProcessed = block; block.AfterFirstRun(evaluator); } AddDependentPages(blocks); lastBlockProcessed = null; initException = null; hasCompletedFirstRun = true; } catch (Exception ex) { initException = ex; throw; } finally { isBusy = false; } } } lock (readWriteLock) { while (isBusy) { Monitor.Wait(readWriteLock); } } if (initException != null) { timesRun = 0; throw initException; } MarkdownViewBase instance = null; if (this.evaluator != null) { instance = (MarkdownViewBase)this.evaluator.CreateInstance(); object model; pageContext.ScopeArgs.TryGetValue(ModelName, out model); instance.Init(Markdown.AppHost, this, pageContext.ScopeArgs, model, pageContext.RenderHtml); instance.ViewEngine = Markdown; } foreach (var block in blocks) { block.Write(instance, textWriter, pageContext.ScopeArgs); } if (instance != null) { instance.OnLoad(); } }
/// <summary> /// Writes the specified instance. /// </summary> /// <param name="instance">The instance.</param> /// <param name="textWriter">The text writer.</param> /// <param name="scopeArgs">The scope arguments.</param> public abstract void Write(MarkdownViewBase instance, TextWriter textWriter, Dictionary<string, object> scopeArgs);