コード例 #1
0
 public static Step BeginReadBackward(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     int fromEventNumber,
     int maxCount,
     bool resolveLinks,
     IPrincipal principal,
     Action <ClientMessage.ReadStreamEventsBackwardCompleted> handler)
 {
     return
         (steps =>
          cancellationScope.Register(
              ioDispatcher.ReadBackward(
                  streamId,
                  fromEventNumber,
                  maxCount,
                  resolveLinks,
                  principal,
                  response =>
     {
         if (cancellationScope.Cancelled(response.CorrelationId))
         {
             return;
         }
         handler(response);
         Run(steps);
     })));
 }
コード例 #2
0
 private static void WriteEventsWithRetry(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     long expectedVersion,
     ClaimsPrincipal principal,
     Event[] events,
     Action <ClientMessage.WriteEventsCompleted> handler,
     IEnumerator <Step> steps)
 {
     PerformWithRetry(
         ioDispatcher,
         handler,
         steps,
         expectedVersion == ExpectedVersion.Any,
         TimeSpan.FromMilliseconds(100),
         action =>
         cancellationScope.Register(
             ioDispatcher.WriteEvents(
                 streamId,
                 expectedVersion,
                 events,
                 principal,
                 response => {
         if (cancellationScope.Cancelled(response.CorrelationId))
         {
             return;
         }
         action(response, response.Result);
     })));
 }
コード例 #3
0
 private static void DeleteStreamWithRetry(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     int expectedVersion,
     bool hardDelete,
     IPrincipal principal,
     Action <ClientMessage.DeleteStreamCompleted> handler,
     IEnumerator <Step> steps)
 {
     PerformWithRetry(
         ioDispatcher,
         handler,
         steps,
         expectedVersion == ExpectedVersion.Any,
         TimeSpan.FromMilliseconds(100),
         action =>
         cancellationScope.Register(
             ioDispatcher.DeleteStream(
                 streamId,
                 expectedVersion,
                 hardDelete,
                 principal,
                 response =>
     {
         if (cancellationScope.Cancelled(response.CorrelationId))
         {
             return;
         }
         action(response, response.Result);
     })));
 }
コード例 #4
0
 private static void UpdateStreamAclWithRetry(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     long expectedVersion,
     ClaimsPrincipal principal,
     StreamMetadata metadata,
     Action <ClientMessage.WriteEventsCompleted> handler,
     IEnumerator <Step> steps)
 {
     PerformWithRetry(
         ioDispatcher,
         handler,
         steps,
         expectedVersion == ExpectedVersion.Any,
         TimeSpan.FromMilliseconds(100),
         action =>
         cancellationScope.Register(
             ioDispatcher.WriteEvents(
                 SystemStreams.MetastreamOf(streamId),
                 expectedVersion,
                 new[] {
         new Event(Guid.NewGuid(), SystemEventTypes.StreamMetadata, true, metadata.ToJsonBytes(),
                   null)
     },
                 principal,
                 response => {
         if (cancellationScope.Cancelled(response.CorrelationId))
         {
             return;
         }
         action(response, response.Result);
     })));
 }
コード例 #5
0
        public void CancellationScopeInPick()
        {
            // CancellationScope does not have test OM
            CancellationScope cancel = new CancellationScope()
            {
                DisplayName = "TestCancellationScope",
                Body        = new TestSequence()
                {
                    Activities =
                    {
                        new TestDelay("LongDelay", new TimeSpan(0, 0, 5))
                    }
                }.ProductActivity,
                              CancellationHandler = new TestSequence()
                {
                    Activities =
                    {
                        new TestWriteLine()
                        {
                            Message = "Cancelled"
                        }
                    }
                }.ProductActivity
            };

            TestCustomActivity testCancel = TestCustomActivity <CancellationScope> .CreateFromProduct(cancel);

            testCancel.ActivitySpecificTraces.Add(
                new UnorderedTraces()
            {
                Steps =
                {
                    new UserTrace("Cancelled"),
                }
            });

            TestPick pick = new TestPick()
            {
                Branches =
                {
                    new TestPickBranch()
                    {
                        Trigger = new TestDelay("ShortDelay", new TimeSpan(0, 0, 1))
                    },
                    new TestPickBranch()
                    {
                        Trigger = testCancel
                    }
                }
            };

            ExpectedTrace expectedTrace = pick.GetExpectedTrace();

            expectedTrace.AddVerifyTypes(typeof(UserTrace));

            TestRuntime.RunAndValidateWorkflow(pick, expectedTrace);
        }
コード例 #6
0
        private static ActivityView BuildCancellationScopeView(CancellationScope source)
        {
            string activityId = ObjectIdManager.GetId(source);

            var view = new CancellationScopeView(activityId)
            {
                ActivityName = source.DisplayName,
            };

            return(view);
        }
