private async Task Query(DocumentsOperationContext context, string indexName, OperationCancelToken token, HttpMethod method) { var indexQuery = GetIndexQuery(context, method); var existingResultEtag = GetLongFromHeaders("If-None-Match"); var includes = GetStringValuesQueryString("include", required: false); var metadataOnly = GetBoolValueQueryString("metadata-only", required: false) ?? false; var runner = new QueryRunner(Database, context); DocumentQueryResult result; try { result = await runner.ExecuteQuery(indexName, indexQuery, includes, existingResultEtag, token).ConfigureAwait(false); } catch (IndexDoesNotExistsException) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } if (result.NotModified) { HttpContext.Response.StatusCode = 304; return; } HttpContext.Response.Headers[Constants.MetadataEtagField] = result.ResultEtag.ToInvariantString(); using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteDocumentQueryResult(context, result, metadataOnly); } }
/// <summary>The query background worker_ do work.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void queryBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { string sql = (string)e.Argument; _runner.BatchProgress += RunnerBatchProgress; _runner.ExecuteQuery(sql); }
/// <summary> /// Execute query /// </summary> public static void ExecuteQuery(SqlQuery query) { var databaseIds = query .Databases .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(id => id .Trim() .ToLower()) .ToList(); bool isAllDatabases = databaseIds.Count == 1 && databaseIds[0] == "all"; List <WorkerDb> executeInDatabases = (isAllDatabases) ? _databases.ToList() : new List <WorkerDb>(); if (!isAllDatabases) { foreach (var id in databaseIds) { var database = _databases .Where(db => db.Id == id) .FirstOrDefault(); if (database != null) { executeInDatabases.Add(database); } } } QueryRunner runner = new QueryRunner(query, executeInDatabases); runner.ExecuteQuery(); }
public void No_provider_expects_error_on_Execute() { _runner = new QueryRunner(null, _conn, true, 30); var exp = Assert.Throws <InvalidOperationException>(() => _runner.ExecuteQuery(" ")); Assert.That(exp.Message, Is.EqualTo("Supply a provider.")); }
public void No_connection_expects_error_on_Execute() { _runner = new QueryRunner(DbProviderFactories.GetFactory("System.Data.SqlClient"), null, true, 30); var exp = Assert.Throws <InvalidOperationException>(() => _runner.ExecuteQuery(" ")); Assert.That(exp.Message, Is.EqualTo("Supply a connection.")); }
static Task <AttachmentExecutionResult> RunQuery(string queryString) { var incomingAttachments = new IncomingAttachments(); var stream = BuildStream(); var metadata = new HeaderDictionary { { "header1", "headerValue" } }; incomingAttachments.Add("key", new AttachmentStream("key", stream, 3, metadata)); var services = new ServiceCollection(); TestServices.AddGraphQlTestTypes(services); return(QueryRunner.ExecuteQuery(queryString, services, incomingAttachments)); }
private async Task Query(DocumentsOperationContext context, OperationCancelToken token, HttpMethod method) { var indexQuery = await GetIndexQuery(context, method); var existingResultEtag = GetLongFromHeaders("If-None-Match"); var includes = GetStringValuesQueryString("include", required: false); var metadataOnly = GetBoolValueQueryString("metadata-only", required: false) ?? false; var runner = new QueryRunner(Database, context); DocumentQueryResult result; try { result = await runner.ExecuteQuery(indexQuery, includes, existingResultEtag, token).ConfigureAwait(false); } catch (IndexDoesNotExistException) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } if (result.NotModified) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified; return; } HttpContext.Response.Headers[Constants.Headers.Etag] = CharExtensions.ToInvariantString(result.ResultEtag); int numberOfResults; using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream())) { writer.WriteDocumentQueryResult(context, result, metadataOnly, out numberOfResults); } Database.QueryMetadataCache.MaybeAddToCache(indexQuery.Metadata, result.IndexName); AddPagingPerformanceHint(PagingOperationType.Queries, $"{nameof(Query)} ({indexQuery.Metadata.IndexName})", HttpContext, numberOfResults, indexQuery.PageSize, TimeSpan.FromMilliseconds(result.DurationInMs)); }
public override void Execute() { //The BL is not allowed to run any queries, it can not even reference this assembly containing the //queries because that would be a cyclical reference. We need to give all data to the BL. IQueryable <SalaryCalculation> previousSalaries = QueryRunner.ExecuteQuery(new GetSalaryCalculationsForAnEmployee(db, _employeeId)); var validation = new SalaryCalculationValidation(); validation.ValidateSalaryCalculationPreConditions(_periodStartDate, _periodEndDate, previousSalaries); string idString = _employeeId; Taxcard taxCard = db.Taxcards.SingleOrDefault(card => card.EmployeeId == idString); var calculator = new SalaryCalculator(); SalaryCalculationResults res = calculator.CalculateSalary(taxCard, _grossSalary); //Saving the new calculation is not BL, that's why it is here. var salaryCalc = new SalaryCalculation { //EmployeeId = _employeeId, //GrossAmount = _grossSalary, //NetAmount = res.NetSalary, //PeriodStartDate = _periodStartDate, //PeriodEndDate = _periodEndDate, //Tax = res.Tax, SalaryCalculationId = Guid.NewGuid().ToString() }; db.SalaryCalculations.Add(salaryCalc); db.SaveChanges(); //You could argue that sending this event could be BL. Or you can say it is an infrastructural concern, like using //a transaction (if that was required here). However, it can not really exist in the salary calculation core because //the core only calculates and the whole process is not done until the result is persisted. So I would say this is //the right place after all. MessageBus.Send(new SalaryCalculationDoneEvent()); }
/// <summary> /// Runs the report. /// </summary> /// <param name="report">The report.</param> /// <param name="reportSettings">The settings.</param> /// <param name="suppressPreload">Pass true if the report has already been preloaded.</param> /// <returns>ReportResult.</returns> /// <exception cref="System.ArgumentException">@The report identifier resource is not a report.;reportId</exception> public ReportCompletionData PrepareReport(Model.Report report, ReportSettings reportSettings, bool suppressPreload = false) { if (report == null) { throw new ArgumentNullException("report"); } if (reportSettings == null) { reportSettings = new ReportSettings( ); } StructuredQuery structuredQuery; PreparedQuery preparedReport; PreparedQuery preparedRollup; using (EDC.ReadiNow.Diagnostics.Profiler.Measure("Prepare report run")) using (MessageContext messageContext = new MessageContext("Reports")) using (new SecurityBypassContext( )) { // Get the structured query structuredQuery = GetStructuredQuery(report, reportSettings, suppressPreload); // Handle metadata-only request if (reportSettings.RequireSchemaMetadata) { ReportResult reportResult = new ReportResult(report, structuredQuery, null, null, null, reportSettings); return(new ReportCompletionData(reportResult)); } // Prepare query settings preparedReport = PrepareReportRun(structuredQuery, reportSettings); preparedReport.QuerySettings.Hint = "Rpt-" + report.Id.ToString( ); // Handle rollups preparedRollup = PrepareReportRollupRun(report, preparedReport.StructuredQuery, reportSettings, preparedReport.QuerySettings); } Func <ReportResult> resultCallback = () => { ReportResult reportResult = null; QueryResult queryResult = null; QueryResult rollupResult = null; using (new SecurityBypassContext( )) { // Execute the query queryResult = QueryRunner.ExecuteQuery(preparedReport.StructuredQuery, preparedReport.QuerySettings); // Execute the rollup query if (preparedRollup.StructuredQuery != null) { rollupResult = QueryRunner.ExecuteQuery(preparedRollup.StructuredQuery, preparedRollup.QuerySettings); } // Package up the result. reportResult = new ReportResult(report, preparedReport.StructuredQuery, queryResult, preparedRollup.ClientAggregate, rollupResult, reportSettings); } return(reportResult); }; // Create cache key (null indicates report is not cacheable) IQueryRunnerCacheKey reportCacheKey = null; IQueryRunnerCacheKey rollupCacheKey = null; ReportResultCacheKey reportResultCacheKey = null; reportCacheKey = QueryRunnerCacheKeyProvider.CreateCacheKey(preparedReport.StructuredQuery, preparedReport.QuerySettings); if (reportCacheKey != null) { if (preparedRollup.StructuredQuery != null) { rollupCacheKey = QueryRunnerCacheKeyProvider.CreateCacheKey(preparedRollup.StructuredQuery, preparedRollup.QuerySettings); } reportResultCacheKey = new ReportResultCacheKey(reportSettings, reportCacheKey, rollupCacheKey); } // Create completion result ReportCompletionData completionData = new ReportCompletionData( ); completionData.ResultCallback = resultCallback; completionData.ResultCacheKey = reportResultCacheKey; completionData.CacheContextDuringPreparation = CacheContext.GetContext( ); return(completionData); }
public void No_provider_expects_error_on_Execute() { _runner = new QueryRunner(null, _conn, true, 30); Assert.That(() => _runner.ExecuteQuery(" "), Throws.InstanceOf <InvalidOperationException>().With.Message.EqualTo("Supply a provider.")); }
public void Bad_SQL_expects_an_error() { _runner.ExecuteQuery("SELECT foo FROM bar "); Console.WriteLine(_runner.Messages); Assert.That(_runner.Messages, Is.Not.Empty); }
public void No_provider_expects_error_on_Execute() { _runner = new QueryRunner(null, _conn, true, 30); _runner.ExecuteQuery(" "); }
public void No_connection_expects_error_on_Execute() { _runner = new QueryRunner(DbProviderFactories.GetFactory("System.Data.SqlClient"), null, true, 30); _runner.ExecuteQuery(" "); }