static bool ProcessQuestionnaire(string prefix, ITemplater templater, Questionnaire q) { var tags = templater.Tags.ToArray(); foreach (var t in tags) if ((prefix + "title").Equals(t, StringComparison.CurrentCultureIgnoreCase)) templater.ReplaceAll(t, q.Title); templater.Resize(new[] { prefix + "Text", prefix + "Question", prefix + "Answer" }, q.Questions.Count); foreach (var ask in q.Questions) { templater.Replace(prefix + "Text", ask.Text); templater.Resize(new[] { prefix + "Answer", prefix + "Question" }, ask.Options.Length); for (int i = 0; i < ask.Options.Length; i++) { if (ask.SelectedOption == i) templater.Replace(prefix + "Answer", "\u2611"); else templater.Replace(prefix + "Answer", "\u2610"); templater.Replace(prefix + "Question", ask.Options[i]); } } return true; }
static bool ProcessQuestionnaire(string prefix, ITemplater templater, Questionnaire q) { var tags = templater.Tags.ToArray(); foreach (var t in tags) { if ((prefix + "title").Equals(t, StringComparison.CurrentCultureIgnoreCase)) { templater.ReplaceAll(t, q.Title); } } templater.Resize(new[] { prefix + "Text", prefix + "Question", prefix + "Answer" }, q.Questions.Count); foreach (var ask in q.Questions) { templater.Replace(prefix + "Text", ask.Text); templater.Resize(new[] { prefix + "Answer", prefix + "Question" }, ask.Options.Length); for (int i = 0; i < ask.Options.Length; i++) { if (ask.SelectedOption == i) { templater.Replace(prefix + "Answer", "\u2611"); } else { templater.Replace(prefix + "Answer", "\u2610"); } templater.Replace(prefix + "Question", ask.Options[i]); } } return(true); }
public Toolbox(ILogger <Toolbox> logger, IJustifier justifier, IVariableWidthJustifier varWidthJustifier, ITemplater templater) { _logger = logger; _justifier = justifier; _varWidthJustifier = varWidthJustifier; _templater = templater; CheckComponents(); }
public void SetTemplater(ITemplater templater) { if (templater == null) { throw new ArgumentNullException("templater"); } internalTemplater = templater; }
static bool CollapseNonEmpty(object value, string metadata, string property, ITemplater templater) { if (metadata == "collapseNonEmpty" || metadata == "collapseEmpty") { var dt = value as DataTable; if (dt == null) { return(false); } var isEmpty = dt.Rows.Count == 0; //loop until all tags with the same name are processed do { var md = templater.GetMetadata(property, false); var collapseOnEmpty = md.Contains("collapseEmpty"); var collapseNonEmpty = md.Contains("collapseNonEmpty"); if (isEmpty) { if (collapseOnEmpty) { templater.Resize(property, 0); } else { templater.Replace(property, ""); } } else { if (collapseNonEmpty) { templater.Resize(property, 0); } else { templater.Replace(property, ""); } } } while (templater.Tags.Contains(property)); return(true); } return(false); }
static bool Limit10Table(string prefix, ITemplater templater, DataTable table) { if (table.Rows.Count > 10) { //simplified way to match columns against tags var tags = table.Columns.Cast<DataColumn>().Select(it => prefix + it.ColumnName).ToList(); //if any of the found tags matches limit10 condition if (tags.Any(t => templater.GetMetadata(t, true).Contains("limit10"))) { templater.Resize(tags, 10); for (int i = 0; i < 10; i++) { DataRow r = table.Rows[i]; foreach (DataColumn c in table.Columns) templater.Replace(prefix + c.ColumnName, r[c]); } return true; } } return false; }
static bool TopNElementsProcessing(string prefix, ITemplater templater, IList list) { foreach (var t in templater.Tags) { //if any of the tag metadata contain limit(X), apply limit on the provided list var limit = templater.GetMetadata(t, true).FirstOrDefault(it => it.StartsWith("limit(")); if (limit != null) { int x = int.Parse(limit.Substring(6, limit.Length - 7)); //mutate the object in place... while this is not ideal, it's a convenient way to implement such requirement //alternative is to replicate Iterable processor features which is not trivial var size = list.Count - x; while (size-- > 0) { list.RemoveAt(x); } } } //say that we did not process object, so it's passed down to next processor (built-in) //which will process it with more complex logic return(false); }
static bool Limit10Table(string prefix, ITemplater templater, DataTable table) { if (table.Rows.Count > 10) { //simplified way to match columns against tags var tags = table.Columns.Cast <DataColumn>().Select(it => prefix + it.ColumnName).ToList(); //if any of the found tags matches limit10 condition if (tags.Any(t => templater.GetMetadata(t, true).Contains("limit10"))) { templater.Resize(tags, 10); for (int i = 0; i < 10; i++) { DataRow r = table.Rows[i]; foreach (DataColumn c in table.Columns) { templater.Replace(prefix + c.ColumnName, r[c]); } } return(true); } } return(false); }
static void RemoveTagsWithMissing(ITemplater templater) { foreach (var tag in templater.Tags.ToList()) { int i = 0; string[] md; //metadata will return null when a tag does not exist at that index while ((md = templater.GetMetadata(tag, i)) != null) { var missing = md.FirstOrDefault(it => it.StartsWith("missing(")); if (missing != null) { var description = missing.Substring(8, missing.Length - 9); //Replace tag at specific index, not just the first tag templater.Replace(tag, i, description); } else { i++; } } } }
public PdfRenderer(ITemplater templater, IPdfer pdfer, ILogger <PdfRenderer> logger) { _templater = templater; _pdfer = pdfer; _logger = logger; }
public EmailRenderer(ITemplater templater, IEmailer mailer) { _templater = templater; _mailer = mailer; }
/// <summary> /// Creates an instance of the SMS renderer class. /// </summary> /// <param name="smsMessagingGateway">An instance of a SMSer.</param> /// <param name="templater">An instance of a templater.</param> public SmsRenderer(ISmser smsMessagingGateway, ITemplater templater) { _smsMessagingGateway = smsMessagingGateway; _templater = templater; }
//for this example position is ignored as it is always -1 static bool CollapseNonEmpty(object value, string metadata, string tag, int position, ITemplater templater) { var dt = value as DataTable; if (dt != null && (metadata == "collapseNonEmpty" || metadata == "collapseEmpty")) { var isEmpty = dt.Rows.Count == 0; //loop until all tags with the same name are processed do { var md = templater.GetMetadata(tag, false); var collapseOnEmpty = md.Contains("collapseEmpty"); var collapseNonEmpty = md.Contains("collapseNonEmpty"); if (isEmpty) { if (collapseOnEmpty) { //when position is -1 it means non sharing tag is being used, in which case we can resize that region via "standard" API //otherwise we need to use "advanced" resize API to specify which exact tag to replace if (position == -1) { templater.Resize(new[] { tag }, 0); } else { templater.Resize(new[] { new TagPosition(tag, position) }, 0); } } else { //when position is -1 it means non sharing tag is being used, in which case we can just replace the first tag //otherwise we can replace that exact tag via position API //replacing the first tag is the same as calling replace(tag, 0, value) if (position == -1) { templater.Replace(tag, ""); } else { templater.Replace(tag, position, ""); } } } else { if (collapseNonEmpty) { if (position == -1) { templater.Resize(new[] { tag }, 0); } else { templater.Resize(new[] { new TagPosition(tag, position) }, 0); } } else { if (position == -1) { templater.Replace(tag, ""); } else { templater.Replace(tag, position, ""); } } } } while (templater.Tags.Contains(tag)); return(true); } return(false); }
public void SetTemplater(ITemplater templater) { if (templater == null) throw new ArgumentNullException("templater"); internalTemplater = templater; }