public TableColumns(TableColumns colDefs) { _cols = new List<TableColumn>(); for (int i = 0; i < colDefs.Count; i++) { _cols.Add(new TableColumn(colDefs[i])); } buildColumnIndex(); }
public Table Load(Table selSeries, DateTime start, DateTime end, string filters, HashSet<string> refIds) { Stopwatch watch = Stopwatch.StartNew(); Dictionary<int, Dictionary<int, HashSet<int>>> loadSpecs = new Dictionary<int, Dictionary<int, HashSet<int>>>(); loadSpecs.Add(STORE_VALUE, new Dictionary<int, HashSet<int>>()); loadSpecs.Add(STORE_INST, new Dictionary<int, HashSet<int>>()); ElementType valueType = (ElementType) selSeries[0, selSeries.ColumnDefinitions.IndexOf("AttrDataType")].LongValue(); for (int i = 0; i < selSeries.Rows; i++) { int attrID = selSeries[i, selSeries.ColumnDefinitions.IndexOf("AttrID")].ToInt32(null); int logID = selSeries[i, selSeries.ColumnDefinitions.IndexOf("LogTypeID")].ToInt32(null); int storeType = selSeries[i, selSeries.ColumnDefinitions.IndexOf("StoreType")].ToInt32(null); if (!loadSpecs[storeType].ContainsKey(logID)) { loadSpecs[storeType].Add(logID, new HashSet<int>()); } loadSpecs[storeType][logID].Add(attrID); } //create the table schema List<TableColumn> s = new List<TableColumn>(); s.Add(new TableColumn("time", ElementType.DATETIME, false)); s.Add(new TableColumn("LogTypeID", ElementType.LONG, false)); s.Add(new TableColumn("ResID", ElementType.LONG, false)); s.Add(new TableColumn("AttrID", ElementType.LONG, false)); s.Add(new TableColumn("Context", ElementType.STRING, false)); s.Add(new TableColumn("value", valueType, false)); s.Add(new TableColumn("severity", ElementType.LONG, false)); TableColumns schema = new TableColumns(s); int numCols = schema.Count; foreach (string col in refIds) { if (schema.IndexOf(col) < 0) numCols++; } List<Element[]> rows = new List<Element[]>(); using (SqlConnection connection = new SqlConnection(this.GetConnectionString())) { connection.Open(); foreach (KeyValuePair<int, Dictionary<int, HashSet<int>>> ls in loadSpecs) { foreach (KeyValuePair<int, HashSet<int>> l in ls.Value) { string cmd = CreateQueryString(l.Key, l.Value, ls.Key, filters); using (SqlCommand command = new SqlCommand(cmd, connection)) { command.Parameters.AddWithValue("@startTime", start.ToUniversalTime()); command.Parameters.AddWithValue("@endTime", end.ToUniversalTime()); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { DateTime time = reader.GetDateTime(0); string context = reader.GetString(1); int resID = reader.GetInt32(2); try { int[] attrIDs = new int[l.Value.Count]; l.Value.CopyTo(attrIDs); for (int i = 0; i < attrIDs.Length; i++) { Element[] row = new Element[numCols]; row[0] = new Element(time); //time row[1] = new Element(l.Key); //log ID row[2] = new Element(resID); //resource ID row[3] = new Element(attrIDs[i]); //attribute ID row[4] = new Element(context); //context try { row[5] = GetCellValue(reader, VALUE_COL_START + i * 2, valueType); //value row[6] = new Element(reader.GetInt16(VALUE_COL_START + i * 2 + 1)); //severity } catch (Exception ex) { Trace.Write(ex); } rows.Add(row); } } catch (Exception ex) { Trace.WriteLine("Error: " + ex.Message); } } reader.Close(); } } } } Table data = new Table("$ATTR_DATA", schema, rows); watch.Stop(); Trace.WriteLine("MetricsDataLoader.Load : " + watch.ElapsedMilliseconds + "ms"); return data; }
public Table(string name, TableColumns cols, List<Element[]> rows) { this.Name = name; this.ColumnDefinitions = new TableColumns(cols); _rows = rows; }
public Table() { _colDefs = new TableColumns(); _rows = new List<Element[]>(); }