Esempio n. 1
0
        public PollingSubscription(
            IEventStore eventStore,
            IEventSubscriber eventSubscriber,
            string?streamFilter,
            string?position)
        {
            Guard.NotNull(eventStore);
            Guard.NotNull(eventSubscriber);

            timer = new CompletionTimer(5000, async ct =>
            {
                try
                {
                    await eventStore.QueryAsync(async storedEvent =>
                    {
                        await eventSubscriber.OnEventAsync(this, storedEvent);

                        position = storedEvent.EventPosition;
                    }, streamFilter, position, ct);
                }
                catch (Exception ex)
                {
                    if (!ex.Is <OperationCanceledException>())
                    {
                        await eventSubscriber.OnErrorAsync(this, ex);
                    }
                }
            });
        }
Esempio n. 2
0
        public RuleDequeuer(RuleService ruleService, IRuleEventRepository ruleEventRepository, ISemanticLog log, IClock clock)
        {
            Guard.NotNull(ruleEventRepository, nameof(ruleEventRepository));
            Guard.NotNull(ruleService, nameof(ruleService));
            Guard.NotNull(clock, nameof(clock));
            Guard.NotNull(log, nameof(log));

            this.ruleEventRepository = ruleEventRepository;
            this.ruleService         = ruleService;

            this.clock = clock;

            this.log = log;

            requestBlock =
                new ActionBlock <IRuleEventEntity>(MakeRequestAsync,
                                                   new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 32, BoundedCapacity = 32
            });

            blockBlock =
                new TransformBlock <IRuleEventEntity, IRuleEventEntity>(x => BlockAsync(x),
                                                                        new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 1, BoundedCapacity = 1
            });

            blockBlock.LinkTo(requestBlock, new DataflowLinkOptions {
                PropagateCompletion = true
            });

            timer = new CompletionTimer(5000, QueryAsync);
        }
Esempio n. 3
0
 public AnimatedText(string text, TimeSpan?timePerCharacter = null, TimeSpan?delayTime = null)
 {
     Text                  = text;
     TimePerCharacter      = timePerCharacter ?? TimeSpan.FromMilliseconds(100);
     _characterRevealTimer = new CompletionTimer(TimePerCharacter);
     _delayTimer           = new CompletionTimer(delayTime ?? TimeSpan.Zero);
 }
Esempio n. 4
0
        public PollingSubscription(
            IEventStore eventStore,
            IEventSubscriber eventSubscriber,
            string?streamFilter,
            string?position)
        {
            Guard.NotNull(eventStore, nameof(eventStore));
            Guard.NotNull(eventSubscriber, nameof(eventSubscriber));

            timer = new CompletionTimer(5000, async ct =>
            {
                try
                {
                    await foreach (var storedEvent in eventStore.QueryAllAsync(streamFilter, position, ct: ct))
                    {
                        await eventSubscriber.OnEventAsync(this, storedEvent);

                        position = storedEvent.EventPosition;
                    }
                }
                catch (Exception ex)
                {
                    await eventSubscriber.OnErrorAsync(this, ex);
                }
            });
        }
Esempio n. 5
0
 public ProjectileBase(Guid shipGuid, Vector3 parentVelocity, Vector3 direction, float speed, TimeSpan? despawnDuration = null)
 {
     ShipGuid = shipGuid;
     direction.Normalize();
     Velocity = direction * speed + parentVelocity;
     _despawnTimer = new CompletionTimer(despawnDuration ?? TimeSpan.FromSeconds(10));
 }
Esempio n. 6
0
        private void StartPhase(int phaseIndex)
        {
            if (phaseIndex >= NumberOfPhases)
            {
                Orchestrator.PhasesComplete();
                return;
            }
            this.Update(() =>
            {
                PhaseIndex   = phaseIndex % NumberOfPhases;
                State        = PhaseManagerState.Starting;
                CurrentPhase = _phases.ElementAt(PhaseIndex);
                _startTimer  = new CompletionTimer(TimeSpan.FromSeconds(3));
#if DEBUG
                _startTimer = new CompletionTimer(TimeSpan.FromSeconds(1));
#endif
                if (CurrentPhase.Duration.HasValue)
                {
                    _phaseTimer = new CompletionTimer(CurrentPhase.Duration.Value);
                }
                else
                {
                    _phaseTimer = null;
                }
                _endedTimer = new CompletionTimer(TimeSpan.FromSeconds(3));
            });
        }
Esempio n. 7
0
        public CounterCollector(ICounterStore <T> store, int updateInterval, int maxSize = 20000)
        {
            this.store = store;

            this.maxSize = maxSize;

            timer = new CompletionTimer(updateInterval, StoreAsync, updateInterval);
        }
