T IQueryExecutor.ExecuteScalar <T>(QueryModel queryModel) { var mapping = _schema.MappingFor(queryModel.SelectClause.Selector.Type); var documentQuery = new DocumentQuery(mapping, queryModel, _serializer); _schema.EnsureStorageExists(mapping.DocumentType); if (queryModel.ResultOperators.OfType <AnyResultOperator>().Any()) { var anyCommand = documentQuery.ToAnyCommand(); return(_runner.Execute(conn => { anyCommand.Connection = conn; return (T)anyCommand.ExecuteScalar(); })); } if (queryModel.ResultOperators.OfType <CountResultOperator>().Any()) { var countCommand = documentQuery.ToCountCommand(); return(_runner.Execute(conn => { countCommand.Connection = conn; var returnValue = countCommand.ExecuteScalar(); return Convert.ToInt32(returnValue).As <T>(); })); } throw new NotSupportedException(); }
private void Restore(string pathToProjectJson) { ExtractNugetExecutable(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { commandRunner.Execute(PathToNuget, $"restore {pathToProjectJson}"); } else { commandRunner.Execute("mono", $"{PathToNuget} restore {pathToProjectJson}"); } }
private IEnumerable <string> findFunctionNames() { return(_runner.Execute(conn => { var sql = @" SELECT routine_name FROM information_schema.routines WHERE specific_schema NOT IN ('pg_catalog', 'information_schema') AND type_udt_name != 'trigger'; "; var command = conn.CreateCommand(); command.CommandText = sql; var list = new List <string>(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { list.Add(reader.GetString(0)); } reader.Close(); } return list; })); }
public async Task <Measurement> Measure(MetricConfig config, CancellationToken ct) { if (config is null) { throw new ArgumentNullException(nameof(config)); } using (logger.WithTopic(config.Metric)) { logger.LogDebug($"Capturing new measurement ..."); try { ct.ThrowIfCancellationRequested(); var output = await runner.Execute(config.Command, ct); logger.LogDebug("Measurement successfully completed!"); return(new SuccessfulMeasurement(config.Metric, output)); } catch (Exception e) { logger.LogError(e, $"Failed to measure {config.Metric.Topic} !"); return(new FailedMeasurement(config.Metric, e)); } } }
public static IList <string> GetStringList(this ICommandRunner runner, string sql, params object[] parameters) { var list = new List <string>(); runner.Execute(conn => { var cmd = conn.CreateCommand(sql); parameters.Each(x => { var param = cmd.AddParameter(x); cmd.CommandText = cmd.CommandText.UseParameter(param); }); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { list.Add(reader.GetString(0)); } reader.Close(); } }); return(list); }
public FetchResult <T> LoadDocument <T>(object id) where T : class { var storage = storage <T>(); var resolver = storage.As <IResolver <T> >(); var cmd = storage.LoaderCommand(id); return(_runner.Execute(conn => { cmd.Connection = conn; using (var reader = cmd.ExecuteReader()) { var found = reader.Read(); return found ? new FetchResult <T>(resolver.Build(reader, _serializer), reader.GetString(0)) : null; } })); }
public void CreateSchema(IDocumentSchema schema, IDocumentMapping mapping) { var writer = new StringWriter(); SchemaBuilder.WriteSchemaObjects(mapping, schema, writer); var sql = writer.ToString(); try { _runner.Execute(sql); } catch (Exception e) { throw new MartenSchemaException(mapping.DocumentType, sql, e); } }
public async Task <LoanResult> CreateLoanAsync(CreateLoanRequestModel createLoanRequestModel) { var command = createLoanRequestModel.ToCommand(); var validationErrors = _commandRunner.Validate(command, null); if (validationErrors.Any()) { return(new LoanResult { ValidationErrors = validationErrors }); } var id = await _commandRunner.Execute(command, null); var loanDto = await GetLoanByIdAsync(id); return(new LoanResult { LoanDto = loanDto }); }
public HiloSequenceTests() { _container.GetInstance <DocumentCleaner>().CompletelyRemoveAll(); var sql = SchemaBuilder.GetText("mt_hilo"); _runner = _container.GetInstance <ICommandRunner>(); _runner.Execute(sql); theSequence = new HiloSequence(_runner, "foo", new HiloSettings()); }
public HiloSequenceTests() { _container.GetInstance<DocumentCleaner>().CompletelyRemoveAll(); var sql = SchemaBuilder.GetText("mt_hilo"); _runner = _container.GetInstance<ICommandRunner>(); _runner.Execute(sql); theSequence = new HiloSequence(_runner, "foo", new HiloSettings()); }
public static int Execute(this ICommandRunner runner, string sql) { return(runner.Execute(conn => { using (var command = conn.CreateCommand()) { command.CommandText = sql; return command.ExecuteNonQuery(); } })); }
public static T QueryScalar <T>(this ICommandRunner runner, string sql) { return(runner.Execute(conn => { using (var command = conn.CreateCommand()) { command.CommandText = sql; return (T)command.ExecuteScalar(); } })); }
public static IEnumerable <T> Fetch <T>(this ICommandRunner runner, string sql, Func <DbDataReader, T> transform, params object[] parameters) { return(runner.Execute(conn => { try { return conn.Fetch(sql, transform, parameters); } catch (Exception e) { throw new Exception($"Error trying to fetch w/ sql '{sql}'", e); } })); }
public static IEnumerable <T> Resolve <T>(this ICommandRunner runner, NpgsqlCommand cmd, IResolver <T> resolver, IIdentityMap map) { return(runner.Execute(conn => { cmd.Connection = conn; var list = new List <T>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { list.Add(resolver.Resolve(reader, map)); } } return list; })); }
public void AdvanceToNextHi() { _runner.Execute(conn => { using (var tx = conn.BeginTransaction(IsolationLevel.Serializable)) { var raw = conn.CreateSprocCommand("mt_get_next_hi") .With("entity", _entityName) .Returns("next", NpgsqlDbType.Bigint).ExecuteScalar(); CurrentHi = Convert.ToInt64(raw); tx.Commit(); } }); CurrentLo = 1; }
public async Task <UserResult> CreateUserAsync(UserRequestModel userRequestModel) { var command = userRequestModel.ToCommand(); var validationErrors = _commandRunner.Validate(command, null); if (validationErrors.Any()) { return(new UserResult { ValidationErrors = validationErrors }); } var id = await _commandRunner.Execute(command, null); var userDto = await GetUserByIdAsync(id); return(new UserResult { UserDto = userDto }); }
public async Task <BookResult> CreateBookAsync(BookRequestModel bookRequestModel) { var command = bookRequestModel.ToCommand(); var validationErrors = _commandRunner.Validate(command, null); if (validationErrors.Any()) { return(new BookResult { ValidationErrors = validationErrors }); } var id = await _commandRunner.Execute(command, null); var bookDto = await GetBookByIdAsync(id); return(new BookResult { BookDto = bookDto }); }
public static IEnumerable <string> QueryJson(this ICommandRunner runner, NpgsqlCommand cmd) { return(runner.Execute(conn => { cmd.Connection = conn; var list = new List <string>(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { list.Add(reader.GetString(0)); } reader.Close(); } return list; })); }
public static void ExecuteInTransaction(this ICommandRunner runner, Action <NpgsqlConnection, NpgsqlTransaction> action) { runner.Execute(conn => { using (var tx = conn.BeginTransaction()) { try { action(conn, tx); tx.Commit(); } catch (Exception) { tx.Rollback(); throw; } } }); }
/// <summary> /// Executes the command line. /// </summary> /// <param name="cmdline">The command line to execute. That's the alias and the arguments (which are not mandatory)</param> public ExecutionResult Execute(string cmdline, long sessionId) { var cmd = _resolver.Split(cmdline, sessionId); var alias = _databaseService.GetAlias(cmd.Command, sessionId); alias = _resolver.Resolve(alias, cmd.Parameters); if (_pluginManager.Exists(alias.Name)) { _pluginManager.Execute(cmd); return(ExecutionResult.SuccesShow);; } else if (_macroRunner.Exists(alias.FileName)) { _macroRunner.Execute(alias); return(ExecutionResult.SuccessHide); } else { return(_cmdRunner.Execute(alias)); } }
public void Execute(Alias alias) { _log.Trace($"Managing a '{alias.FileName}' with multiple aliases: {alias.Arguments}"); var splited = Regex.Split(alias.Arguments, "([@])"); foreach (var item in splited) { if (string.IsNullOrEmpty(item)) { continue; } else if (item == "@") { _log.Trace("Sleep for one second"); Thread.Sleep(1_000); } else { _log.Trace($"Multiple alias. Executing '{item}'."); _runner.Execute(item, alias.IdSession); } } }
private void OnDeletePointEvent(object sender, EventArgs e) { if (_route == null) { _errorView.ShowErrorMessage("Please load route first."); return; } var trackPoint = GetTrackPoint(_selectedTimeStamp); if (trackPoint == null) { _errorView.ShowErrorMessage("Please select a point first"); return; } TryCatch(() => { var result = _commandRunner.Execute( new DeleteCoursePointInput { Route = _route, TimeStamp = _selectedTimeStamp }) as DeleteCoursePointResponse; _route = result.Route; _routeView.ShowRoute(result.Route); _routeView.ShowPointToEdit( result.Route.TrackPoints.First( p => p.TimeStamp == _selectedTimeStamp)); _guiControls.Apply(new GuiState { SaveEnabled = true, AddCoursePoint = true, DeleteCoursePoint = false, ScrollRoute = true }); }); }
private void Restore(string pathToProjectFile) { _commandRunner.Execute("DotNet", $"restore {pathToProjectFile} -r win7-x64"); }
private void truncateTable(string tableName) { var sql = "truncate {0} cascade".ToFormat(tableName); _runner.Execute(sql); }
public void Execute(Action <NpgsqlConnection> action) { incrementRequestCount(); _commandRunner.Execute(action); }
public void Append <T>(Guid stream, T @event) where T : IEvent { var eventMapping = _schema.Events.EventMappingFor <T>(); _runner.Execute(conn => appendEvent(conn, eventMapping, stream, @event)); }