public MetadataRepository(DataSet schema) { RuntimeID = Guid.NewGuid(); VersionNumber = 0; m_tablesLookup = new Dictionary <string, int>(); m_tables = new List <MetadataTable>(); m_isReadOnly = false; //-- Fill the schema //------------------------------------- foreach (DataTable table in schema.Tables) { var columns = new List <MetadataColumn>(); foreach (DataColumn c in table.Columns) { columns.Add(new MetadataColumn(c.ColumnName, SttpValueTypeCodec.FromType(c.DataType))); } m_tables.Add(new MetadataTable(table.TableName, columns)); m_tablesLookup[table.TableName] = m_tables.Count - 1; } MetadataSchema = new List <MetadataSchemaTable>(); foreach (var table in m_tables) { var t = new MetadataSchemaTable(); t.TableName = table.TableName; t.LastModifiedVersionNumber = table.LastModifiedVersionNumber; foreach (var col in table.Columns) { t.Columns.Add(col); } MetadataSchema.Add(t); } }
public DataTable ToTable() { DataTable tbl = new DataTable(); foreach (var column in Columns) { tbl.Columns.Add(column.Name, SttpValueTypeCodec.ToType(column.TypeCode)); } object[] list = new object[Columns.Count]; foreach (var row in Rows) { for (int x = 0; x < list.Length; x++) { list[x] = row[x].ToNativeType; } tbl.Rows.Add(list); } return(tbl); }
public MetadataTable MergeDataSets(DbDataReader table, long newSequenceNumber) { List <MetadataRow> newRows = new List <MetadataRow>(); int fieldCount = table.FieldCount; if (Columns.Count != fieldCount) { throw new Exception("Schema has changed, Cannot fill data set."); } for (var x = 0; x < fieldCount; x++) { if (Columns[x].Name != table.GetName(x)) { throw new Exception("Schema has changed, Cannot fill data set."); } if (Columns[x].TypeCode != SttpValueTypeCodec.FromType(table.GetFieldType(x))) { throw new Exception("Schema has changed, Cannot fill data set."); } } object[] row = new object[fieldCount]; while (table.Read()) { if (table.GetValues(row) != fieldCount) { throw new Exception("Field count did not match"); } List <CtpObject> values = new List <CtpObject>(); values.AddRange(row.Select(CtpObject.FromObject)); newRows.Add(new MetadataRow(values)); } return(new MetadataTable(this, newRows, newSequenceNumber)); }