public async Task <ClassificationResponse> Classify <TClassification>(DateTime?asOfDate = null) where TClassification : IClassification, new()
        {
            TClassification classificationToRun = new TClassification();

            ClassificationResponse.ClassificationResults ret = ClassificationResponse.ClassificationResults.Unchanged;

            if (null != eventStreamReader)
            {
                foreach (IEventContext wrappedEvent in await eventStreamReader.GetEventsWithContext(effectiveDateTime: asOfDate))
                {
                    classificationToRun.OnEventRead(wrappedEvent.SequenceNumber, null);


                    if (classificationToRun.HandlesEventType(wrappedEvent.EventInstance.EventTypeName))
                    {
                        var stepResult = classificationToRun.HandleEvent(wrappedEvent.EventInstance.EventTypeName, wrappedEvent.EventInstance.EventPayload);
                        if (stepResult != ClassificationResponse.ClassificationResults.Unchanged)
                        {
                            // The classification state changed so store it as the current result
                            ret = stepResult;
                        }
                    }

                    // mark the event as handled
                    classificationToRun.MarkEventHandled(wrappedEvent.SequenceNumber);
                }
            }

            return(new ClassificationResponse(ret, classificationToRun.CurrentSequenceNumber));
        }
Esempio n. 2
0
        public async Task <TProjection> Process <TProjection>(TProjection projectionToRun, DateTime?asOfDate = null) where TProjection : IProjection
        {
            if (null != eventStreamReader)
            {
                if (projectionToRun == null)
                {
                    throw new ArgumentException("Projection to run must not be null", nameof(projectionToRun));
                }

                foreach (IEventContext wrappedEvent in await eventStreamReader.GetEventsWithContext(
                             effectiveDateTime: asOfDate,
                             StartingSequenceNumber:  projectionToRun.CurrentSequenceNumber))
                {
                    projectionToRun.OnEventRead(wrappedEvent.SequenceNumber, null);


                    if (projectionToRun.HandlesEventType(wrappedEvent.EventInstance.EventTypeName))
                    {
                        projectionToRun.HandleEvent(wrappedEvent.EventInstance.EventTypeName, wrappedEvent.EventInstance.EventPayload);
                    }

                    // mark the event as handled
                    projectionToRun.MarkEventHandled(wrappedEvent.SequenceNumber);
                }
            }

            return(projectionToRun);
        }
Esempio n. 3
0
        public async Task <ClassificationResponse> Classify(IClassification classificationToRun, DateTime?asOfDate = null)
        {
            ClassificationResponse.ClassificationResults ret = ClassificationResponse.ClassificationResults.Unchanged;

            bool wasEverIncluded = false;
            bool wasEverExcluded = false;

            if (null != eventStreamReader)
            {
                foreach (IEventContext wrappedEvent in await eventStreamReader.GetEventsWithContext(effectiveDateTime: asOfDate))
                {
                    classificationToRun.OnEventRead(wrappedEvent.SequenceNumber, null);


                    if (classificationToRun.HandlesEventType(wrappedEvent.EventInstance.EventTypeName))
                    {
                        var stepResult = classificationToRun.HandleEvent(wrappedEvent.EventInstance.EventTypeName, wrappedEvent.EventInstance.EventPayload);
                        if (stepResult != ClassificationResponse.ClassificationResults.Unchanged)
                        {
                            // The classification state changed so store it as the current result
                            ret = stepResult;
                            if (ret == ClassificationResponse.ClassificationResults.Include)
                            {
                                wasEverIncluded = true;
                            }
                            if (ret == ClassificationResponse.ClassificationResults.Exclude)
                            {
                                wasEverIncluded = true;
                            }
                        }
                    }

                    // mark the event as handled
                    classificationToRun.MarkEventHandled(wrappedEvent.SequenceNumber);
                }
            }
            return(new ClassificationResponse(ret,
                                              classificationToRun.CurrentSequenceNumber,
                                              classificationToRun.CurrentAsOfDate,
                                              wasEverIncluded,
                                              wasEverExcluded,
                                              Parameters));
        }
Esempio n. 4
0
        public async Task<TProjection> Process<TProjection>(TProjection projectionToRun, DateTime? asOfDate = null) where TProjection : IProjection
        {

            if (null != eventStreamReader)
            {
                foreach (IEventContext wrappedEvent in await eventStreamReader.GetEventsWithContext(effectiveDateTime: asOfDate))
                {

                    projectionToRun.OnEventRead(wrappedEvent.SequenceNumber, null);


                    if (projectionToRun.HandlesEventType(wrappedEvent.EventInstance.EventTypeName))
                    {
                        projectionToRun.HandleEvent(wrappedEvent.EventInstance.EventTypeName, wrappedEvent.EventInstance.EventPayload);
                    }

                    // mark the event as handled
                    projectionToRun.MarkEventHandled(wrappedEvent.SequenceNumber);
                }
            }

            return projectionToRun;
        }