示例#1
0
        private async Task UpdateColumns()
        {
            var loadId = Guid.NewGuid();

            _columnsLoadId = loadId;
            _columnsLoadControl.PushLoad();

            try {
                var sourceColumns = await GetSourceColumns();

                if (_columnsLoadId == loadId)
                {
                    _columnsControl.SetSourceColumns(sourceColumns);
                    UpdateTargetColumns();
                    _columnsLoadControl.ClearError();
                    _columnsError.Value = null;
                }
            } catch (UncaughtErrorScriptException ex) {
                if (_columnsLoadId == loadId)
                {
                    _columnsError.Value = $"Error importing the CSV file:\r\n{ex.ErrorMessage}";
                    _columnsLoadControl.SetError(_columnsError.Value);
                }
            } catch (Exception ex) {
                if (_columnsLoadId == loadId)
                {
                    _columnsError.Value = $"Error importing the CSV file:\r\n{ex.Message}";
                    _columnsLoadControl.SetError(_columnsError.Value);
                }
            } finally {
                _columnsLoadControl.PopLoad();
            }
        }
示例#2
0
        private async Task UpdateScriptAndOutputPreview()
        {
            var errorMessage = GetErrorMessage();

            // Import Script pane
            if (errorMessage == null)
            {
                _sqlLoadControl.ClearError();
                _sqlControl.SqlText = GetImportSql();
            }
            else
            {
                _sqlLoadControl.SetError(errorMessage);
            }

            // Preview pane
            if (errorMessage == null)
            {
                _outputPreviewLoadControl.ClearError();
                var loadId = Guid.NewGuid();
                _outputPreviewLoadId = loadId;
                _outputPreviewLoadControl.PushLoad();
                try {
                    var dt = await Task.Run(() => {
                        var tableName = Guid.NewGuid().ToString();
                        try {
                            _manager.ExecuteScript(GetImportSql(100, tableName));
                            return(_manager.ExecuteScript($"SELECT * FROM {tableName.DoubleQuote()}").DataTables[0]);
                        } finally {
                            _manager.ExecuteScript($"DROP TABLE IF EXISTS {tableName.DoubleQuote()}");
                        }
                    });

                    if (_outputPreviewLoadId == loadId)
                    {
                        _outputPreviewControl.SetTable(dt.ToDataTable(), disposeTable: true);
                    }
                } catch (UncaughtErrorScriptException ex) {
                    if (_outputPreviewLoadId == loadId)
                    {
                        _outputPreviewLoadControl.SetError($"Error importing the CSV file:\r\n{ex.ErrorMessage}");
                    }
                } catch (Exception ex) {
                    if (_outputPreviewLoadId == loadId)
                    {
                        _outputPreviewLoadControl.SetError($"Error importing the CSV file:\r\n{ex.Message}");
                    }
                } finally {
                    _outputPreviewLoadControl.PopLoad();
                }
            }
            else
            {
                _outputPreviewLoadControl.SetError(errorMessage);
            }
        }
示例#3
0
        private async Task UpdateInputPreview()
        {
            var loadId = Guid.NewGuid();

            _inputPreviewLoadId = loadId;
            _inputPreviewLoadControl.PushLoad();
            try {
                var tempTableName = Guid.NewGuid().ToString();
                var fileEncoding  = _optionsControl.FileEncoding.Value;
                var text          = await Task.Run(() => {
                    try {
                        var importSql =
                            @"IMPORT TXT @filePath INTO @tableName (number, line)
                            OPTIONS (TAKE_LINES: 1000, TEMPORARY_TABLE: 1, FILE_ENCODING: @encoding);";
                        _manager.ExecuteScript(importSql, new Dictionary <string, object> {
                            ["@filePath"]  = _filePath,
                            ["@tableName"] = tempTableName,
                            ["@encoding"]  = fileEncoding
                        });

                        var dt = _manager.ExecuteScript($"SELECT line FROM {tempTableName.DoubleQuote()} ORDER BY number")
                                 .DataTables[0];

                        return(string.Join(Environment.NewLine, dt.Rows.Select(x => x[0].ToString())));
                    } finally {
                        _manager.ExecuteScript($"DROP TABLE IF EXISTS {tempTableName.DoubleQuote()}");
                    }
                });

                if (_inputPreviewLoadId == loadId)
                {
                    _inputPreviewError.Value         = null;
                    _inputPreviewControl.PreviewText = text;
                }
            } catch (UncaughtErrorScriptException ex) {
                if (_inputPreviewLoadId == loadId)
                {
                    _inputPreviewError.Value = $"Error loading the input file:\r\n{ex.ErrorMessage}";
                    _inputPreviewLoadControl.SetError(_inputPreviewError.Value);
                }
            } finally {
                _inputPreviewLoadControl.PopLoad();
            }
        }