Esempio n. 8
0
 public BuildMode(ShipTopology topology, Planet planet)
 {
     _topology  = topology;
     State      = BuildModeState.AwaitingBegin;
     _countIn   = new CompletionTimer(TimeSpan.FromSeconds(3));
     _countDown = new CompletionTimer(TimeSpan.FromSeconds(planet == Planet.Earth ? 80 : 50));
     _countOut  = new CompletionTimer(TimeSpan.FromSeconds(5));
 }
Esempio n. 9
0
        public void Subscribe(IEventConsumer eventConsumer)
        {
            Guard.NotNull(eventConsumer, nameof(eventConsumer));

            ThrowIfDisposed();

            if (timer != null)
            {
                return;
            }

            var consumerName    = eventConsumer.Name;
            var consumerStarted = false;

            timer = new CompletionTimer(5000, async ct =>
            {
                if (!consumerStarted)
                {
                    await eventConsumerInfoRepository.CreateAsync(consumerName);

                    consumerStarted = true;
                }

                try
                {
                    var status = await eventConsumerInfoRepository.FindAsync(consumerName);

                    var position = status.Position;

                    if (status.IsResetting)
                    {
                        currentSubscription?.Dispose();
                        currentSubscription = null;

                        position = null;

                        await ResetAsync(eventConsumer);
                    }
                    else if (status.IsStopped)
                    {
                        currentSubscription?.Dispose();
                        currentSubscription = null;

                        return;
                    }

                    if (currentSubscription == null)
                    {
                        await SubscribeAsync(eventConsumer, position);
                    }
                }
                catch (Exception ex)
                {
                    log.LogFatal(ex, w => w.WriteProperty("action", "EventHandlingFailed"));
                }
            });
        }
Esempio n. 10
0
        public BackgroundRequestLogStore(IRequestLogRepository logRepository, ISemanticLog log)
        {
            Guard.NotNull(logRepository, nameof(logRepository));
            Guard.NotNull(log, nameof(log));

            this.logRepository = logRepository;
            this.log           = log;

            timer = new CompletionTimer(Intervall, ct => TrackAsync(), Intervall);
        }
Esempio n. 11
0
        public void Subscribe(IEventConsumer eventConsumer, int delay = 5000)
        {
            Guard.NotNull(eventConsumer, nameof(eventConsumer));

            ThrowIfDisposed();

            if (timer != null)
            {
                return;
            }

            var consumerName    = eventConsumer.Name;
            var consumerStarted = false;

            timer = new CompletionTimer(delay, async ct =>
            {
                if (!consumerStarted)
                {
                    await eventConsumerInfoRepository.CreateAsync(consumerName);

                    consumerStarted = true;
                }

                try
                {
                    var status = await eventConsumerInfoRepository.FindAsync(consumerName);

                    var position = status.Position;

                    if (status.IsResetting)
                    {
                        position = null;

                        await ResetAsync(eventConsumer, consumerName, position);
                    }
                    else if (status.IsStopped)
                    {
                        return;
                    }

                    await eventStore.GetEventsAsync(se =>
                    {
                        return(HandleEventAsync(eventConsumer, se, consumerName));
                    }, ct, eventConsumer.EventsFilter, position);
                }
                catch (Exception ex)
                {
                    log.LogFatal(ex, w => w.WriteProperty("action", "EventHandlingFailed"));

                    await eventConsumerInfoRepository.StopAsync(consumerName, ex.ToString());
                }
            });

            eventNotifier.Subscribe(timer.Trigger);
        }
        public BackgroundRequestLogStore(IOptions <RequestLogStoreOptions> options,
                                         IRequestLogRepository logRepository, ISemanticLog log)
        {
            this.options = options.Value;

            this.logRepository = logRepository;

            timer = new CompletionTimer(options.Value.WriteIntervall, TrackAsync, options.Value.WriteIntervall);

            this.log = log;
        }
Esempio n. 13
0
        public async Task InitializeAsync(CancellationToken ct)
        {
            await SetupIndexAsync(ct);

            await PruneAsync(ct);

            timer = new CompletionTimer((int)TimeSpan.FromHours(6).TotalMilliseconds, async ct =>
            {
                await PruneAsync(ct);
            });
        }
Esempio n. 14
0
        public BackgroundUsageTracker(IUsageStore usageStore, ISemanticLog log)
        {
            Guard.NotNull(usageStore, nameof(usageStore));
            Guard.NotNull(log, nameof(log));

            this.usageStore = usageStore;

            this.log = log;

            timer = new CompletionTimer(Intervall, ct => TrackAsync(), Intervall);
        }
Esempio n. 15
0
        public ContentScheduler(
            IContentRepository contentRepository,
            ICommandBus commandBus,
            IClock clock)
        {
            Guard.NotNull(contentRepository, nameof(contentRepository));
            Guard.NotNull(commandBus, nameof(commandBus));
            Guard.NotNull(clock, nameof(clock));

            this.contentRepository = contentRepository;
            this.commandBus        = commandBus;
            this.clock             = clock;

            timer = new CompletionTimer(5000, x => PublishAsync());
        }
