private void AddNewColumnsInfo(List <DictionaryEntry> group, int i, GridColumnInfoArgs initCellInfo) { var cellInfo = new GridColumnInfoArgs(initCellInfo.Column); cellInfo.Assign(initCellInfo); cellInfo.Tag = group[i].Key as GridGroupSummaryItem; cellInfo.Info.StartRow = i; ColumnsInfo.Add(cellInfo); }
private void RemoveColumnsInfo() { var count = ColumnsInfo.OfType <GridColumnInfoArgs>().Where(ci => ci.Tag == null).Count(); while (ColumnsInfo.Count > count) { ColumnsInfo.RemoveAt(count); } }
/// <summary> /// Gets the column ordinal, given the name of the column. /// </summary> public int GetOrdinal(string name) { var keyValuePair = ColumnsInfo.FirstOrDefault(pair => pair.Value.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (keyValuePair.Value != null) { return(keyValuePair.Value.Ordinal); } throw new IndexOutOfRangeException(name); }
private void RemoveColumnsInfo() { var count = GetCount(); if (count < 0) { return; } while (ColumnsInfo.Count > count) { ColumnsInfo.RemoveAt(count); } }
//private void ComputeTableSize() //{ //} public override string ToString() { var rowHeadersWidth = RowsInfo.Max(r => r.Header.Length); var colHeadersWidth = ColumnsInfo.Max(c => c.Header.Length); var maxItemWidth = Math.Max(rowHeadersWidth, colHeadersWidth); for (var c = 0; c < Columns; c++) { for (var r = 0; r < Rows; r++) { var item = Items[r, c]; if (!string.IsNullOrEmpty(item) && maxItemWidth < item.Length) { maxItemWidth = item.Length; } } } var composer = new LinearTextComposer(); //Add column headers composer.Append(FormatItem("", maxItemWidth)); for (var c = 0; c < Columns; c++) { composer.Append(FormatItem(ColumnsInfo[c].Header, maxItemWidth)); } composer.AppendLine(); //Add rows for (var r = 0; r < Rows; r++) { composer.Append(FormatItem(RowsInfo[r].Header, maxItemWidth)); for (var c = 0; c < Columns; c++) { composer.Append(FormatItem(Items[r, c], maxItemWidth)); } composer.AppendLine(); } return(composer.ToString()); }
private IEnumerable <Vars> getTransformedRowsInternal(ColumnsInfo ci, ParsingReader csvReader) { int rowNo = 0; string quote = Context.TransformStr(Quote, Transform); string separator = Context.TransformStr(Separator, Transform); char? quoteChar = string.IsNullOrEmpty(quote) ? (char?)null : quote[0]; bool trim = (Options & RowsetOptions.Trim) != 0; // Read the rest of CSV, if available if (csvReader != null) { // If there are no columns, treat data as the list of strings if (ci.Count == 0) { string s; while ((s = csvReader.ReadLine()) != null) { if ((Options & RowsetOptions.Trim) == RowsetOptions.Trim) { s = s.Trim(); } if (string.IsNullOrEmpty(s) && (Options & RowsetOptions.IgnoreEmpty) == RowsetOptions.IgnoreEmpty) { continue; } Vars r = new Vars(); r[string.Empty] = s; Context.CheckAbort(); yield return(r); } } else { // We have columns, and therefore a complete CSV string[] data; while ((data = Utils.ReadCsvRow(csvReader, quoteChar, separator[0], trim)) != null) { if ((Options & RowsetOptions.IgnoreEmpty) != 0 && (data.Length == 0 || (data.Length == 1 && data[0].Length == 0))) { continue; } rowNo++; if (data.Length > ci.Count) { throw new ScriptRuntimeException(string.Format("{0} columns expected in row #{1}, but {2} found.", ci.Count, rowNo, data.Length)); } Vars r = new Vars(); for (int i = 0; i < Math.Min(ci.Count, data.Length); ++i) { object o = Context.Transform(data[i], Verbatim ? TransformRules.None : Transform); if (i < ci.Count) { r[ci[i].Name] = ci[i].AdjustType(o); } else { r[ci[i].Name] = o; } } ci.ApplyDefaults(r); Context.CheckAbort(); var c = checkWhere(r); if (c == null) { yield break; } if (c.Value) { yield return(r); } } } } // Rowset ID string id = Context.TransformStr(RowsetId, Transform); if (!string.IsNullOrEmpty(id)) { var rs = Context.Find <RowSet>(id, true); foreach (var v in rs.GetData()) { rowNo++; Vars sv1 = null; if (ci.Count == 0) { sv1 = v; } else { sv1 = new Vars(); Context.ExecuteWithVars(() => { foreach (var col in ci) { sv1.Set(col.Name, col.AdjustType(v.GetOrDefault(col.Name, null))); } return(null); }, v, null); } ci.ApplyDefaults(sv1); Context.CheckAbort(); var c = checkWhere(sv1); if (c == null) { yield break; } if (c.Value) { yield return(sv1); } } } // Try XmlDoc id = Context.TransformStr(XmlDocId, Transform); if (!string.IsNullOrEmpty(id)) { XmlDoc doc = Context.Find <XmlDoc>(id, true); foreach (XmlNode n in doc.Nodes(Context.TransformStr(XPath, Transform))) { Vars sv = new Vars(); rowNo++; if (ci.Count > 0) { foreach (var col in ci) { var node = n.SelectSingleNode(col.Value); if (node != null) { sv[col.Name] = col.AdjustType(node.Value); } } } else { foreach (XmlAttribute attr in n.Attributes) { sv[attr.LocalName] = attr.Value; } sv[string.Empty] = n.InnerText; } ci.ApplyDefaults(sv); Context.CheckAbort(); var c = checkWhere(sv); if (c == null) { yield break; } if (c.Value) { yield return(sv); } } } foreach (var row in Rows) { rowNo++; Vars sv = new Vars(); foreach (Var v in row) { var val = (Verbatim) ? v.Value : Context.Transform(v.Value, Transform); sv.Set(v.Name, ci.AdjustType(v.Name, val)); } ci.ApplyDefaults(sv); Context.CheckAbort(); var c = checkWhere(sv); if (c == null) { yield break; } if (c.Value) { yield return(sv); } } }
private IEnumerable <Vars> getTransformedRows(string columnsOverride, string sortOverride, string whereExpression) { bool overrideSort = (sortOverride != null); if (!overrideSort) { sortOverride = Context.TransformStr(SortColumns, Transform); } // ColumnsInfo ci = new ColumnsInfo(); // Load CSV, if present string text = GetTransformedValueStr(); string quote = Context.TransformStr(Quote, Transform); string separator = Context.TransformStr(Separator, Transform); char? quoteChar = string.IsNullOrEmpty(quote) ? (char?)null : quote[0]; bool trim = (Options & RowsetOptions.Trim) != 0; string colNames = Context.TransformStr(Columns, Transform);; // Read additional column names from the first CSV row, if specified ParsingReader csvReader = null; if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text.Trim())) { csvReader = new ParsingReader(new StringReader(text)); if ((Options & RowsetOptions.Header) == RowsetOptions.Header) { csvReader.SkipWhiteSpace(); colNames = Context.TransformStr(csvReader.ReadLine(), Verbatim ? TransformRules.None : Transform); } } char sep = string.IsNullOrEmpty(separator) ? '\0' : separator[0]; // Add these columns if (!string.IsNullOrEmpty(colNames)) { ci.AddParsed(Context, colNames, quoteChar, sep, trim); } // Add extra columns if (Cols != null) { foreach (var col in Cols) { ColumnInfo cc = new ColumnInfo(); cc.Name = Context.TransformStr(col.Name, col.Transform); cc.Value = Context.TransformStr(col.Value, col.Transform); cc.IsDefault = (col.Default != null); if (cc.IsDefault) { cc.Default = Context.Transform(col.Default, col.Transform); } object t = Context.Transform(col.Type, col.Transform); if (t != null) { if (t is Type) { cc.Type = (Type)t; } else { cc.Type = Context.FindType(t.ToString()); } } ci.Add(cc); } } SortInfos si = new SortInfos(sortOverride, quoteChar, sep, trim); if (!overrideSort && SortCols != null) { foreach (var col in SortCols) { var ss = new SortInfo { Name = Context.TransformStr(col.Name, col.Transform), Sort = col.Sort }; var cmp = Context.Transform(col.Comparer, Transform); if (cmp != null) { object c1 = null; if (cmp is Type) { ss.Comparer = (IComparer)Utils.CreateInstance((Type)cmp); } else if (cmp is string && !string.IsNullOrEmpty((string)cmp)) { string smp = (string)cmp; if (smp.ToUpperInvariant() == "IGNORECASE" || smp.ToUpperInvariant() == "NOCASE" || smp.ToUpperInvariant() == "IC") { ss.Comparer = StringComparer.CurrentCultureIgnoreCase; } else if (Utils.TryGetProperty(null, typeof(StringComparer), smp, null, false, out c1)) { ss.Comparer = (IComparer)c1; } else { ss.Comparer = (IComparer)Utils.CreateInstance(Context.FindType(smp)); } } else { ss.Comparer = (IComparer)cmp; } } si.Add(ss); } } var ret = si.SortAndFilter(Context, columnsOverride, whereExpression, getTransformedRowsInternal(ci, csvReader)); if (columnsOverride == null) { return(ret); } ci = new ColumnsInfo(); ci.AddParsed(Context, columnsOverride, quoteChar, separator[0], trim); return(ci.Process(ret)); }
public JsonResult GetColumnsNames() { ColumnsInfo columnsInfo = new ColumnsInfo(_unitOfWork); return(columnsInfo.GetColumnsNames()); }