Пример #1
0
        public async Task Convert()
        {
            DatabaseType sourceDbType = this.sourceInterpreter.DatabaseType;
            DatabaseType targetDbType = this.targetInterpreter.DatabaseType;

            int dataBatchSize = 500;

            DbInterpreterOption sourceScriptOption = new DbInterpreterOption()
            {
                ScriptOutputMode = GenerateScriptOutputMode.WriteToString
            };
            DbInterpreterOption targetScriptOption = new DbInterpreterOption()
            {
                ScriptOutputMode = (GenerateScriptOutputMode.WriteToFile | GenerateScriptOutputMode.WriteToString)
            };

            this.sourceInterpreter.Option = sourceScriptOption;
            this.targetInterpreter.Option = targetScriptOption;

            GenerateScriptMode scriptMode = GenerateScriptMode.Schema | GenerateScriptMode.Data;

            DbConveterInfo source = new DbConveterInfo()
            {
                DbInterpreter = sourceInterpreter
            };
            DbConveterInfo target = new DbConveterInfo()
            {
                DbInterpreter = targetInterpreter
            };

            try
            {
                using (DbConverter dbConverter = new DbConverter(source, target))
                {
                    dbConverter.Option.GenerateScriptMode = scriptMode;

                    dbConverter.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;
                    }

                    dbConverter.Option.SplitScriptsToExecute = true;

                    FeedbackHelper.EnableLog = true;

                    await dbConverter.Convert();
                }
            }
            catch (Exception ex)
            {
                string msg = ExceptionHelper.GetExceptionDetails(ex);

                this.Feedback(new FeedbackInfo()
                {
                    InfoType = FeedbackInfoType.Error, Message = msg
                });
            }
        }
Пример #2
0
        public async Task Translate(DatabaseType sourceDbType, DatabaseType targetDbType, DatabaseObject dbObject, ConnectionInfo connectionInfo, TranslateHandler translateHandler = null)
        {
            DbInterpreterOption sourceScriptOption = new DbInterpreterOption()
            {
                ScriptOutputMode = GenerateScriptOutputMode.None
            };
            DbInterpreterOption targetScriptOption = new DbInterpreterOption()
            {
                ScriptOutputMode = GenerateScriptOutputMode.WriteToString
            };

            DbConveterInfo source = new DbConveterInfo()
            {
                DbInterpreter = DbInterpreterHelper.GetDbInterpreter(sourceDbType, connectionInfo, sourceScriptOption)
            };
            DbConveterInfo target = new DbConveterInfo()
            {
                DbInterpreter = DbInterpreterHelper.GetDbInterpreter(targetDbType, new ConnectionInfo(), sourceScriptOption)
            };

            using (DbConverter dbConverter = new DbConverter(source, target))
            {
                dbConverter.Option.OnlyForTranslate               = true;
                dbConverter.Option.GenerateScriptMode             = GenerateScriptMode.Schema;
                dbConverter.Option.ExecuteScriptOnTargetServer    = false;
                dbConverter.Option.ConvertComputeColumnExpression = true;

                dbConverter.Subscribe(this.observer);

                if (translateHandler != null)
                {
                    dbConverter.OnTranslated += translateHandler;
                }

                if (targetDbType == DatabaseType.SqlServer)
                {
                    target.DbOwner = "dbo";
                }

                SchemaInfo schemaInfo = new SchemaInfo();

                if (dbObject is Table)
                {
                    schemaInfo.Tables.Add(dbObject as Table);
                }
                else if (dbObject is View)
                {
                    schemaInfo.Views.Add(dbObject as DatabaseInterpreter.Model.View);
                }
                else if (dbObject is Function)
                {
                    schemaInfo.Functions.Add(dbObject as Function);
                }
                else if (dbObject is Procedure)
                {
                    schemaInfo.Procedures.Add(dbObject as Procedure);
                }
                else if (dbObject is TableTrigger)
                {
                    schemaInfo.TableTriggers.Add(dbObject as TableTrigger);
                }

                await dbConverter.Convert(schemaInfo);
            }
        }