Beispiel #1
0
        public override ValueTask ApplyChangesAsync(DocumentSessionBase session, EventSlice <CustomAggregate, int> slice, CancellationToken cancellation,
                                                    ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline)
        {
            var aggregate = slice.Aggregate ?? new CustomAggregate {
                Id = slice.Id
            };

            foreach (var @event in slice.Events())
            {
                if (@event.Data is CustomEvent e)
                {
                    switch (e.Letter)
                    {
                    case 'a':
                        aggregate.ACount++;
                        break;

                    case 'b':
                        aggregate.BCount++;
                        break;

                    case 'c':
                        aggregate.CCount++;
                        break;

                    case 'd':
                        aggregate.DCount++;
                        break;
                    }
                }
            }

            session.Store(aggregate);
            return(new ValueTask());
        }
Beispiel #2
0
        public async ValueTask ApplyChangesAsync(DocumentSessionBase session,
                                                 EventSlice <TDoc, TId> slice, CancellationToken cancellation,
                                                 ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline)
        {
            if (Projection.MatchesAnyDeleteType(slice))
            {
                var operation = Storage.DeleteForId(slice.Id, slice.Tenant.TenantId);
                session.QueueOperation(operation);
                return;
            }

            var aggregate = slice.Aggregate;

            if (slice.Aggregate == null && lifecycle == ProjectionLifecycle.Inline)
            {
                aggregate = await Storage.LoadAsync(slice.Id, session, cancellation).ConfigureAwait(false);
            }

            // Does the aggregate already exist before the events are applied?
            var exists = aggregate != null;

            foreach (var @event in slice.Events())
            {
                try
                {
                    aggregate = await ApplyEvent(session, slice, @event, aggregate, cancellation).ConfigureAwait(false);
                }
                catch (MartenCommandException)
                {
                    throw;
                }
                catch (NpgsqlException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    throw new ApplyEventException(@event, e);
                }
            }

            if (aggregate != null)
            {
                Storage.SetIdentity(aggregate, slice.Id);
            }

            // Delete the aggregate *if* it existed prior to these events
            if (aggregate == null)
            {
                if (exists)
                {
                    var operation = Storage.DeleteForId(slice.Id, slice.Tenant.TenantId);
                    session.QueueOperation(operation);
                }

                return;
            }

            session.QueueOperation(Storage.Upsert(aggregate, session, slice.Tenant.TenantId));
        }
        public async Task <IStorageOperation> DetermineOperation(DocumentSessionBase session,
                                                                 EventSlice <TDoc, TId> slice, CancellationToken cancellation, ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline)
        {
            var aggregate = slice.Aggregate;

            if (slice.Aggregate == null && lifecycle == ProjectionLifecycle.Inline)
            {
                aggregate = await Storage.LoadAsync(slice.Id, session, cancellation);
            }

            var exists = aggregate != null;

            foreach (var @event in slice.Events)
            {
                aggregate = await ApplyEvent(session, slice, @event, aggregate, cancellation);
            }

            if (aggregate != null)
            {
                Storage.SetIdentity(aggregate, slice.Id);
            }

            if (aggregate == null)
            {
                return(exists ? Storage.DeleteForId(slice.Id, slice.Tenant) : null);
            }

            return(Storage.Upsert(aggregate, session, slice.Tenant));
        }
Beispiel #4
0
        public async Task <IStorageOperation?> DetermineOperation(DocumentSessionBase session,
                                                                  EventSlice <TDoc, TId> slice, CancellationToken cancellation, ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline)
        {
            var aggregate = slice.Aggregate;

            if (slice.Aggregate == null && lifecycle == ProjectionLifecycle.Inline)
            {
                aggregate = await Storage.LoadAsync(slice.Id, session, cancellation).ConfigureAwait(false);
            }

            var exists = aggregate != null;

            foreach (var @event in slice.Events())
            {
                try
                {
                    aggregate = await ApplyEvent(session, slice, @event, aggregate, cancellation).ConfigureAwait(false);
                }
                catch (MartenCommandException)
                {
                    throw;
                }
                catch (NpgsqlException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    throw new ApplyEventException(@event, e);
                }
            }

            if (aggregate != null)
            {
                Storage.SetIdentity(aggregate, slice.Id);
            }

            if (aggregate == null)
            {
                return(exists ? Storage.DeleteForId(slice.Id, slice.Tenant) : null);
            }

            return(Storage.Upsert(aggregate, session, slice.Tenant));
        }
