public Task AttachPreBuiltTypes(GenerationRules rules, Assembly assembly, IServiceProvider services)
        {
            foreach (var mapping in Storage.AllDocumentMappings)
            {
                var builder = typeof(ProviderBuilder <>).CloseAndBuildAs <IProviderBuilder>(mapping.DocumentType);
                builder.BuildAndStore(assembly, mapping, this);
            }

            if (_compiledQueryTypes.Any())
            {
                using var session = new LightweightSession(this);
                foreach (var compiledQueryType in _compiledQueryTypes)
                {
                    var plan    = QueryCompiler.BuildPlan(session, compiledQueryType, this);
                    var builder = new CompiledQuerySourceBuilder(plan, this);
                    var source  = builder.CreateFromPreBuiltType(assembly);

                    if (source == null)
                    {
                        Console.WriteLine("Could not find a pre-built compiled query source type for compiled query type " + compiledQueryType.FullNameInCode());
                    }
                    else
                    {
                        _querySources = _querySources.AddOrUpdate(compiledQueryType, source);
                    }
                }
            }

            return(Task.CompletedTask);
        }
Пример #2
0
        internal ICompiledQuerySource GetCompiledQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query, IMartenSession session)
        {
            if (_querySources.TryFind(query.GetType(), out var source))
            {
                return(source);
            }

            var plan = QueryCompiler.BuildPlan(session, query, this);

            source        = new CompiledQuerySourceBuilder(plan, this).Build();
            _querySources = _querySources.AddOrUpdate(query.GetType(), source);

            return(source);
        }
Пример #3
0
        public string SourceCodeForCompiledQuery(Type type)
        {
            if (!type.Closes(typeof(ICompiledQuery <,>)))
            {
                throw new ArgumentOutOfRangeException(nameof(type), "Not a compiled query type");
            }

            var assembly = new GeneratedAssembly(new GenerationRules(SchemaConstants.MartenGeneratedNamespace));

            using var session = _store.LightweightSession();
            var plan    = QueryCompiler.BuildPlan((IMartenSession)session, type, _store.Options);
            var builder = new CompiledQuerySourceBuilder(plan, _store.Options);

            var(sourceType, handlerType) = builder.AssemblyType(assembly);

            return(assembly.GenerateCode());
        }
Пример #4
0
        internal ICompiledQuerySource GetCompiledQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query, IMartenSession session)
        {
            if (_querySources.TryFind(query.GetType(), out var source))
            {
                return(source);
            }

            if (typeof(TOut).CanBeCastTo <Task>())
            {
                throw InvalidCompiledQueryException.ForCannotBeAsync(query.GetType());
            }

            var plan = QueryCompiler.BuildPlan(session, query, this);

            source        = new CompiledQuerySourceBuilder(plan, this).Build();
            _querySources = _querySources.AddOrUpdate(query.GetType(), source);

            return(source);
        }
Пример #5
0
        public Task AttachPreBuiltTypes(GenerationRules rules, Assembly assembly, IServiceProvider services)
        {
            foreach (var mapping in Storage.AllDocumentMappings)
            {
                var builder = typeof(ProviderBuilder <>).CloseAndBuildAs <IProviderBuilder>(mapping.DocumentType);
                builder.BuildAndStore(assembly, mapping, this);
            }

            if (_compiledQueryTypes.Any())
            {
                using var session = new LightweightSession(this);
                foreach (var compiledQueryType in _compiledQueryTypes)
                {
                    var plan    = QueryCompiler.BuildPlan(session, compiledQueryType, this);
                    var builder = new CompiledQuerySourceBuilder(plan, this);
                    var source  = builder.CreateFromPreBuiltType(assembly);

                    _querySources = _querySources.AddOrUpdate(compiledQueryType, source);
                }
            }

            return(Task.CompletedTask);
        }
Пример #6
0
        public IServiceVariableSource AssemblyTypes(GenerationRules rules, GeneratedAssembly assembly)
        {
            // This is important to ensure that all the possible DocumentMappings exist
            // first
            Storage.BuildAllMappings();
            foreach (var mapping in Storage.AllDocumentMappings)
            {
                var builder = new DocumentPersistenceBuilder(mapping, this);
                builder.AssemblyTypes(assembly);
            }

            if (_compiledQueryTypes.Any())
            {
                using var session = new LightweightSession(this);
                foreach (var compiledQueryType in _compiledQueryTypes)
                {
                    var plan    = QueryCompiler.BuildPlan(session, compiledQueryType, this);
                    var builder = new CompiledQuerySourceBuilder(plan, this);
                    builder.AssemblyType(assembly);
                }
            }

            return(null);
        }