protected static async Task <string> ParseElementAsync(IParseManager parseManager, ListInfo listInfo, List <KeyValuePair <int, Dictionary <string, object> > > dataSource) { var pageInfo = parseManager.PageInfo; if (dataSource == null || dataSource.Count == 0) { return(string.Empty); } var builder = new StringBuilder(); if (listInfo.Layout == Layout.None) { if (!string.IsNullOrEmpty(listInfo.HeaderTemplate)) { builder.Append(listInfo.HeaderTemplate); } var isAlternative = false; var isSeparator = false; if (!string.IsNullOrEmpty(listInfo.AlternatingItemTemplate)) { isAlternative = true; } if (!string.IsNullOrEmpty(listInfo.SeparatorTemplate)) { isSeparator = true; } for (var i = 0; i < dataSource.Count; i++) { var dict = dataSource[i]; pageInfo.SqlItems.Push(dict); var templateString = isAlternative && i % 2 == 1 ? listInfo.AlternatingItemTemplate : listInfo.ItemTemplate; builder.Append(await TemplateUtility.GetSqlContentsTemplateStringAsync(templateString, listInfo.SelectedItems, listInfo.SelectedValues, string.Empty, parseManager, ParseType.SqlContent)); if (isSeparator && i != dataSource.Count - 1) { builder.Append(listInfo.SeparatorTemplate); } } if (!string.IsNullOrEmpty(listInfo.FooterTemplate)) { builder.Append(listInfo.FooterTemplate); } } else { var isAlternative = !string.IsNullOrEmpty(listInfo.AlternatingItemTemplate); var tableAttributes = listInfo.GetTableAttributes(); var cellAttributes = listInfo.GetCellAttributes(); using (var table = new HtmlTable(builder, tableAttributes)) { if (!string.IsNullOrEmpty(listInfo.HeaderTemplate)) { table.StartHead(); using (var tHead = table.AddRow()) { tHead.AddCell(listInfo.HeaderTemplate, cellAttributes); } table.EndHead(); } table.StartBody(); var columns = listInfo.Columns <= 1 ? 1 : listInfo.Columns; var itemIndex = 0; while (true) { using var tr = table.AddRow(); for (var cell = 1; cell <= columns; cell++) { var cellHtml = string.Empty; if (itemIndex < dataSource.Count) { var dict = dataSource[itemIndex]; pageInfo.SqlItems.Push(dict); var templateString = isAlternative && itemIndex % 2 == 1 ? listInfo.AlternatingItemTemplate : listInfo.ItemTemplate; cellHtml = await TemplateUtility.GetSqlContentsTemplateStringAsync(templateString, listInfo.SelectedItems, listInfo.SelectedValues, string.Empty, parseManager, ParseType.SqlContent); } tr.AddCell(cellHtml, cellAttributes); itemIndex++; } if (itemIndex >= dataSource.Count) { break; } } table.EndBody(); if (!string.IsNullOrEmpty(listInfo.FooterTemplate)) { table.StartFoot(); using (var tFoot = table.AddRow()) { tFoot.AddCell(listInfo.FooterTemplate, cellAttributes); } table.EndFoot(); } } } return(builder.ToString()); }
private static async Task <string> ParseImplAsync(IParseManager parseManager, ListInfo listInfo) { var pageInfo = parseManager.PageInfo; var type = listInfo.Others.Get(Type); if (string.IsNullOrEmpty(type)) { type = nameof(Content.ImageUrl); } var valueList = new List <string>(); var content = await parseManager.GetContentAsync(); if (content != null) { if (!string.IsNullOrEmpty(content.Get <string>(type))) { valueList.Add(content.Get <string>(type)); } var countName = ColumnsManager.GetCountName(type); var total = content.Get <int>(countName); for (var i = 1; i <= total; i++) { var extendName = ColumnsManager.GetExtendName(type, i); var extend = content.Get <string>(extendName); valueList.Add(extend); } //var extendAttributeName = ColumnsManager.GetExtendAttributeName(type); //var extendValues = content.Get<string>(extendAttributeName); //if (!string.IsNullOrEmpty(extendValues)) //{ // foreach (var extendValue in ListUtils.GetStringList(extendValues)) // { // valueList.Add(extendValue); // } //} if (listInfo.StartNum > 1 || listInfo.TotalNum > 0) { if (listInfo.StartNum > 1) { var count = listInfo.StartNum - 1; if (count > valueList.Count) { count = valueList.Count; } valueList.RemoveRange(0, count); } if (listInfo.TotalNum > 0) { if (listInfo.TotalNum < valueList.Count) { valueList.RemoveRange(listInfo.TotalNum, valueList.Count - listInfo.TotalNum); } } } } if (valueList.Count == 0) { return(string.Empty); } var eachList = new List <KeyValuePair <int, object> >(); var index = 0; foreach (string value in valueList) { eachList.Add(new KeyValuePair <int, object>(index++, value)); } var builder = new StringBuilder(); if (listInfo.Layout == Layout.None) { if (!string.IsNullOrEmpty(listInfo.HeaderTemplate)) { builder.Append(listInfo.HeaderTemplate); } var isAlternative = false; var isSeparator = false; if (!string.IsNullOrEmpty(listInfo.AlternatingItemTemplate)) { isAlternative = true; } if (!string.IsNullOrEmpty(listInfo.SeparatorTemplate)) { isSeparator = true; } for (var i = 0; i < eachList.Count; i++) { var each = eachList[i]; pageInfo.EachItems.Push(each); var templateString = isAlternative && i % 2 == 1 ? listInfo.AlternatingItemTemplate : listInfo.ItemTemplate; builder.Append(await TemplateUtility.GetEachsTemplateStringAsync(templateString, listInfo.SelectedItems, listInfo.SelectedValues, string.Empty, parseManager, ParseType.Each)); if (isSeparator && i != eachList.Count - 1) { builder.Append(listInfo.SeparatorTemplate); } } if (!string.IsNullOrEmpty(listInfo.FooterTemplate)) { builder.Append(listInfo.FooterTemplate); } } else { var isAlternative = !string.IsNullOrEmpty(listInfo.AlternatingItemTemplate); var tableAttributes = listInfo.GetTableAttributes(); var cellAttributes = listInfo.GetCellAttributes(); using var table = new HtmlTable(builder, tableAttributes); if (!string.IsNullOrEmpty(listInfo.HeaderTemplate)) { table.StartHead(); using (var tHead = table.AddRow()) { tHead.AddCell(listInfo.HeaderTemplate, cellAttributes); } table.EndHead(); } table.StartBody(); var columns = listInfo.Columns <= 1 ? 1 : listInfo.Columns; var itemIndex = 0; while (true) { using var tr = table.AddRow(); for (var cell = 1; cell <= columns; cell++) { var cellHtml = string.Empty; if (itemIndex < eachList.Count) { var each = eachList[itemIndex]; pageInfo.EachItems.Push(each); var templateString = isAlternative && itemIndex % 2 == 1 ? listInfo.AlternatingItemTemplate : listInfo.ItemTemplate; cellHtml = await TemplateUtility.GetEachsTemplateStringAsync(templateString, listInfo.SelectedItems, listInfo.SelectedValues, string.Empty, parseManager, ParseType.Each); } tr.AddCell(cellHtml, cellAttributes); itemIndex++; } if (itemIndex >= eachList.Count) { break; } } table.EndBody(); if (!string.IsNullOrEmpty(listInfo.FooterTemplate)) { table.StartFoot(); using (var tFoot = table.AddRow()) { tFoot.AddCell(listInfo.FooterTemplate, cellAttributes); } table.EndFoot(); } } return(builder.ToString()); }
private void AddSeperators(HtmlTableRowGroup rowGroup, HtmlTable left, HtmlTable right, HtmlTable edge) { // Unchanged seperator left.AddBody("Seperator Base"); right.AddBody("Seperator Diff"); edge.AddBody("Seperator Diff"); var startLine = rowGroup.Lines.Count > 0 ? rowGroup.Lines.First() : GetEmptyLine(); var endLine = rowGroup.Lines.Count > 0 ? rowGroup.Lines.Last() : GetEmptyLine(); left.AddBodySeperator(startLine.Left.LineNum, startLine.Left.Id, string.Format("Lines {0} to {1}", startLine.Left.LineNumber, endLine.Left.LineNumber)); right.AddBodySeperator(startLine.Right.LineNum, startLine.Right.Id, string.Format("Lines {0} to {1}", startLine.Right.LineNumber, endLine.Right.LineNumber)); edge.AddEdgeSeperator(startLine.Right.LineNum, startLine.Right.Id); left.EndBody(); right.EndBody(); edge.EndBody(); }
private IEnumerable<string> EncodeRowGroups(List<HtmlTableRowGroup> rowGroups, string baseHeader, string diffHeader, string leftIdPrefix, string rightIdPrefix, string edgePrefix) { var left = new HtmlTable(leftIdPrefix, leftIdPrefix, "LeftTable"); var right = new HtmlTable(rightIdPrefix, rightIdPrefix, "RightTable"); var edge = new HtmlTable(edgePrefix, edgePrefix, "EdgeTable"); left.AddDiffHeader(); right.AddDiffHeader(); foreach (var rowGroup in rowGroups) { left.AddBody(rowGroup.Class + " Base"); right.AddBody(rowGroup.Class + " Diff"); edge.AddBody(rowGroup.Class + " Diff"); foreach (var line in rowGroup.Lines) { var id = line.Left.Id + "-" + line.Right.Id; left.AddCodeLine(line.Left.LineNumber, id, line.Left.Code); right.AddCodeLine(line.Right.LineNumber, id, line.Right.Code); edge.AddEdgeLine(line.Right.LineNumber, id); } left.EndBody(); right.EndBody(); edge.EndBody(); // Add Seperator line after every unchanged if (rowGroup.DiffType == DiffType.Unchanged) AddSeperators(rowGroup, left, right, edge); } left.End(); right.End(); edge.End(); var testMode = false; var containerTable = new HtmlTable("", "DiffView", "DiffTable", testMode); containerTable.AddContainerHeader("ContainerTable", baseHeader, diffHeader); containerTable.AddTables(left, right, edge); containerTable.End(testMode); return containerTable.Html; }
private static async Task <string> ParseElementAsync(IParseManager parseManager, ListInfo listInfo, List <KeyValuePair <int, Site> > sites) { var pageInfo = parseManager.PageInfo; var contextInfo = parseManager.ContextInfo; if (sites == null || sites.Count == 0) { return(string.Empty); } var builder = new StringBuilder(); if (listInfo.Layout == Layout.None) { if (!string.IsNullOrEmpty(listInfo.HeaderTemplate)) { builder.Append(listInfo.HeaderTemplate); } var isAlternative = false; var isSeparator = false; if (!string.IsNullOrEmpty(listInfo.AlternatingItemTemplate)) { isAlternative = true; } if (!string.IsNullOrEmpty(listInfo.SeparatorTemplate)) { isSeparator = true; } for (var i = 0; i < sites.Count; i++) { var site = sites[i]; pageInfo.SiteItems.Push(site); var templateString = isAlternative ? listInfo.AlternatingItemTemplate : listInfo.ItemTemplate; var parsedString = await TemplateUtility.GetSitesTemplateStringAsync(templateString, string.Empty, parseManager, ParseType.Site); builder.Append(parsedString); if (isSeparator && i != sites.Count - 1) { builder.Append(listInfo.SeparatorTemplate); } } if (!string.IsNullOrEmpty(listInfo.FooterTemplate)) { builder.Append(listInfo.FooterTemplate); } } else { var isAlternative = !string.IsNullOrEmpty(listInfo.AlternatingItemTemplate); var tableAttributes = listInfo.GetTableAttributes(); var cellAttributes = listInfo.GetCellAttributes(); using var table = new HtmlTable(builder, tableAttributes); if (!string.IsNullOrEmpty(listInfo.HeaderTemplate)) { table.StartHead(); using (var tHead = table.AddRow()) { tHead.AddCell(listInfo.HeaderTemplate, cellAttributes); } table.EndHead(); } table.StartBody(); var columns = listInfo.Columns <= 1 ? 1 : listInfo.Columns; var itemIndex = 0; while (true) { using var tr = table.AddRow(null); for (var cell = 1; cell <= columns; cell++) { var cellHtml = string.Empty; if (itemIndex < sites.Count) { var site = sites[itemIndex]; pageInfo.SiteItems.Push(site); var templateString = isAlternative ? listInfo.AlternatingItemTemplate : listInfo.ItemTemplate; cellHtml = await TemplateUtility.GetSitesTemplateStringAsync(templateString, string.Empty, parseManager, ParseType.Site); } tr.AddCell(cellHtml, cellAttributes); itemIndex++; } if (itemIndex >= sites.Count) { break; } } table.EndBody(); if (!string.IsNullOrEmpty(listInfo.FooterTemplate)) { table.StartFoot(); using (var tFoot = table.AddRow()) { tFoot.AddCell(listInfo.FooterTemplate, cellAttributes); } table.EndFoot(); } } return(builder.ToString()); }