Exemplo n.º 1
0
        private void buildInlineAggregationType()
        {
            var inlineBaseType =
                typeof(InlineAggregationBase <,>).MakeGenericType(typeof(T), _aggregateMapping.IdType);

            _inlineType = _assembly.AddType(GetType().NameInCode().Sanitize() + "InlineHandler", inlineBaseType);

            _createMethods.BuildCreateMethod(_inlineType, _aggregateMapping);

            _inlineType.AllInjectedFields.Add(new InjectedField(_storageType));
            _inlineType.AllInjectedFields.Add(new InjectedField(GetType()));

            var method = _inlineType.MethodFor(nameof(InlineAggregationBase <string, string> .DetermineOperation));

            // This gets you the EventSlice aggregate Id
            method.DerivedVariables.Add(Variable.For <Guid>($"slice.{nameof(EventSlice<string, string>.Id)}"));
            method.DerivedVariables.Add(Variable.For <string>($"slice.{nameof(EventSlice<string, string>.Id)}"));

            // TODO -- this is hokey. Just pass in ITenant?
            method.DerivedVariables.Add(Variable.For <ITenant>($"(({typeof(IMartenSession).FullNameInCode()})session).{nameof(IMartenSession.Tenant)}"));
            method.DerivedVariables.Add(Variable.For <IEvent>("@event"));
            method.DerivedVariables.Add(Variable.For <IMartenSession>($"({typeof(IMartenSession).FullNameInCode()})session"));
            method.DerivedVariables.Add(Variable.For <IQuerySession>("session"));
            method.DerivedVariables.Add(Variable.For <IAggregateProjection>(nameof(InlineAggregationBase <string, string> .Projection)));

            var sliceType =
                typeof(EventSlice <,>).MakeGenericType(_aggregateMapping.DocumentType, _aggregateMapping.IdType);

            if (DeleteEvents.Any())
            {
                method.Frames.Code($"if (Projection.{nameof(MatchesAnyDeleteType)}({{0}})) return {{1}}.{nameof(IDocumentStorage<string, string>.DeleteForId)}({{2}});", new Use(sliceType), new Use(_storageType), new Use(_aggregateMapping.IdType));
            }

            var createFrame = new CallCreateAggregateFrame(_createMethods);

            method.Frames.Add(new InitializeLiveAggregateFrame(typeof(T), _aggregateMapping.IdType, createFrame));

            method.Frames.Add(new MethodCall(_storageType, "SetIdentity"));

            var handlers = MethodCollection.AddEventHandling(typeof(T), _aggregateMapping, _applyMethods, _shouldDeleteMethods);
            var iterate  = new ForEachEventFrame((IReadOnlyList <Frame>)handlers);

            method.Frames.Add(iterate);

            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());
        }
Exemplo n.º 2
0
 public void Post(DeleteEvents request)
 {
     try
     {
         eventRepository.EraseAll(request.EventIds);
         RequestContext.RemoveFromCache(Cache, keyBuilder.Build(request, x => x.EventIds).ToString());
     }
     catch (InvalidOperationException ex)
     {
         logger.Error(ex.ToString());
         throw;
     }
     catch (ApplicationException ex)
     {
         logger.Error(ex.ToString());
         throw;
     }
     catch (Exception ex)
     {
         logger.Error(ex.ToString()); 
         throw;
     }
 }
Exemplo n.º 3
0
 public IAggregationSteps <T> DeleteEvent <TEvent>() where TEvent : class
 {
     DeleteEvents.Add(typeof(TEvent));
     return(this);
 }
Exemplo n.º 4
0
 public AggregateProjection <T> DeleteEvent <TEvent>() where TEvent : class
 {
     DeleteEvents.Add(typeof(TEvent));
     return(this);
 }