private void WriteTable(string sql) { using var status = WaitStatus.StartRows(Path.GetFileName(_filePath)); var fileMode = _truncateExistingFile ? FileMode.Create : FileMode.Append; using var stream = File.Open(_filePath, fileMode, FileAccess.Write, FileShare.None); using var writer = new StreamWriter(stream, _fileEncoding); using var statement = _notebook.Prepare(sql); var args = statement.GetArgs(_env.Vars); statement.ExecuteStream(args, OnHeader, OnRow, CancellationToken.None); void OnHeader(List <string> columnNames) { if (_headerRow) { writer.WriteLine(string.Join(_separator, columnNames.Select(c => CsvUtil.QuoteCsv(c, _separator)))); } } void OnRow(object[] row) { _cancel.ThrowIfCancellationRequested(); CsvUtil.WriteCsvLine(writer, _separator, row); status.IncrementRows(); } }
private void Execute() { var sql = _inputText.SqlText.Trim(); if (string.IsNullOrWhiteSpace(sql)) { return; } using var output = WaitForm.GoWithCancel(TopLevelControl, "Console", "Executing...", out var success, cancel => { return(SqlUtil.WithCancellation(_manager.Notebook, () => { using var status = WaitStatus.StartRows("Script output"); return _manager.ExecuteScript(sql, onRow: status.IncrementRows); }, cancel)); }); _manager.SetDirty(); _manager.Rescan(); if (!success) { return; } _inputText.SqlText = ""; Log(sql, output); TakeFocus(); }
public void SaveAs(string filePath, CancellationToken cancel) { NotebookItemsSaveRequest?.Invoke(this, EventArgs.Empty); using var status = WaitStatus.StartCustom(Path.GetFileName(filePath)); Notebook.SaveAs(filePath, c => status.SetProgress($"{c}% complete"), cancel); }
private void WriteTable(SimpleDataTable sdt) { using var status = WaitStatus.StartRows(Path.GetFileName(_filePath)); var fileMode = _truncateExistingFile ? FileMode.Create : FileMode.Append; using var stream = File.Open(_filePath, fileMode, FileAccess.Write, FileShare.None); using var writer = new StreamWriter(stream, _fileEncoding); if (_headerRow) { writer.WriteLine(string.Join(_separator, sdt.Columns.Select(c => CsvUtil.QuoteCsv(c, _separator)))); } CsvUtil.WriteCsv(sdt.Rows, writer, status.IncrementRows, _separator, _cancel); }
private void ImportLink() { using var status = WaitStatus.StartStatic(GetTruncatedDstTableName()); if (_vendor == "mssql") { _notebook.Execute( $"CREATE VIRTUAL TABLE {_dstTableName.DoubleQuote()} USING mssql " + $"('{_connectionString.Replace("'", "''")}', '{_srcTableName.Replace("'", "''")}', " + $"'{_srcSchemaName.Replace("'", "''")}')"); } else { _notebook.Execute( $"CREATE VIRTUAL TABLE {_dstTableName.DoubleQuote()} USING {_vendor} " + $"('{_connectionString.Replace("'", "''")}', '{_srcTableName.Replace("'", "''")}')"); } }
private static void InitHelpNotebook(Notebook notebook, string sqlnbFilePath) { var exeDir = Path.GetDirectoryName(Application.ExecutablePath); var docDir = Path.Combine(exeDir, "doc"); var htmlFiles = ( from htmlFilePath in Directory.GetFiles(docDir, "*.html", SearchOption.AllDirectories) let content = File.ReadAllText(htmlFilePath) select(FilePath: htmlFilePath, Content: content) ).ToList(); notebook.Execute("BEGIN"); notebook.Execute( @"CREATE TABLE docs ( id INTEGER PRIMARY KEY, path TEXT NOT NULL, book TEXT NOT NULL, title TEXT NOT NULL, html TEXT NOT NULL )"); notebook.Execute( @"CREATE TABLE books_txt (number INTEGER PRIMARY KEY, line TEXT NOT NULL)"); notebook.Execute( @"CREATE TABLE art (file_path TEXT PRIMARY KEY, content BLOB)"); notebook.Execute("CREATE VIRTUAL TABLE docs_fts USING fts5 (id, title, text)"); using var status = WaitStatus.StartCustom("Documentation index"); for (var i = 0; i < htmlFiles.Count; i++) { status.SetProgress($"{i * 100 / htmlFiles.Count}% complete"); var(filePath, content) = htmlFiles[i]; var filename = Path.GetFileName(filePath); if (filename == "doc.html" || filename == "index.html") { continue; } // Parse out the title. var title = "(no title)"; { var startIndex = content.IndexOf("<title>"); var endIndex = content.IndexOf("</title>"); if (startIndex >= 0 && endIndex > startIndex) { title = WebUtility.HtmlDecode(content[(startIndex + "<title>".Length)..endIndex]).Trim();
internal ConfirmationResponse Wait(int millisecondsTimeout) { try { var response = true; if (_confirmationMessage == null) { _waitStatus = WaitStatus.Waiting; response = _confirmEvent.WaitOne(millisecondsTimeout); } return(new ConfirmationResponse(response, _confirmationMessage, _isSuccess)); } finally { _waitStatus = WaitStatus.DoneWaiting; } }
public void SetFuncBtn(WaitStatus status) { nowWaitStatus = status; if (status == WaitStatus.beReady) { funcText.text = "准备"; } else if (status == WaitStatus.cancelReady) { funcText.text = "取消准备"; } else if (status == WaitStatus.startMatch) { funcText.text = "开始匹配"; } else if (status == WaitStatus.matching) { funcText.text = "匹配中..."; } }
public void OnOpen() { using var simpleDataTable = WaitForm.GoWithCancel(TopLevelControl, "Table", "Reading table...", out var success, cancel => { using var status = WaitStatus.StartStatic(_tableName); cancel.Register(() => _manager.Notebook.BeginUserCancel()); try { return(_manager.Notebook.Query($"SELECT * FROM {_tableName.DoubleQuote()} LIMIT 1000")); } finally { _manager.Notebook.EndUserCancel(); } }); if (!success) { throw new OperationCanceledException(); } _grid.DataSource = simpleDataTable.ToDataTable(); _grid.AutoSizeColumns(this.Scaled(500)); _query = $"SELECT\r\n{string.Join(",\r\n", simpleDataTable.Columns.Select(x => " " + x.DoubleQuote()))}\r\nFROM {_tableName.DoubleQuote()}\r\nLIMIT 1000;\r\n"; }
private void OnWaitStatus(EventArgs e) { try { WaitStatus?.Invoke(this, e); } catch { } }
public static long ExitStatus(this WaitStatus w) { return(0L); }
public static Signal StopSignal(this WaitStatus w) { return(0L); }
public static long TrapCause(this WaitStatus w) { return(0L); }
public static bool Continued(this WaitStatus w) { return(false); }
public static bool Stopped(this WaitStatus w) { return(false); }
public static bool CoreDump(this WaitStatus w) { return(false); }
public static bool Signaled(this WaitStatus w) { return(false); }
public static bool Exited(this WaitStatus w) { return(false); }