private async Task UpdateColumns() { var loadId = Guid.NewGuid(); _columnsLoadId = loadId; _columnsLoadControl.PushLoad(); try { var(sourceColumns, detectedTypes) = await GetSourceColumns(); if (_columnsLoadId == loadId) { _columnsControl.SetSourceColumns(sourceColumns, detectedTypes); 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.GetExceptionMessage()}"; _columnsLoadControl.SetError(_columnsError.Value); } } finally { _columnsLoadControl.PopLoad(); } }
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.ExecuteScriptNoOutput(importSql, new Dictionary <string, object> { ["@filePath"] = _filePath, ["@tableName"] = tempTableName, ["@encoding"] = fileEncoding }); using 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.ExecuteScriptNoOutput($"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(); } }