private void buildAsyncDaemonAggregation() { var daemonBuilderIsAsync = _applyMethods.IsAsync || _createMethods.IsAsync || _shouldDeleteMethods.IsAsync; var baseType = (daemonBuilderIsAsync ? typeof(AsyncDaemonAggregationBase <,>) : typeof(SyncDaemonAggregationBase <,>)) .MakeGenericType(typeof(T), _aggregateMapping.IdType); _asyncDaemonType = _assembly.AddType(GetType().Name.Sanitize() + "AsyncDaemonAggregation", baseType); _asyncDaemonType.AllInjectedFields.Add(new InjectedField(_storageType)); var injectedField = new InjectedField(GetType()); _asyncDaemonType.AllInjectedFields.Add(injectedField); // Build the create method _createMethods.BuildCreateMethod(_asyncDaemonType, _aggregateMapping); buildDetermineOperationMethodForDaemonRunner(daemonBuilderIsAsync); buildAsyncDaemonSplitMethod(); _asyncDaemonType.Setters.AddRange(_applyMethods.Setters()); _asyncDaemonType.Setters.AddRange(_createMethods.Setters()); _asyncDaemonType.Setters.AddRange(_shouldDeleteMethods.Setters()); }
private void buildInlineAggregationType() { var inlineBaseType = typeof(AggregationRuntime <,>).MakeGenericType(typeof(T), _aggregateMapping.IdType); _inlineType = _assembly.AddType(GetType().NameInCode().Sanitize() + "InlineHandler", inlineBaseType); _createMethods.BuildCreateMethod(_inlineType, _aggregateMapping); _inlineType.AllInjectedFields.Add(new InjectedField(GetType())); var method = buildDetermineOperationMethod(); var upsertMethod = typeof(IDocumentStorage <>).MakeGenericType(typeof(T)).GetMethod("Upsert"); var upsert = new MethodCall(_storageType, upsertMethod) { ReturnAction = ReturnAction.Return }; method.Frames.Add(upsert); _inlineType.Setters.AddRange(_applyMethods.Setters()); _inlineType.Setters.AddRange(_createMethods.Setters()); _inlineType.Setters.AddRange(_shouldDeleteMethods.Setters()); }
private void buildInlineAggregationType(GeneratedAssembly assembly) { var inlineBaseType = baseTypeForAggregationRuntime(); _inlineGeneratedType = assembly.AddType(_inlineAggregationHandlerType, inlineBaseType); _createMethods.BuildCreateMethod(_inlineGeneratedType, _aggregateMapping); _inlineGeneratedType.AllInjectedFields.Add(new InjectedField(GetType())); buildApplyEventMethod(); _inlineGeneratedType.Setters.AddRange(_applyMethods.Setters()); _inlineGeneratedType.Setters.AddRange(_createMethods.Setters()); _inlineGeneratedType.Setters.AddRange(_shouldDeleteMethods.Setters()); }
private void buildInlineAggregationType() { var inlineBaseType = typeof(AggregationRuntime <,>).MakeGenericType(typeof(T), _aggregateMapping.IdType); _inlineType = _assembly.AddType(GetType().NameInCode().Sanitize() + "InlineHandler", inlineBaseType); _createMethods.BuildCreateMethod(_inlineType, _aggregateMapping); _inlineType.AllInjectedFields.Add(new InjectedField(GetType())); buildApplyEventMethod(); _inlineType.Setters.AddRange(_applyMethods.Setters()); _inlineType.Setters.AddRange(_createMethods.Setters()); _inlineType.Setters.AddRange(_shouldDeleteMethods.Setters()); }
internal static ILiveAggregator <T> Build <T>(StoreOptions options) { var mapping = options.Storage.MappingFor(typeof(T)); var assembly = new GeneratedAssembly(new GenerationRules("Marten.Generated")); var applyMethods = new ApplyMethodCollection(typeof(T), typeof(T)); // TODO -- this doesn't do very much right now. var createMethods = new CreateMethodCollection(typeof(T), typeof(T)); assembly.Generation.Assemblies.Add(typeof(IMartenSession).Assembly); assembly.Generation.Assemblies.AddRange(applyMethods.ReferencedAssemblies()); assembly.Generation.Assemblies.AddRange(createMethods.ReferencedAssemblies()); var isAsync = applyMethods.IsAsync; assembly.Namespaces.Add("System.Linq"); var liveBaseType = isAsync ? typeof(AsyncLiveAggregatorBase <>) : typeof(SyncLiveAggregatorBase <>); liveBaseType = liveBaseType.MakeGenericType(typeof(T)); var liveType = assembly.AddType(typeof(T).NameInCode().Sanitize() + "LiveAggregation", liveBaseType); var overrideMethodName = isAsync ? "BuildAsync" : "Build"; var buildMethod = liveType.MethodFor(overrideMethodName); // TODO -- use constructor functions later // TODO -- use static Create() methods // TODO -- validate that there is some way to create the aggregate buildMethod.Frames.Code("if (!events.Any()) return null;"); buildMethod.Frames.Add(new CallCreateAggregateFrame(createMethods)); buildMethod.Frames.Add(new CallApplyAggregateFrame(applyMethods) { InsideForEach = true }); buildMethod.Frames.Return(typeof(T)); createMethods.BuildCreateMethod(liveType, mapping); applyMethods.BuildApplyMethod(liveType, mapping); var assemblyGenerator = new AssemblyGenerator(); assemblyGenerator.ReferenceAssembly(typeof(IMartenSession).Assembly); assemblyGenerator.Compile(assembly); return((ILiveAggregator <T>)Activator.CreateInstance(liveType.CompiledType)); }