public double Multiply(double lhs, double rhs) { var result = lhs * rhs; _resultWriter.WriteResult(result); return(result); }
public int ExecuteQuery(string sql, IResultWriter sw, Action <Int64> setResults, string context = "", Globals.ResultWriterDestination dest = Globals.ResultWriterDestination.stdOut) { Int64 numResults = 0; if (sql.Contains("ROW_NUMBER(")) { SQLitePCL.Functions.core.CoreFn.RowNumDictionary = new Dictionary <string, int>(); } if (sql.Contains("JSON(")) { var match = Regex.Match(sql, @"JSON\((?<key>.*?)\)"); sql = Regex.Replace(sql, @"JSON\(\w*\)", "", RegexOptions.IgnoreCase); sw.Key = match.Groups["key"].Value; } int resp = (int)ErrorCode.Ok; try { var stmts = DbConnection.PrepareAll(CleanSql(sql)); foreach (var stmt in stmts) { if (stmt.SQL != null && stmt.MoveNext()) { var headers = stmt.Columns.Select(col => col.Name).ToList <string>(); sw .BeginContext(context, dest) .WriteHeaders(headers, dest) .WriteResult(stmt.Current, dest); // Write the rest... while (stmt.MoveNext()) { numResults++; sw.WriteResult(stmt.Current, dest); } sw.EndContext(dest); } } } catch (SQLiteException e) { resp = (int)e.ErrorCode; LastError = e.Message + " -- " + raw.sqlite3_errmsg(RawDbConnection) + " -- on query: " + sql; } finally { sw.Flush(); Int64 changes = DbConnection.Changes; // if we didn't make any db changes, then we performed a query, so let's return the number of results in that query if (changes == 0 && numResults != 0) { changes = numResults; } setResults(changes); } return(resp); }
public void CallResultWriter(IResultWriter writer) { if (!cachedResult.HasValue) { cachedResult = results.Pop(); } writer.WriteResult((int)cachedResult); }
void BackupFile(string file) { var backupFile = new BackupFile(file, _opts.RelativeRoot); var result = new BackupResult { Region = _opts.Region, Vault = _opts.VaultName, Backup = backupFile }; for (var i = 1; i <= RETRY_COUNT; i++) { var attempt = i > 1 ? $" (attempt {i})" : string.Empty; try { Console.WriteLine($" - backing up {backupFile.GlacierDescription}{attempt}"); result.Result = _atm.UploadAsync(_opts.VaultName, backupFile.GlacierDescription, backupFile.FullPath).Result; lock (_lockObj) { _resultWriter.WriteResult(result); } return; } catch (Exception ex) { Console.WriteLine($" - error backing up {backupFile.GlacierDescription}{attempt}: {ex.Message}"); var ms = _rand.Next(START_WAIT_TIME_MS) * i; // wait for a random amount of time, and increase as the number of tries increases Thread.Sleep(ms); } } Console.WriteLine($" ** unable to backup {backupFile.GlacierDescription} **"); }
private void OnSaveButtonClick(Object sender, EventArgs args) { IResultWriter affected = this.tvcContent.SelectedTab.Controls[0] as IResultWriter; if (affected == null || !affected.HasResult) { return; } SaveFileDialog dialog = new SaveFileDialog() { Title = "Save Passwords", Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*", FileName = $"passwords-{DateTime.Now:yyyyMMddHHmmss}.txt", RestoreDirectory = true }; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } try { using (Stream stream = dialog.OpenFile()) { affected.WriteResult(stream, Encoding.UTF8); } } catch (Exception exception) { MessageBox.Show(this, $"Could not save file. See message below for more details. {Environment.NewLine.Repeat(2)}{exception.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void CallResultWriter(IResultWriter writer) { writer.WriteResult(sb.ToString()); }