Пример #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 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);
     })));
 }
Пример #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 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);
     })));
 }
Пример #5
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);
     });
 }
Пример #6
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);
        }
Пример #7
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);
     }));
 }
Пример #8
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));
 }