public async Task Convert() { DatabaseType sourceDbType = this.sourceInterpreter.DatabaseType; DatabaseType targetDbType = this.targetInterpreter.DatabaseType; int dataBatchSize = 500; DbInterpreterOption sourceScriptOption = new DbInterpreterOption() { ScriptOutputMode = GenerateScriptOutputMode.WriteToString, DataBatchSize = dataBatchSize }; DbInterpreterOption targetScriptOption = new DbInterpreterOption() { ScriptOutputMode = (GenerateScriptOutputMode.WriteToFile | GenerateScriptOutputMode.WriteToString), DataBatchSize = dataBatchSize }; this.sourceInterpreter.Option = sourceScriptOption; this.targetInterpreter.Option = targetScriptOption; GenerateScriptMode scriptMode = GenerateScriptMode.Schema | GenerateScriptMode.Data; DbConvetorInfo source = new DbConvetorInfo() { DbInterpreter = sourceInterpreter }; DbConvetorInfo target = new DbConvetorInfo() { DbInterpreter = targetInterpreter }; try { using (DbConvertor dbConvertor = new DbConvertor(source, target)) { dbConvertor.Option.GenerateScriptMode = scriptMode; dbConvertor.Subscribe(this); if (sourceDbType == DatabaseType.MySql) { source.DbInterpreter.Option.InQueryItemLimitCount = 2000; } if (targetDbType == DatabaseType.SqlServer) { target.DbOwner = "dbo"; } else if (targetDbType == DatabaseType.MySql) { target.DbInterpreter.Option.RemoveEmoji = true; } dbConvertor.Option.SplitScriptsToExecute = true; FeedbackHelper.EnableLog = true; await dbConvertor.Convert(); } } catch (Exception ex) { string msg = ExceptionHelper.GetExceptionDetails(ex); this.Feedback(new FeedbackInfo() { InfoType = FeedbackInfoType.Error, Message = msg }); } }
private async Task Convert() { SchemaInfo schemaInfo = this.GetSourceTreeSchemaInfo(); if (!this.ValidateSource(schemaInfo)) { return; } if (this.targetDbConnectionInfo == null) { MessageBox.Show("Target connection info is null."); return; } if (this.sourceDbConnectionInfo.Server == this.targetDbConnectionInfo.Server && this.sourceDbConnectionInfo.Database == this.targetDbConnectionInfo.Database) { MessageBox.Show("Source database cannot be equal to the target database."); return; } DatabaseType sourceDbType = this.GetDatabaseType(this.cboSourceDB.Text); DatabaseType targetDbType = this.GetDatabaseType(this.cboTargetDB.Text); int dataBatchSize = SettingManager.Setting.DataBatchSize; DbInterpreterOption sourceScriptOption = new DbInterpreterOption() { ScriptOutputMode = GenerateScriptOutputMode.None, DataBatchSize = dataBatchSize }; DbInterpreterOption targetScriptOption = new DbInterpreterOption() { ScriptOutputMode = (GenerateScriptOutputMode.WriteToString), DataBatchSize = dataBatchSize }; this.SetGenerateScriptOption(sourceScriptOption, targetScriptOption); if (this.chkGenerateSourceScripts.Checked) { sourceScriptOption.ScriptOutputMode = sourceScriptOption.ScriptOutputMode | GenerateScriptOutputMode.WriteToFile; } if (this.chkOutputScripts.Checked) { targetScriptOption.ScriptOutputMode = targetScriptOption.ScriptOutputMode | GenerateScriptOutputMode.WriteToFile; } targetScriptOption.GenerateIdentity = this.chkGenerateIdentity.Checked; GenerateScriptMode scriptMode = this.GetGenerateScriptMode(); if (scriptMode == GenerateScriptMode.None) { MessageBox.Show("Please specify the script mode."); return; } DbConvetorInfo source = new DbConvetorInfo() { DbInterpreter = DbInterpreterHelper.GetDbInterpreter(sourceDbType, this.sourceDbConnectionInfo, sourceScriptOption) }; DbConvetorInfo target = new DbConvetorInfo() { DbInterpreter = DbInterpreterHelper.GetDbInterpreter(targetDbType, this.targetDbConnectionInfo, targetScriptOption) }; try { using (dbConvertor = new DbConvertor(source, target)) { dbConvertor.Option.GenerateScriptMode = scriptMode; dbConvertor.Option.BulkCopy = this.chkBulkCopy.Checked; dbConvertor.Option.ExecuteScriptOnTargetServer = this.chkExecuteOnTarget.Checked; dbConvertor.Option.UseTransaction = this.chkUseTransaction.Checked; dbConvertor.Subscribe(this); if (sourceDbType == DatabaseType.MySql) { source.DbInterpreter.Option.InQueryItemLimitCount = 2000; } if (targetDbType == DatabaseType.SqlServer) { target.DbOwner = this.txtTargetDbOwner.Text ?? "dbo"; } else if (targetDbType == DatabaseType.MySql) { target.DbInterpreter.Option.RemoveEmoji = true; } dbConvertor.Option.SplitScriptsToExecute = true; this.btnExecute.Enabled = false; this.btnCancel.Enabled = true; await dbConvertor.Convert(schemaInfo); } } catch (Exception ex) { this.hasError = true; this.HandleException(ex); } if (!this.hasError) { this.btnExecute.Enabled = true; this.btnCancel.Enabled = false; if (!this.dbConvertor.CancelRequested) { this.txtMessage.AppendText(Environment.NewLine + DONE); MessageBox.Show(DONE); } else { MessageBox.Show("Task has been canceled."); } } }