Beispiel #5
0
        public void onRealTimeEvent(EventSlice.Interfaces.RealTimeEvent rte)
        {
            if (rte.GetType() == typeof(ReceiverSlice.RealTimeEvents.RunStateChangedReceiver))
            {
                ReceiverSlice.Receiver receiver = ((ReceiverSlice.RealTimeEvents.RunStateChangedReceiver)rte)["receiver"];
                ReceiverSlice.RunState runstate = ((ReceiverSlice.RealTimeEvents.RunStateChangedReceiver)rte)["runstate"];
                if (receiversListBox.Dispatcher.CheckAccess())
                {
                    onChangeRunModeListBox(receiver, runstate);
                }
                else
                {
                    ConsoleLog.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
                    {
                        onChangeRunModeListBox(receiver, runstate);
                    }));
                }

            }
            appendToConsoleLog(rte.ToString());
        }
Beispiel #6
0
        public override ValueTask ApplyChangesAsync(DocumentSessionBase session, EventSlice <StartAndStopAggregate, Guid> slice, CancellationToken cancellation,
                                                    ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline)
        {
            var aggregate = slice.Aggregate;


            foreach (var data in slice.AllData())
            {
                switch (data)
                {
                case Start:
                    aggregate = new StartAndStopAggregate
                    {
                        // Have to assign the identity ourselves
                        Id = slice.Id
                    };
                    break;

                case Increment when aggregate is { Deleted: false } :
                    // Use explicit code to only apply this event
                    // if the aggregate already exists
                    aggregate.Increment();
                    break;
Beispiel #7
0
 public abstract ValueTask <TDoc> ApplyEvent(IQuerySession session, EventSlice <TDoc, TId> slice,
                                             IEvent evt, TDoc?aggregate,
                                             CancellationToken cancellationToken);
Beispiel #8
0
 /// <summary>
 /// The hook for the event dispatcher.
 /// </summary>
 /// <param name="rte">realtime event</param>
 public override void onRealTimeEvent(EventSlice.Interfaces.RealTimeEvent rte)
 {
 }
Beispiel #9
0
 public sui(EventSlice.Dispatcher d)
     : base(d)
 {
 }
Beispiel #10
0
        public void EnqueueDelete(EventSlice <TDoc, TId> fragment)
        {
            var deletion = _storage.DeleteForId(fragment.Id);

            _enqueueOperations.Post(deletion);
        }
 /// <summary>
 /// Apply any document changes based on the incoming slice of events to the underlying aggregate document
 /// </summary>
 /// <param name="session"></param>
 /// <param name="slice"></param>
 /// <param name="cancellation"></param>
 /// <param name="lifecycle"></param>
 /// <returns></returns>
 public abstract ValueTask ApplyChangesAsync(DocumentSessionBase session, EventSlice <TDoc, TId> slice,
                                             CancellationToken cancellation,
                                             ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline);
 /// <summary>
 /// Override to give Marten "hints" about whether the aggregate is all new based on the incoming
 /// event slice. The default implementation is always false.
 /// </summary>
 /// <param name="slice"></param>
 /// <returns></returns>
 public virtual bool IsNew(EventSlice <TDoc, TId> slice)
 {
     return(false);
 }
 public void AddToEventSliceSet(EventSlice eventSlice)
 {
     base.AddObject("EventSliceSet", eventSlice);
 }
 public static EventSlice CreateEventSlice(int ID, int eventSlice_PvPInstance, int sliceNumber, byte[] rowVersion)
 {
     EventSlice eventSlice = new EventSlice();
     eventSlice.Id = ID;
     eventSlice.EventSlice_PvPInstance = eventSlice_PvPInstance;
     eventSlice.SliceNumber = sliceNumber;
     eventSlice.RowVersion = rowVersion;
     return eventSlice;
 }
Beispiel #15
0
 public virtual bool IsNew(EventSlice <TDoc, TId> slice)
 {
     return(slice.Events().First().Version == 1);
 }
 public abstract Task <IStorageOperation> DetermineOperation(IDocumentSession session,
                                                             EventSlice <TDoc, TId> slice, CancellationToken cancellation);
Beispiel #17
0
 public override bool IsNew(EventSlice <TDoc, TId> slice)
 {
     return(false);
 }
Beispiel #18
0
 public override ValueTask ApplyChangesAsync(DocumentSessionBase session, EventSlice <CustomAggregate, int> slice, CancellationToken cancellation,
                                             ProjectionLifecycle lifecycle = ProjectionLifecycle.Inline)
 {
     throw new NotImplementedException();
 }
Beispiel #19
0
 // This is what would be generated.
 public abstract ValueTask <IStorageOperation> ResolveOperation(EventSlice <TDoc, TId> fragment);
Beispiel #20
0
 public virtual bool IsNew(EventSlice <TDoc, TId> fragment)
 {
     return(fragment.Events.First().Version == 1);
 }