Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
            }
        }