Exemplo n.º 1
0
        public void Init(ClientEventBroadcasterSettings broadcasterSettings)
        {
            this.logger.LogDebug($"Initialising SignalR Broadcaster {this.GetType().Name}");
            this.asyncLoop = this.asyncProvider.CreateAndRunAsyncLoop(
                $"Broadcast {this.GetType().Name}",
                async token =>
            {
                using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(this.nodeLifetime.ApplicationStopping, token))
                {
                    linkedTokenSource.CancelAfter(new TimeSpan(0, 0, 10));
                    try
                    {
                        IEnumerable <IClientEvent> messages = await this.GetMessages(linkedTokenSource.Token);
                        foreach (IClientEvent clientEvent in messages)
                        {
                            await this.eventsHub.SendToClientsAsync(clientEvent);
                        }
                    }
                    catch (Exception ex)
                    {
                        this.logger.LogError($"{this.GetType().Name} Error in GetMessages", ex);
                    }
                }
            },
                this.nodeLifetime.ApplicationStopping,
                repeatEvery:
                TimeSpan.FromSeconds(Math.Max(broadcasterSettings.BroadcastFrequencySeconds, 5)));

            this.OnInitialise();
        }
Exemplo n.º 2
0
 public void Init(ClientEventBroadcasterSettings broadcasterSettings)
 {
     this.logger.LogDebug($"Initialising SignalR Broadcaster {this.GetType().Name}");
     this.asyncLoop = this.asyncProvider.CreateAndRunAsyncLoop(
         $"Broadcast {this.GetType().Name}",
         async token =>
     {
         foreach (IClientEvent clientEvent in this.GetMessages())
         {
             await this.eventsHub.SendToClientsAsync(clientEvent).ConfigureAwait(false);
         }
     },
         this.nodeLifetime.ApplicationStopping,
         repeatEvery: TimeSpan.FromSeconds(Math.Max(broadcasterSettings.BroadcastFrequencySeconds, 5)));
 }