Пример #1
0
        public string Execute()
        {
            ScripterParserInput parserInput = null;

            if (!TryGetParserInput(out parserInput))
            {
                return("Cannot find any input");
            }

            ScripterParserResult parserResult = null;

            if (!_parser.TryParse(parserInput, out parserResult))
            {
                return(parserResult.Error);
            }

            ScripterConfig config = _configStorage.Load();

            var scripterInput = new ScripterInput()
            {
                Database = parserResult.Database,
                Schema   = parserResult.Schema,
                Name     = parserResult.Name,
                ScriptDatabaseContext = config.ScriptDatabaseContext,
            };

            string scriptResult = null;

            if (!TryScript(scripterInput, out scriptResult))
            {
                return(scriptResult);
            }

            IEditor editor = _hostCtx.GetNewEditor();

            editor.SetContent(scriptResult);

            return("Success");
        }
Пример #2
0
        private bool TryScript(ScripterInput input, out string result)
        {
            result = null;

            bool success = false;

            try
            {
                using (IDbConnection connection = _hostCtx.CloneCurrentConnection(input.Database))
                {
                    connection.Open();
                    result  = _scripter.Script(connection, input);
                    success = true;
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            return(success);
        }