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); }))); }
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); }))); }
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); }))); }
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); }))); }
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); }
private static ActivityView BuildCancellationScopeView(CancellationScope source) { string activityId = ObjectIdManager.GetId(source); var view = new CancellationScopeView(activityId) { ActivityName = source.DisplayName, }; return(view); }
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); }
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); }
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)); }
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()); }
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); })); }
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); }); }
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); }
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)); }
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)); }
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)); }