private void DoBackupModule(IDataWriteOperator writer, DbFactory dbFactory, IModuleSpecifics module) { Logger.Debug("begin saving data for module {0}", module.ModuleName); var tablesToProcess = module.Tables.Where(t => !IgnoredTables.Contains(t.Name) && t.InsertMethod != InsertMethod.None).ToList(); int tablesCount = tablesToProcess.Count; int tablesProcessed = 0; using (var connection = dbFactory.OpenConnection()) { foreach (var table in tablesToProcess) { Logger.Debug("begin load table {0}", table.Name); using (var data = new DataTable(table.Name)) { ActionInvoker.Try( state => { data.Clear(); var t = (TableInfo)state; var dataAdapter = dbFactory.CreateDataAdapter(); dataAdapter.SelectCommand = module.CreateSelectCommand(connection.Fix(), TenantId, t).WithTimeout(600); ((DbDataAdapter)dataAdapter).Fill(data); }, table, maxAttempts: 5, onFailure: error => { throw ThrowHelper.CantBackupTable(table.Name, error); }, onAttemptFailure: error => Logger.Warn("backup attempt failure: {0}", error)); foreach (var col in data.Columns.Cast <DataColumn>().Where(col => col.DataType == typeof(DateTime))) { col.DateTimeMode = DataSetDateTime.Unspecified; } module.PrepareData(data); Logger.Debug("end load table {0}", table.Name); Logger.Debug("begin saving table {0}", table.Name); var tmp = Path.GetTempFileName(); using (var file = File.OpenWrite(tmp)) { data.WriteXml(file, XmlWriteMode.WriteSchema); data.Clear(); } writer.WriteEntry(KeyHelper.GetTableZipKey(module, data.TableName), tmp); File.Delete(tmp); Logger.Debug("end saving table {0}", table.Name); } SetCurrentStepProgress((int)((++tablesProcessed * 100) / (double)tablesCount)); } } Logger.Debug("end saving data for module {0}", module.ModuleName); }
private void DoBackupModule(IDataWriteOperator writer, DbFactory dbFactory, IModuleSpecifics module) { InvokeInfo("begin saving data for module {0}", module.ModuleName); int tablesCount = module.Tables.Count(); int tablesProcessed = 0; using (var connection = dbFactory.OpenConnection(module.ConnectionStringName)) { foreach (var table in module.Tables) { InvokeInfo("begin saving table {0}", table.Name); using (var data = new DataTable(table.Name)) { ActionInvoker.Try( state => { data.Clear(); var t = (TableInfo)state; var dataAdapter = dbFactory.CreateDataAdapter(module.ConnectionStringName); dataAdapter.SelectCommand = module.CreateSelectCommand(connection.Fix(), Tenant.TenantId, t).WithTimeout(600); ((DbDataAdapter)dataAdapter).Fill(data); }, table, maxAttempts: 5, onFailure: error => { throw ThrowHelper.CantBackupTable(table.Name, error); }, onAttemptFailure: error => InvokeWarning("backup attempt failure: {0}", error)); foreach (var col in data.Columns.Cast<DataColumn>().Where(col => col.DataType == typeof(DateTime))) { col.DateTimeMode = DataSetDateTime.Unspecified; } var stream = writer.BeginWriteEntry(KeyHelper.GetTableZipKey(module, data.TableName)); data.WriteXml(stream, XmlWriteMode.WriteSchema); writer.EndWriteEntry(); data.Clear(); } SetStepProgress((int)((++tablesProcessed*100)/(double)tablesCount)); } } InvokeInfo("end saving data for module {0}", module.ModuleName); }
private void DoBackupModule(IDataWriteOperator writer, DbFactory dbFactory, IModuleSpecifics module) { InvokeInfo("begin saving data for module {0}", module.ModuleName); int tablesCount = module.Tables.Count(); int tablesProcessed = 0; using (var connection = dbFactory.OpenConnection(module.ConnectionStringName)) { foreach (var table in module.Tables) { InvokeInfo("begin saving table {0}", table.Name); using (var data = new DataTable(table.Name)) { ActionInvoker.Try( state => { data.Clear(); var t = (TableInfo)state; var dataAdapter = dbFactory.CreateDataAdapter(module.ConnectionStringName); dataAdapter.SelectCommand = module.CreateSelectCommand(connection.Fix(), Tenant.TenantId, t).WithTimeout(600); ((DbDataAdapter)dataAdapter).Fill(data); }, table, maxAttempts: 5, onFailure: error => { throw ThrowHelper.CantBackupTable(table.Name, error); }, onAttemptFailure: error => InvokeWarning("backup attempt failure: {0}", error)); foreach (var col in data.Columns.Cast <DataColumn>().Where(col => col.DataType == typeof(DateTime))) { col.DateTimeMode = DataSetDateTime.Unspecified; } var stream = writer.BeginWriteEntry(KeyHelper.GetTableZipKey(module, data.TableName)); data.WriteXml(stream, XmlWriteMode.WriteSchema); writer.EndWriteEntry(); data.Clear(); } SetStepProgress((int)((++tablesProcessed * 100) / (double)tablesCount)); } } InvokeInfo("end saving data for module {0}", module.ModuleName); }