/// <summary> /// Validates the query sentence. /// </summary> /// <param name="sentence">The sentence.</param> /// <param name="configuration">The configuration.</param> /// <returns></returns> private Domain.Entities.ValidationResult ValidateQuerySentence(Query sentence, Configuration configuration) { QueryValidator validator = new QueryValidator(configuration.MatrixDimension); FluentValidation.Results.ValidationResult results = validator.Validate(sentence); return(GetValidationResultResponse(results)); }
public JsonLinesEvaluator(Query query) { var validator = new QueryValidator(); validator.Validate(query); validator.ThrowIfErrors(); _query = query; _recordWriter = new JsonRecordWriter(query.From, query.Select); }
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { if (actionExecutedContext == null) { throw Error.ArgumentNull("actionExecutedContext"); } Contract.Assert(actionExecutedContext.Request != null); HttpRequestMessage request = actionExecutedContext.Request; HttpResponseMessage response = actionExecutedContext.Response; IQueryable query; if (response != null && response.TryGetContentValue(out query)) { IQueryable deserializedQuery = null; if (request != null && request.RequestUri != null && !String.IsNullOrWhiteSpace(request.RequestUri.Query)) { Uri requestUri = request.RequestUri; try { ServiceQuery serviceQuery = ODataQueryDeserializer.GetServiceQuery(requestUri); if (serviceQuery.QueryParts.Count > 0) { IQueryable baseQuery = Array.CreateInstance(query.ElementType, 0).AsQueryable(); // T[] deserializedQuery = ODataQueryDeserializer.Deserialize(baseQuery, serviceQuery.QueryParts); if (_queryValidator != null) { _queryValidator.Validate(deserializedQuery); } } } catch (ParseException e) { actionExecutedContext.Response = request.CreateResponse( HttpStatusCode.BadRequest, Error.Format(SRResources.UriQueryStringInvalid, e.Message)); return; } } if (deserializedQuery != null) { query = QueryComposer.Compose(query, deserializedQuery); } query = ApplyResultLimit(actionExecutedContext, query); ((ObjectContent)response.Content).Value = query; } }
public IHttpActionResult GetInternal(string systemFilter = null, string userFilter = null, string sort = null, string time = null, string offset = null, string mode = null, int page = 1, int limit = 10) { page = GetPage(page); limit = GetLimit(limit); var skip = GetSkip(page + 1, limit); if (skip > MAXIMUM_SKIP) { return(Ok(new object[0])); } var validationResult = QueryValidator.Validate(userFilter); if (!validationResult.IsValid) { return(BadRequest(validationResult.Message)); } if (String.IsNullOrEmpty(systemFilter)) { systemFilter = GetAssociatedOrganizationsFilter(_organizationRepository, validationResult.UsesPremiumFeatures, HasOrganizationOrProjectFilter(userFilter)); } var sortBy = GetSort(sort); var timeInfo = GetTimeInfo(time, offset); var options = new PagingOptions { Page = page, Limit = limit }; var events = _repository.GetByFilter(systemFilter, userFilter, sortBy.Item1, sortBy.Item2, timeInfo.Field, timeInfo.UtcRange.Start, timeInfo.UtcRange.End, options); if (!String.IsNullOrEmpty(mode) && String.Equals(mode, "summary", StringComparison.InvariantCultureIgnoreCase)) { return(OkWithResourceLinks(events.Select(e => { var summaryData = _formattingPluginManager.GetEventSummaryData(e); return new EventSummaryModel { TemplateKey = summaryData.TemplateKey, Id = e.Id, Date = e.Date, Data = summaryData.Data }; }).ToList(), options.HasMore, page)); } return(OkWithResourceLinks(events, options.HasMore && !NextPageExceedsSkipLimit(page, limit), page)); }
public async Task <ViewModel> Handle(Query query, CancellationToken cancellationToken) { var viewModel = new ViewModel(); viewModel.ValidationResult = queryValidator.Validate(query); if (!viewModel.ValidationResult.IsValid) { return(viewModel); } viewModel.AuthorityCertificates = await privateCertRepository.GetValidAuthorityCertificatesAsync(); viewModel.SelectedAuthorityCertificateId = viewModel.AuthorityCertificates.First().CertificateId; viewModel.ExpirationDateInDays = 720; viewModel.SubjectName = "Signer or Bob"; return(viewModel); }
public IHttpActionResult FrequentInternal(string systemFilter = null, string userFilter = null, string time = null, string offset = null, string mode = null, int page = 1, int limit = 10) { page = GetPage(page); limit = GetLimit(limit); var skip = GetSkip(page, limit); if (skip > MAXIMUM_SKIP) { return(Ok(new object[0])); } var validationResult = QueryValidator.Validate(userFilter); if (!validationResult.IsValid) { return(BadRequest(validationResult.Message)); } if (String.IsNullOrEmpty(systemFilter)) { systemFilter = GetAssociatedOrganizationsFilter(_organizationRepository, validationResult.UsesPremiumFeatures, HasOrganizationOrProjectFilter(userFilter)); } var timeInfo = GetTimeInfo(time, offset); var terms = _eventStats.GetTermsStats(timeInfo.UtcRange.Start, timeInfo.UtcRange.End, "stack_id", systemFilter, userFilter, timeInfo.Offset, GetSkip(page + 1, limit) + 1).Terms; if (terms.Count == 0) { return(Ok(new object[0])); } var stackIds = terms.Skip(skip).Take(limit + 1).Select(t => t.Term).ToArray(); var stacks = _stackRepository.GetByIds(stackIds).Select(s => s.ApplyOffset(timeInfo.Offset)).ToList(); if (!String.IsNullOrEmpty(mode) && String.Equals(mode, "summary", StringComparison.InvariantCultureIgnoreCase)) { var summaries = GetStackSummaries(stacks, terms); return(OkWithResourceLinks(GetStackSummaries(stacks, terms).Take(limit).ToList(), summaries.Count > limit, page)); } return(OkWithResourceLinks(stacks.Take(limit).ToList(), stacks.Count > limit, page)); }
public IHttpActionResult GetInternal(string systemFilter, string userFilter = null, string time = null, string offset = null) { var timeInfo = GetTimeInfo(time, offset); var validationResult = QueryValidator.Validate(userFilter); if (!validationResult.IsValid) { return(BadRequest(validationResult.Message)); } if (String.IsNullOrEmpty(systemFilter)) { systemFilter = GetAssociatedOrganizationsFilter(_organizationRepository, validationResult.UsesPremiumFeatures, HasOrganizationOrProjectFilter(userFilter)); } var result = _stats.GetOccurrenceStats(timeInfo.UtcRange.Start, timeInfo.UtcRange.End, systemFilter, userFilter, timeInfo.Offset); return(Ok(result)); }
private static void ExecuteSearchQuery(string userInput) { var queryValidator = new QueryValidator(); try { queryValidator.Validate(userInput); var queryGenerator = new StudentQueryGenerator(); PrintFoundData(StudentRepository.Find(queryGenerator.Generate(userInput))); } catch (QueryNotMatchException ex) { Console.WriteLine(ex.Message); Console.ReadKey(); } catch (ParseException ex) { Console.WriteLine("The query generator is key sensitive, please use the properties listed previously."); Console.ReadKey(); } }
public IHttpActionResult GetInternal(string systemFilter, string userFilter = null, string sort = null, string time = null, string offset = null, string mode = null, int page = 1, int limit = 10) { page = GetPage(page); limit = GetLimit(limit); var skip = GetSkip(page + 1, limit); if (skip > MAXIMUM_SKIP) { return(Ok(new object[0])); } var validationResult = QueryValidator.Validate(userFilter); if (!validationResult.IsValid) { return(BadRequest(validationResult.Message)); } if (String.IsNullOrEmpty(systemFilter)) { systemFilter = GetAssociatedOrganizationsFilter(_organizationRepository, validationResult.UsesPremiumFeatures, HasOrganizationOrProjectFilter(userFilter), "last"); } var sortBy = GetSort(sort); var timeInfo = GetTimeInfo(time, offset); var options = new PagingOptions { Page = page, Limit = limit }; var stacks = _repository.GetByFilter(systemFilter, userFilter, sortBy.Item1, sortBy.Item2, timeInfo.Field, timeInfo.UtcRange.Start, timeInfo.UtcRange.End, options).Select(s => s.ApplyOffset(timeInfo.Offset)).ToList(); if (!String.IsNullOrEmpty(mode) && String.Equals(mode, "summary", StringComparison.InvariantCultureIgnoreCase)) { return(OkWithResourceLinks(GetStackSummaries(stacks, timeInfo.Offset, timeInfo.UtcRange.UtcStart, timeInfo.UtcRange.UtcEnd), options.HasMore, page)); } return(OkWithResourceLinks(stacks, options.HasMore && !NextPageExceedsSkipLimit(page, limit), page)); }
public IHttpActionResult GetById(string id, string filter = null, string time = null, string offset = null) { var model = GetModel(id); if (model == null) { return(NotFound()); } var timeInfo = GetTimeInfo(time, offset); var validationResult = QueryValidator.Validate(filter); if (!validationResult.IsValid) { return(BadRequest(validationResult.Message)); } var systemFilter = GetAssociatedOrganizationsFilter(_organizationRepository, validationResult.UsesPremiumFeatures, HasOrganizationOrProjectFilter(filter)); return(OkWithLinks(model, GetEntityResourceLink(_repository.GetPreviousEventId(model, systemFilter, filter, timeInfo.UtcRange.Start, timeInfo.UtcRange.End), "previous"), GetEntityResourceLink(_repository.GetNextEventId(model, systemFilter, filter, timeInfo.UtcRange.Start, timeInfo.UtcRange.End), "next"), GetEntityResourceLink <Stack>(model.StackId, "parent"))); }
public Task <ValidationResult> Handle(Query query, CancellationToken cancellationToken) { return(Task.FromResult(queryValidator.Validate(query))); }
public IHttpActionResult Validate(string query) { return(Ok(QueryValidator.Validate(query))); }