/// <summary> /// update configuration object with tables desc from server database /// </summary> private async Task ReadConfigurationAsync(SyncConfiguration syncConfiguration) { if (syncConfiguration == null || syncConfiguration.Count() == 0) { throw new ArgumentNullException("syncConfiguration", "Configuration should contains Tables, at least tables with a name"); } DbConnection connection = null; DbTransaction transaction; try { using (connection = this.CreateConnection()) { await connection.OpenAsync(); using (transaction = connection.BeginTransaction()) { foreach (var dmTable in syncConfiguration) { var builderTable = this.GetDbManager(dmTable.TableName); var tblManager = builderTable.CreateManagerTable(connection, transaction); tblManager.TableName = dmTable.TableName; // get columns list var lstColumns = tblManager.GetTableDefinition(); // Validate the column list and get the dmTable configuration object. this.ValidateTableFromColumns(dmTable, lstColumns, tblManager); var relations = tblManager.GetTableRelations(); if (relations != null) { foreach (var r in relations) { DmColumn tblColumn = dmTable.Columns[r.ColumnName]; DmColumn foreignColumn = null; var foreignTable = syncConfiguration[r.ReferenceTableName]; // Since we can have a table with a foreign key but not the parent table // It's not a problem, just forget it if (foreignTable == null) { continue; } foreignColumn = foreignTable.Columns[r.ReferenceColumnName]; if (foreignColumn == null) { throw new NotSupportedException( $"Foreign column {r.ReferenceColumnName} does not exist in table {r.TableName}"); } DmRelation dmRelation = new DmRelation(r.ForeignKey, tblColumn, foreignColumn); syncConfiguration.ScopeSet.Relations.Add(dmRelation); } } } transaction.Commit(); } connection.Close(); } } catch (Exception ex) { throw new SyncException(ex, SyncStage.ConfigurationApplying, this.ProviderTypeName); } finally { if (connection != null && connection.State != ConnectionState.Closed) { connection.Close(); } } }
/// <summary> /// update configuration object with tables desc from server database /// </summary> public async Task ReadConfigurationAsync(SyncConfiguration configuration) { if (configuration == null || configuration.Count() == 0) { throw new SyncException("Configuration should contains Tables, at least tables with a name", SyncStage.ConfigurationApplying, SyncExceptionType.Argument); } DbConnection connection; DbTransaction transaction; using (connection = this.CreateConnection()) { try { await connection.OpenAsync(); using (transaction = connection.BeginTransaction()) { foreach (var dmTable in configuration) { var builderTable = this.GetDbManager(dmTable.TableName); var tblManager = builderTable.GetManagerTable(connection, transaction); // get columns list var lstColumns = tblManager.GetTableDefinition(); // Validate the column list and get the dmTable configuration object. this.ValidateTableFromColumnsList(dmTable, lstColumns, tblManager); var relations = tblManager.GetTableRelations(); if (relations != null) { foreach (var r in relations) { DmColumn tblColumn = dmTable.Columns[r.ColumnName]; DmColumn foreignColumn = null; var foreignTable = configuration[r.ReferenceTableName]; // Since we can have a table with a foreign key but not the parent table // It's not a problem, just forget it if (foreignTable == null) { continue; } foreignColumn = foreignTable.Columns[r.ReferenceColumnName]; if (foreignColumn == null) { throw new SyncException($"Foreign column {r.ReferenceColumnName} does not exist in table {r.TableName}", SyncStage.ConfigurationApplying, SyncExceptionType.DataStore); } DmRelation dmRelation = new DmRelation(r.ForeignKey, tblColumn, foreignColumn); configuration.ScopeSet.Relations.Add(dmRelation); } } } transaction.Commit(); } connection.Close(); } catch (Exception ex) { Debug.WriteLine($"Error during building BuildConfiguration : {ex.Message}"); throw; } finally { if (connection.State != ConnectionState.Closed) { connection.Close(); } } } }