コード例 #7
0
        public void NoCancellationShouldBehaveAsSpect()
        {
            CancellationToken ct;

            using (var cts = CancellationScope.None())
            {
                ct = cts.Token;
                AssertState(ct, canBeCancelled: false, isCancellationRequested: false);
            }

            AssertState(ct, canBeCancelled: false, isCancellationRequested: false);
        }
コード例 #8
0
        public void CancelledScopeShouldBehaveAsSpec()
        {
            CancellationToken ct;

            using (var cts = CancellationScope.Cancelled())
            {
                ct = cts.Token;
                AssertState(ct, canBeCancelled: true, isCancellationRequested: true);
            }

            AssertState(ct, canBeCancelled: true, isCancellationRequested: true);
        }
コード例 #9
0
 public static Step BeginWriteEvents(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     int expectedVersion,
     IPrincipal principal,
     Event[] events,
     Action <ClientMessage.WriteEventsCompleted> handler)
 {
     return
         (steps =>
          WriteEventsWithRetry(ioDispatcher, cancellationScope, streamId, expectedVersion, principal, events, handler, steps));
 }
コード例 #10
0
        private static ActivityInfo[] GetCancellationScopeChildren(CancellationScope activity)
        {
            var children = new List <ActivityInfo>();

            if (activity.Body != null)
            {
                children.Add(new ActivityInfo(activity.Body, activity, "Body"));
            }

            if (activity.CancellationHandler != null)
            {
                children.Add(new ActivityInfo(activity.CancellationHandler, activity, "CancellationHandler"));
            }

            return(children.ToArray());
        }
コード例 #11
0
 public static Step BeginDelay(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     TimeSpan timeout,
     Action handler)
 {
     return(steps => ioDispatcher.Delay(
                timeout,
                () => {
         if (cancellationScope.Cancelled(Guid.Empty))
         {
             return;
         }
         handler();
         Run(steps);
     }));
 }
コード例 #12
0
 public static Step BeginReadForward(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     long fromEventNumber,
     int maxCount,
     bool resolveLinks,
     IPrincipal principal,
     Action <ClientMessage.ReadStreamEventsForwardCompleted> handler,
     Action timeoutHandler)
 {
     return
         (steps =>
     {
         var corrId = Guid.NewGuid();
         cancellationScope.Register(corrId);
         ioDispatcher.ReadForward(
             streamId,
             fromEventNumber,
             maxCount,
             resolveLinks,
             principal,
             response =>
         {
             if (cancellationScope.Cancelled(response.CorrelationId))
             {
                 return;
             }
             handler(response);
             Run(steps);
         },
             () =>
         {
             if (cancellationScope.Cancelled(corrId))
             {
                 return;
             }
             timeoutHandler();
             Run(steps);
         },
             corrId);
     });
 }
コード例 #13
0
        public static bool TryCancelScope(this tTask task)
        {
            if (task.IsCanceled)
            {
                return(true);
            }
            else if (task.IsCompleted)
            {
                return(false);
            }

            CancellationScope scope;

            if (CancellationScope.TryGet(task, out scope))
            {
                return(scope.TryCancel());
            }

            return(false);
        }
コード例 #14
0
 public static Step BeginUpdateStreamAcl(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     int expectedVersion,
     IPrincipal principal,
     StreamMetadata metadata,
     Action <ClientMessage.WriteEventsCompleted> handler)
 {
     return
         (steps =>
          UpdateStreamAclWithRetry(
              ioDispatcher,
              cancellationScope,
              streamId,
              expectedVersion,
              principal,
              metadata,
              handler,
              steps));
 }
コード例 #15
0
 public static Step BeginDeleteStream(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     int expectedVersion,
     bool hardDelete,
     IPrincipal principal,
     Action <ClientMessage.DeleteStreamCompleted> handler)
 {
     return
         (steps =>
          DeleteStreamWithRetry(
              ioDispatcher,
              cancellationScope,
              streamId,
              expectedVersion,
              hardDelete,
              principal,
              handler,
              steps));
 }
コード例 #16
0
 public static Step BeginSubscribeAwake(
     this IODispatcher ioDispatcher,
     CancellationScope cancellationScope,
     string streamId,
     TFPos from,
     Action <IODispatcherDelayedMessage> handler,
     Guid?correlationId = null)
 {
     return(steps => ioDispatcher.SubscribeAwake(
                streamId,
                @from,
                message => {
         if (cancellationScope.Cancelled(message.CorrelationId))
         {
             return;
         }
         handler(message);
         Run(steps);
     },
                correlationId));
 }