コード例 #1
0
 public ClassificationResponse.ClassificationResults HandleEvent(string eventTypeName,
                                                                 object eventToHandle)
 {
     if (typedEventHandlers.ContainsKey(eventTypeName))
     {
         var      eventPayloadAsJson   = eventToHandle as Newtonsoft.Json.Linq.JObject;
         object[] invocationParameters = null;
         if (null != eventPayloadAsJson)
         {
             invocationParameters = new object[] { eventPayloadAsJson.ToObject(typedEventHandlers[eventTypeName].Item1) };
         }
         else
         {
             invocationParameters = new object[] { eventToHandle };
         }
         ClassificationResponse.ClassificationResults ret = (ClassificationResponse.ClassificationResults)typedEventHandlers[eventTypeName].Item2.Invoke(this, invocationParameters);
         if (ret == ClassificationResponse.ClassificationResults.Exclude)
         {
             _wasExcluded = true;
         }
         if (ret == ClassificationResponse.ClassificationResults.Include)
         {
             _wasIncluded = true;
         }
         return(ret);
     }
     return(ClassificationResponse.ClassificationResults.Unchanged);
 }
        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));
        }
コード例 #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));
        }