Esempio n. 16
0
        public PollingSubscription(
            IEventStore eventStore,
            IEventNotifier eventNotifier,
            IEventSubscriber eventSubscriber,
            string streamFilter,
            string position)
        {
            Guard.NotNull(eventStore, nameof(eventStore));
            Guard.NotNull(eventNotifier, nameof(eventNotifier));
            Guard.NotNull(eventSubscriber, nameof(eventSubscriber));

            this.position        = position;
            this.eventNotifier   = eventNotifier;
            this.eventStore      = eventStore;
            this.eventSubscriber = eventSubscriber;
            this.streamFilter    = streamFilter;

            streamRegex = new Regex(streamFilter);

            timer = new CompletionTimer(5000, async ct =>
            {
                try
                {
                    await eventStore.GetEventsAsync(async storedEvent =>
                    {
                        await eventSubscriber.OnEventAsync(this, storedEvent);

                        position = storedEvent.EventPosition;
                    }, ct, streamFilter, position);
                }
                catch (Exception ex)
                {
                    if (!ex.Is <OperationCanceledException>())
                    {
                        await eventSubscriber.OnErrorAsync(this, ex);
                    }
                }
            });

            notification = eventNotifier.Subscribe(streamName =>
            {
                if (streamRegex.IsMatch(streamName))
                {
                    timer.SkipCurrentDelay();
                }
            });
        }
Esempio n. 17
0
        public Task SubscribeAsync(Func <StoredEvent, Task> onNext, Func <Exception, Task> onError = null)
        {
            Guard.NotNull(onNext, nameof(onNext));

            if (timer != null)
            {
                throw new InvalidOperationException("An handler has already been registered.");
            }

            timer = new CompletionTimer(5000, async ct =>
            {
                try
                {
                    await eventStore.GetEventsAsync(async storedEvent =>
                    {
                        if (!isStopped)
                        {
                            await onNext(storedEvent);

                            position = storedEvent.EventPosition;
                        }
                    }, ct, streamFilter, position);
                }
                catch (Exception ex) when(!(ex is OperationCanceledException))
                {
                    if (!isStopped)
                    {
                        onError?.Invoke(ex);
                    }
                }
            });

            subscription = eventNotifier.Subscribe(() =>
            {
                if (!isStopped)
                {
                    timer.SkipCurrentDelay();
                }
            });

            return(TaskHelper.Done);
        }
Esempio n. 18
0
        public RuleDequeuer(RuleService ruleService, IRuleEventRepository ruleEventRepository, ISemanticLog log, IClock clock)
        {
            Guard.NotNull(ruleEventRepository, nameof(ruleEventRepository));
            Guard.NotNull(ruleService, nameof(ruleService));
            Guard.NotNull(clock, nameof(clock));
            Guard.NotNull(log, nameof(log));

            this.ruleEventRepository = ruleEventRepository;
            this.ruleService         = ruleService;

            this.clock = clock;

            this.log = log;

            requestBlock =
                new PartitionedActionBlock <IRuleEventEntity>(HandleAsync, x => x.Job.AggregateId.GetHashCode(),
                                                              new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 32, BoundedCapacity = 32
            });

            timer = new CompletionTimer(5000, QueryAsync);
        }
Esempio n. 19
0
        public WebhookDequeuer(WebhookSender webhookSender,
                               IWebhookEventRepository webhookEventRepository,
                               IWebhookRepository webhookRepository,
                               IClock clock,
                               ISemanticLog log)
        {
            Guard.NotNull(webhookEventRepository, nameof(webhookEventRepository));
            Guard.NotNull(webhookRepository, nameof(webhookRepository));
            Guard.NotNull(webhookSender, nameof(webhookSender));
            Guard.NotNull(clock, nameof(clock));
            Guard.NotNull(log, nameof(log));

            this.webhookEventRepository = webhookEventRepository;
            this.webhookRepository      = webhookRepository;
            this.webhookSender          = webhookSender;

            this.clock = clock;

            this.log = log;

            requestBlock =
                new ActionBlock <IWebhookEventEntity>(MakeRequestAsync,
                                                      new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 32, BoundedCapacity = 32
            });

            blockBlock =
                new TransformBlock <IWebhookEventEntity, IWebhookEventEntity>(x => BlockAsync(x),
                                                                              new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 1, BoundedCapacity = 1
            });

            blockBlock.LinkTo(requestBlock, new DataflowLinkOptions {
                PropagateCompletion = true
            });

            timer = new CompletionTimer(5000, QueryAsync);
        }
Esempio n. 20
0
        public Task InitializeAsync(CancellationToken ct)
        {
            timer = new CompletionTimer(5000, CheckAsync, 5000);

            return(Task.CompletedTask);
        }
Esempio n. 21
0
 public PhaseManager(IEnumerable <Phase> phases)
 {
     _phases     = phases;
     _introTimer = new CompletionTimer(TimeSpan.FromSeconds(5));
 }