public void GroupByStructureFieldTest() { using (var session = Domain.OpenSession()) using (var logger = new QueryLogger(session)) using (var transaction = session.OpenTransaction()) { var expectedCounts = Query.All <Product>() .GroupBy(g => g.Price) .AsEnumerable() .Select(g => new { g.Key, Cnt = g.Count() }) .ToList(); using (logger.Attach()) { var x = Query.All <Product>() .GroupBy(g => g.Price) .Select(g => new { g.Key, Cnt = g.Count() }); foreach (var e in x) { var entry = expectedCounts.FirstOrDefault(i => i.Key == e.Key); Assert.That(entry, Is.Not.Null); Assert.That(e.Cnt, Is.EqualTo(entry.Cnt)); } } } }
public void ConfigureServices(IServiceCollection services) { // Init low-level DB singleton InitDB(config, loggerFactory, true); // Application-specific singletons. services.AddSingleton(new CountryResolver(config["ipv4FileName"])); PageProvider pageProvider = new PageProvider(loggerFactory, config["privatePagesFolder"], env.IsDevelopment(), mut, config["baseUrl"]); services.AddSingleton(pageProvider); services.AddSingleton(new LangRepo(config["uniHanziFileName"])); services.AddSingleton(new SqlDict(loggerFactory, mut)); Emailer emailer = new Emailer(config); services.AddSingleton(emailer); if (mut == Mutation.CHD) { services.AddSingleton(new Sphinx(loggerFactory, config["perlBin"], config["sphinxScript"], config["corpusBinFileName"])); } // These below have a shutdown action, so we store them in a member too. auth = new Auth(mut, loggerFactory, config, emailer, pageProvider); services.AddSingleton(auth); qlog = new QueryLogger(config["queryLogFileName"], config["hwriteLogFileName"]); services.AddSingleton(qlog); // MVC for serving pages and REST services.AddMvc(); // Configuration singleton services.AddSingleton <IConfiguration>(sp => { return(config); }); }
public void GroupByAnonymousTypeWithPersistentAndNonNullableFielsTest() { using (var session = Domain.OpenSession()) using (var logger = new QueryLogger(session)) using (var transaction = session.OpenTransaction()) { var expectedCounts = Query.All <Product>() .GroupBy(g => new { Battery = g.Battery, Description = g.Name }) .AsEnumerable() .Select( g => new { g.Key, Cnt = g.Count() }) .ToList(); using (logger.Attach()) { var x = Query.All <Product>() .GroupBy(g => new { Battery = g.Battery, Description = g.Name }) .Select(g => new { g.Key, Cnt = g.Count() }); foreach (var e in x) { var entry = expectedCounts.FirstOrDefault(i => i.Key.Battery == e.Key.Battery && i.Key.Description == e.Key.Description); Assert.That(entry, Is.Not.Null); Assert.That(e.Cnt, Is.EqualTo(entry.Cnt)); } } } }
/// <summary> /// Ctor: init controller within app environment. /// </summary> public SmartsController(CountryResolver cres, LangRepo langRepo, SqlDict dict, QueryLogger qlog, IConfiguration config) { this.cres = cres; this.langRepo = langRepo; this.dict = dict; this.qlog = qlog; }
/// <summary> /// Ctor: Infuse app services. /// </summary> /// <remarks> /// Default null values make controller accessible to <see cref="IndexController"/>. /// That way, functionality is limited to serving static pages. /// </remarks> public DynpageController(PageProvider pageProvider, IConfiguration config, ILoggerFactory loggerFactory, Auth auth, SqlDict dict, CountryResolver cres, QueryLogger qlog, Sphinx sphinx, LangRepo langRepo) { this.cres = cres; this.pageProvider = pageProvider; this.dict = dict; this.sphinx = sphinx; this.qlog = qlog; this.config = config; this.logger = loggerFactory.CreateLogger("DynpageController"); this.auth = auth; this.langRepo = langRepo; }
private void UpdateQueryLoggerSettings() { // This method depends on any log settings having been updated before hand, via updateLogSettings. // The only dynamic settings here are log_queries, and log_queries_threshold which is read by the // ConfiguredQueryLogger constructor. We can add more in the future, though. The various content settings // are prime candidates. if (_config.get(GraphDatabaseSettings.log_queries)) { _currentLog = new ConfiguredQueryLogger(_log, _config); } else { _currentLog = NO_LOG; } }
FieldType BuildQueryField <TSource, TReturn>( Type?itemGraphType, string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IQueryable <TReturn> >?resolve, IEnumerable <QueryArgument>?arguments, string?description) where TReturn : class { Guard.AgainstWhiteSpace(nameof(name), name); var hasId = keyNames.ContainsKey(typeof(TReturn)); var fieldType = new FieldType { Name = name, Description = description, Type = MakeListGraphType <TReturn>(itemGraphType), Arguments = ArgumentAppender.GetQueryArguments(arguments, hasId, true), }; if (resolve is not null) { fieldType.Resolver = new AsyncFieldResolver <TSource, IEnumerable <TReturn> >( async context => { var fieldContext = BuildContext(context); var names = GetKeyNames <TReturn>(); var query = resolve(fieldContext); if (disableTracking) { query = query.AsNoTracking(); } query = includeAppender.AddIncludes(query, context); query = query.ApplyGraphQlArguments(context, names, true); QueryLogger.Write(query); var list = await query .ToListAsync(context.CancellationToken); return(await fieldContext.Filters.ApplyFilter(list, context.UserContext)); }); } return(fieldType); }
static async Task <Connection <TItem> > Range <TSource, TItem>( IQueryable <TItem> list, int skip, int take, int count, IResolveFieldContext <TSource> context, Filters filters, CancellationToken cancellation) where TItem : class { var page = list.Skip(skip).Take(take); QueryLogger.Write(page); IEnumerable <TItem> result = await page.ToListAsync(cancellation); result = await filters.ApplyFilter(result, context.UserContext); cancellation.ThrowIfCancellationRequested(); return(Build(skip, take, count, result)); }
public async Task LogQuery() { string?queryText = null; QueryLogger.Enable(s => queryText = s); var query = @" { parentEntities (where: [ {path: 'Property', comparison: startsWith, value: 'Valu'} {path: 'Property', comparison: endsWith, value: 'ue3'} ] ) { property } }"; var entity1 = new ParentEntity { Property = "Value1" }; var entity2 = new ParentEntity { Property = "Value2" }; var entity3 = new ParentEntity { Property = "Value3" }; await using var database = await sqlInstance.Build(); await RunQuery(database, query, null, null, false, new object[] { entity1, entity2, entity3 }); Assert.NotNull(queryText); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldLogRuntime() public virtual void ShouldLogRuntime() { // given AssertableLogProvider logProvider = new AssertableLogProvider(); IDictionary <string, object> @params = new Dictionary <string, object>(); @params["ages"] = Arrays.asList(41, 42, 43); ExecutingQuery query = query(_session_1, "TestUser", QUERY_4, @params, emptyMap()); Config config = Config.defaults(); config.Augment(GraphDatabaseSettings.log_queries_parameter_logging_enabled, "true"); config.Augment(GraphDatabaseSettings.log_queries_runtime_logging_enabled, "true"); QueryLogger queryLogger = queryLogger(logProvider, config); // when _clock.forward(11, TimeUnit.MILLISECONDS); query.CompilationCompleted(new CompilerInfo("magic", "quantum", Collections.emptyList()), null); queryLogger.Success(query); // then string expectedSessionString = SessionConnectionDetails(_session_1, "TestUser"); logProvider.AssertExactly(inLog(this.GetType()).info(format("%d ms: %s - %s - %s - {}", 11L, expectedSessionString, QUERY_4, "{ages: [41, 42, 43]} - runtime=quantum"))); }
public void SetUp() { _mockLog = new Mock <ILog>(); _logger = new QueryLogger(_mockLog.Object); }
/// <summary> /// Ctor: init controller within app environment. /// </summary> public CorpusController(Sphinx sphinx, QueryLogger qlog, CountryResolver cres) { this.sphinx = sphinx; this.qlog = qlog; this.cres = cres; }
FieldType BuildSingleField <TSource, TReturn>( string name, Func <ResolveEfFieldContext <TDbContext, TSource>, IQueryable <TReturn> > resolve, Func <ResolveEfFieldContext <TDbContext, TSource>, TReturn, Task>?mutate, IEnumerable <QueryArgument>?arguments, Type?graphType, bool nullable, string?description) where TReturn : class { Guard.AgainstWhiteSpace(nameof(name), name); graphType ??= GraphTypeFinder.FindGraphType <TReturn>(nullable); var hasId = keyNames.ContainsKey(typeof(TReturn)); return(new() { Name = name, Type = graphType, Description = description, Arguments = ArgumentAppender.GetQueryArguments(arguments, hasId, false), Resolver = new AsyncFieldResolver <TSource, TReturn?>( async context => { var efFieldContext = BuildContext(context); var names = GetKeyNames <TReturn>(); var query = resolve(efFieldContext); if (disableTracking) { query = query.AsNoTracking(); } query = includeAppender.AddIncludes(query, context); query = query.ApplyGraphQlArguments(context, names, false); QueryLogger.Write(query); var single = await query.SingleOrDefaultAsync(context.CancellationToken); if (single is not null) { if (await efFieldContext.Filters.ShouldInclude(context.UserContext, single)) { if (mutate is not null) { await mutate.Invoke(efFieldContext, single); } return single; } } if (nullable) { return null; } throw new ExecutionError("Not found"); }) }); }