private Viewer.Query.Query CreateQuery(IExecutableQuery query) { var runtime = new Mock <IRuntime>(); var priorityComparerFactory = new Mock <IPriorityComparerFactory>(); return(new Viewer.Query.Query(runtime.Object, priorityComparerFactory.Object, query)); }
private async void SetCurrentQuery(IExecutableQuery query) { Reset(); if (query == null) { return; } // highlight base directories of each pattern foreach (var pattern in query.Patterns) { var basePath = pattern.GetBasePath(); if (basePath == null) { continue; } await OpenAsync(basePath); if (_isDisposed) { return; } View.HighlightDirectory(PathUtils.Split(basePath)); } }
public Query( IRuntime runtime, IPriorityComparerFactory priorityComparerFactory, IExecutableQuery source) : this(runtime, priorityComparerFactory, source, null) { }
public static void Verify(IExecutableQuery query) { Verify( WriterFactory.CreateTextWriter(query.GetQuery()), GetDefaultNamer(), new ExecutableQueryFailure(query, GetReporter())); }
public string ToQueryString <TEntity>(IExecutableQuery <TEntity> query) where TEntity : BaseCrmEntity, new() { var queryStringBuilder = new StringBuilder(query.PluralName); if (query.Fields.Any()) { queryStringBuilder.Append("$select="); queryStringBuilder.Append(string.Join(",", query.Fields)); } if (query.Filter != null) { if (query.Fields.Any()) { queryStringBuilder.Append("&"); } queryStringBuilder.Append("$filter="); queryStringBuilder.Append(ParseFilter(query.Filter)); } if (query.Top.HasValue) { if (query.Fields.Any() || query.Filter != null) { queryStringBuilder.Append("&"); } queryStringBuilder.Append($"$top={query.Top}"); } return(queryStringBuilder.ToString()); }
private void HistoryView_GoUp(object sender, EventArgs e) { var query = _queryHistory.Current; if (query == null) { return; } // build the parent folder query IExecutableQuery nextQuery = null; foreach (var pattern in query.Patterns) { var parentPattern = pattern.GetParent(); var parentQuery = _queryFactory.CreateQuery(parentPattern.Text); if (nextQuery == null) { nextQuery = parentQuery; } else { nextQuery = _queryFactory.Union(parentQuery, nextQuery); } } if (nextQuery == null) { return; } // execute it _queryHistory.ExecuteQuery(nextQuery); }
public QueryEvaluator( IFileWatcherFactory fileWatcherFactory, ILazyThumbnailFactory thumbnailFactory, IEntityManager entities, IExecutableQuery query) { _entities = entities; _fileWatcher = fileWatcherFactory.Create(); _thumbnailFactory = thumbnailFactory; Query = query; // initialize internal structures Cancellation = new CancellationTokenSource(); Comparer = new EntityViewComparer(Query.Comparer); _backBuffer = new List <Group>(); _frontBuffer = new List <Group>(); // register event handlers _fileWatcher.Renamed += FileWatcherOnRenamed; _fileWatcher.Deleted += FileWatcherOnDeleted; _fileWatcher.Created += FileWatcherOnCreated; _entities.Deleted += EntitiesOnDeleted; _entities.Changed += EntitiesOnChanged; _entities.Moved += EntitiesOnMoved; }
/// <summary> /// Transform leaf nodes of <paramref name="node"/> query using the /// <paramref name="transformation"/> function. /// </summary> /// <param name="node">Query to transform</param> /// <param name="transformation">Transformation</param> /// <returns>New transformed query</returns> private IExecutableQuery ModifyQueryLeafs( IExecutableQuery node, Func <SimpleQuery, SimpleQuery> transformation) { for (;;) { if (node is SimpleQuery simpleQuery) { return(transformation(simpleQuery)); } else if (node is Query query) { node = query._source; continue; } var op = (BinaryQueryOperator)node; var left = ModifyQueryLeafs(op.First, transformation); if (op.GetType() == typeof(UnionQuery)) { return(new UnionQuery(left, ModifyQueryLeafs(op.Second, transformation))); } else if (op.GetType() == typeof(IntersectQuery)) { return(new IntersectQuery(left, ModifyQueryLeafs(op.Second, transformation))); } else if (op.GetType() == typeof(ExceptQuery)) { return(new ExceptQuery(left, ModifyQueryLeafs(op.Second, transformation))); } return(null); } }
public void Back_MoveInHistory() { var query = new[] { new Mock <IQuery>(), new Mock <IQuery>(), new Mock <IQuery>(), new Mock <IQuery>(), new Mock <IQuery>(), }; for (var i = 0; i < query.Length; ++i) { query[i].Setup(mock => mock.Text).Returns(i.ToString()); } IExecutableQuery current = null; var queryEvents = new QueryHistory(); queryEvents.QueryExecuted += (sender, args) => current = args.Query; Assert.IsNull(queryEvents.Current); queryEvents.ExecuteQuery(query[0].Object); Assert.AreEqual(query[0].Object, queryEvents.Current); Assert.AreEqual(query[0].Object, current); queryEvents.ExecuteQuery(query[1].Object); Assert.AreEqual(query[1].Object, queryEvents.Current); Assert.AreEqual(query[1].Object, current); queryEvents.Back(); Assert.AreEqual(query[0].Object, queryEvents.Current); Assert.AreEqual(query[0].Object, current); queryEvents.ExecuteQuery(query[2].Object); Assert.AreEqual(query[2].Object, queryEvents.Current); Assert.AreEqual(query[2].Object, current); queryEvents.ExecuteQuery(query[3].Object); Assert.AreEqual(query[3].Object, queryEvents.Current); Assert.AreEqual(query[3].Object, current); queryEvents.Back(); Assert.AreEqual(query[2].Object, queryEvents.Current); Assert.AreEqual(query[2].Object, current); queryEvents.Back(); Assert.AreEqual(query[0].Object, queryEvents.Current); Assert.AreEqual(query[0].Object, current); queryEvents.Back(); Assert.AreEqual(query[0].Object, queryEvents.Current); Assert.AreEqual(query[0].Object, current); queryEvents.ExecuteQuery(query[4].Object); Assert.AreEqual(query[4].Object, queryEvents.Current); Assert.AreEqual(query[4].Object, current); }
public Query( IRuntime runtime, IPriorityComparerFactory priorityComparerFactory, IExecutableQuery source, string text) { _runtime = runtime; _priorityComparerFactory = priorityComparerFactory; _source = source; _text = text; }
public bool TryExecuteQuery <T>(IExecutableQuery <T> query, out T result, out IEnumerable <string> errors) { using (var session = _sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { if (!query.TryExecute(session, out result, out errors)) { tx.Rollback(); return(false); } tx.Commit(); return(Success(out errors)); } }
public void ExecuteQuery_EmptyHistory() { var query = new Mock <IQuery>(); IExecutableQuery executed = null; var queryEvents = new QueryHistory(); queryEvents.QueryExecuted += (sender, args) => executed = args.Query; Assert.IsNull(queryEvents.Current); Assert.IsNull(executed); queryEvents.ExecuteQuery(query.Object); Assert.AreEqual(query.Object, queryEvents.Current); Assert.AreEqual(query.Object, executed); }
public override void SetUp() { base.SetUp(); _queryGeneratorMock = MockRepository.GenerateStrictMock <IDomainObjectQueryGenerator>(); _queryExecutor = new DomainObjectQueryExecutor(TestDomainStorageProviderDefinition, _queryGeneratorMock); _queryManagerMock = MockRepository.GenerateStrictMock <IQueryManager> (); var transaction = ClientTransactionObjectMother.CreateTransactionWithQueryManager <ClientTransaction> (_queryManagerMock); _transactionScope = transaction.EnterDiscardingScope(); _someQueryModel = QueryModelObjectMother.Create(); MockRepository.GenerateStub <IQuery>(); _someOrder = DomainObjectMother.CreateFakeObject <Order>(); _scalarExecutableQueryMock = MockRepository.GenerateStrictMock <IExecutableQuery <int> >(); _collectionExecutableQueryMock = MockRepository.GenerateStrictMock <IExecutableQuery <IEnumerable <Order> > > (); }
public async Task <IEnumerable <TEntity> > GetByQueryAsync <TEntity>(IExecutableQuery <TEntity> query) where TEntity : BaseCrmEntity, new() { var queryString = _queryBuilder.ToQueryString(query); var message = ConstructMessage(HttpMethod.Get, $"{BaseUrl}/{queryString}"); var response = await _client.SendAsync(message); var responseContent = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { throw new CrmApiClientException($"Error quering for entities") { HttpMethod = message.Method, HttpRequestUrl = message.RequestUri.OriginalString, HttpResponseStatusCode = response.StatusCode, HttpResponseBodyJson = responseContent }; } return(ParseApiResponse <TEntity>(responseContent)); }
public bool ExecuteQuery(IExecutableQuery query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } // trigger the BeforeQueryExecuted event and potentially cancel the operation var args = new BeforeQueryExecutedEventArgs(query); BeforeQueryExecuted?.Invoke(this, args); if (args.IsCanceled) { return(false); } // only modify the history if the queries differ if (Current == null || StringComparer.CurrentCultureIgnoreCase.Compare(query.Text, Current.Text) != 0) { // remove all entries in history after _historyHead var index = _history.Count - 1; while (index > _historyHead) { _history.RemoveAt(index--); } // add a new query to history and make it the current query _history.Add(query); ++_historyHead; Trace.Assert(_historyHead == _history.Count - 1); } // trigger query executed event QueryExecuted?.Invoke(this, new QueryEventArgs(query)); return(true); }
/// <summary> /// Execute given query and show all entities in the result. /// </summary> /// <param name="query">Query to show</param> public async Task LoadQueryAsync(IExecutableQuery query) { // release all resources used by the previous query DisposeQuery(); _selection.Clear(); // start the query _queryEvaluator = _queryEvaluatorFactory.Create(query); View.Query = _queryEvaluator.Query.Text; View.Items = _queryEvaluator.Update(); View.History.CanGoBackInHistory = _queryHistory.Previous != null; View.History.CanGoForwardInHistory = _queryHistory.Next != null; View.BeginLoading(); View.BeginPolling(PollingRate); try { await _queryEvaluator.RunAsync(); if (!_isDisposed) { View.UpdateItems(); } } catch (OperationCanceledException) { } finally { if (!_isDisposed) { View.EndLoading(); } } }
public static void Approve(IExecutableQuery query) { Approve(new ApprovalTextWriter(query.GetQuery()), GetDefaultNamer(), new ExecutableQueryFailure(query, GetReporter())); }
public QueryEventArgs(IExecutableQuery query) { Query = query; }
public ExecutableQueryFailure(IExecutableQuery query, IApprovalFailureReporter reporter) { this.query = query; this.reporter = reporter; }
public QueryHistoryItem(IExecutableQuery query) { Query = query ?? throw new ArgumentNullException(nameof(query)); Text = Regex.Replace(Query.Text, @"\r\n?|\n", " "); }
public IExecutableQuery Union(IExecutableQuery first, IExecutableQuery second) { return(new UnionQuery(first, second)); }
public ExceptQuery(IExecutableQuery first, IExecutableQuery second) : base(first, second) { }
protected IActionResult WrapQuery <T>(IExecutableQuery <T> query) { return(_sessionHelper.TryExecuteQuery(query, out var parents, out var errors) ? Ok(parents) : Error(errors)); }
private void ExpectCreateQueryWithFetchQueryModelBuilders <T> (QueryModel queryModel, IExecutableQuery <IEnumerable <T> > fakeResult) { var nonTrailingFetchRequest = AddFetchRequest(queryModel); var someResultOperator = AddSomeResultOperator(queryModel); var trailingFetchRequest1 = AddFetchRequest(queryModel); var trailingFetchRequest2 = AddFetchRequest(queryModel); Assert.That( queryModel.ResultOperators, Is.EqualTo(new[] { nonTrailingFetchRequest, someResultOperator, trailingFetchRequest1, trailingFetchRequest2 })); _queryGeneratorMock .Expect( mock => mock.CreateSequenceQuery <T> ( Arg <string> .Is.Anything, Arg <StorageProviderDefinition> .Is.Anything, Arg.Is(queryModel), Arg <IEnumerable <FetchQueryModelBuilder> > .Is.Anything)) .Return(fakeResult) .WhenCalled(mi => { Assert.That(queryModel.ResultOperators, Is.EqualTo(new[] { nonTrailingFetchRequest, someResultOperator })); var builders = ((IEnumerable <FetchQueryModelBuilder>)mi.Arguments[3]).ToArray(); Assert.That(builders, Has.Length.EqualTo(2)); CheckFetchQueryModelBuilder(builders[0], trailingFetchRequest2, queryModel, 3); CheckFetchQueryModelBuilder(builders[1], trailingFetchRequest1, queryModel, 2); }); }
public UnionQuery(IExecutableQuery first, IExecutableQuery second) : base(first, second) { }
public QueryEvaluator Create(IExecutableQuery query) { return(new QueryEvaluator(_fileWatcherFactory, _thumbnailFactory, _entities, query)); }
public IQuery Intersect(IExecutableQuery entities) { return(new Query(_runtime, _priorityComparerFactory, new IntersectQuery(_source, entities), _text)); }
public BeforeQueryExecutedEventArgs(IExecutableQuery query) { Query = query; }
public IntersectQuery(IExecutableQuery first, IExecutableQuery second) : base(first, second) { }
protected BinaryQueryOperator(IExecutableQuery first, IExecutableQuery second) { First = first; Second = second; }