Ejemplo n.º 1
0
 public void HandleSnapshot(Any anySnapshot, ISnapshotContext context)
 {
     Unwrap(() =>
     {
         var snapshot = AnySupport.Decode(anySnapshot);
         if (!CurrentBehaviors.Any(behavior => BehaviorReflectionCache.GetOrAdd(behavior.GetType())
                                   .GetSnapshotHandler(snapshot.GetType())
                                   .Match(handler =>
         {
             var active = true;
             var ctx = new SnapshotBehaviorContext(context, behaviors =>
             {
                 // TODO: Check sequence number override on this context is set correctly.
                 // ReSharper disable once AccessToModifiedClosure
                 if (!active)
                 {
                     throw new InvalidOperationException("Context is not active!");
                 }
                 CurrentBehaviors = ValidateBehaviors(behaviors).ToArray();
             });
             handler.Invoke(behavior, snapshot, ctx);
             active = false;
             return(true);
         }, () => false))
             )
         {
             throw new CloudStateException(
                 $"No snapshot handler found for snapshot [{snapshot.GetType()}] on any of the current behaviors [{BehaviorsString}]"
                 );
         }
     });
 }
Ejemplo n.º 2
0
 /// <summary>
 /// References the <see cref="BehaviorReflectionCache"/> to get or
 /// set the behavior reflection based on the resolved methods known
 /// to the <see cref="AttributeBasedEntityHandlerFactory"/>.
 /// </summary>
 /// <param name="behavior"></param>
 /// <returns></returns>
 private EventBehaviorReflection GetCachedBehaviorReflection(object behavior)
 {
     return(BehaviorReflectionCache.GetOrAdd(behavior.GetType()));
 }