public static AppMetadata Deserialize(BinaryReader stream, FastAccessList <object> referenceTracking = null) { var cTables = new AppMetadata(); var nbServers = stream.ReadInt32(); for (var n = 0; n < nbServers; n++) { var serverId = stream.ReadInt16(); cTables.Add(serverId, new ServerMetadata()); var nbDatabases = stream.ReadInt32(); for (var j = 0; j < nbDatabases; j++) { var database = stream.ReadString(); cTables[serverId].Add(database, new DatabaseMetadata()); var nbSchemas = stream.ReadInt32(); for (var k = 0; k < nbSchemas; k++) { var schemaMetadata = new SchemaMetadata(); var schema = stream.ReadString(); var nbTablesFrom = stream.ReadInt32(); for (var l = 0; l < nbTablesFrom; l++) { TableMetadata table = null; if (referenceTracking == null) { table = TableMetadata.Deserialize(stream); } else { var id = stream.ReadInt32(); table = (TableMetadata)referenceTracking[id]; } schemaMetadata.Add(table); } cTables[serverId][database].Add(schema, schemaMetadata); } } } return(cTables); }
/// <summary> /// Load the result of an Sql query into the metadatas object. /// </summary> /// <param name="reader">Result of an Sql query defined in <see cref="MetadataProvider.SqlGetColumns"/></param> /// <param name="metadata">Metadatas container</param> /// <param name="serverId">ServerId loaded from</param> /// <param name="database">Database loaded from</param> /// <param name="typeConverter">Classe performing type conversion between database and .NET.</param> internal static void LoadColumns(IDataReader reader, Metadatas metadata, string serverId, string database, ISqlTypeConverter typeConverter) { var schemaMetadata = new SchemaMetadata(); var lstSchemaColumn = new List <ColumnDefinition>(); string currentSchema; if (!reader.Read()) { return; } //Init first row var previousSchema = reader.GetString(0); var previousTable = new TableMetadata(reader.GetString(1)); //Pour chaque ligne do { currentSchema = reader.GetString(0); var currentTable = reader.GetString(1); //Si on change de table if (currentSchema != previousSchema || currentTable != previousTable.Name) { previousTable.ColumnsDefinition = lstSchemaColumn; schemaMetadata.Add(previousTable); lstSchemaColumn = new List <ColumnDefinition>(); previousTable = new TableMetadata(currentTable); } //Si on change de schema if (currentSchema != previousSchema) { metadata[serverId, database, currentSchema] = schemaMetadata; schemaMetadata = new SchemaMetadata(); } //Ajoute la colonne var col = new ColumnDefinition { Name = reader.GetString(2), SqlType = new SqlType { DataType = reader.GetString(3), Precision = reader.GetInt32(4), Scale = reader.GetInt32(5), IsUnsigned = reader.GetBoolean(6) }, IsPrimary = reader.GetBoolean(7), IsAutoIncrement = reader.GetBoolean(8) }; col.DbType = typeConverter.ConvertFromSql(col.SqlType); lstSchemaColumn.Add(col); } while (reader.Read()); //Ajoute la dernière table / schema if (lstSchemaColumn.Count > 0) { previousTable.ColumnsDefinition = lstSchemaColumn; schemaMetadata.Add(previousTable); metadata[serverId, database, currentSchema] = schemaMetadata; } }