Esempio n. 1
0
        protected override void OnInitialized()
        {
            if (RealtimeConnection is null || Configuration is null)
            {
                Updates = new RingBuffer <string>(capacity: 0);

                return;
            }

            Updates = new RingBuffer <string>(Configuration.GetValue(key: "Updates-BufferSize", defaultValue: 10));

            PrimeUpdates();

            RealtimeConnection.Closed += async _ =>
            {
                ErrorMessage = Empty;
                Connected    = false;

                if (Receive)
                {
                    await RealtimeConnection.StartAsync();
                }
            };

            RealtimeConnection.Reconnected += _ =>
            {
                ErrorMessage = Empty;
                Connected    = true;

                return(CompletedTask);
            };

            RealtimeConnection.Reconnecting += _ =>
            {
                ErrorMessage = Empty;
                Connected    = false;

                return(CompletedTask);
            };

            RealtimeConnection.On <string>
            (
                methodName: "statusUpdate"
                , status =>
            {
                Updates.Write(status);

                StateHasChanged();
            }
            );
        }
Esempio n. 2
0
        // ReSharper disable once UnusedMember.Global
        protected async Task UpdatesClicked()
        {
            if (RealtimeConnection is null)
            {
                ErrorMessage = "SignalR Connection was not configured";

                return;
            }

            ErrorMessage = Empty;

            Receive = !Receive;

            if (Receive)
            {
                try
                {
                    Connected = true;

                    await RealtimeConnection.StartAsync();
                }
                catch (Exception exception)
                {
                    ErrorMessage = exception.Message;
                    Connected    = false;
                }
            }
            else
            {
                try
                {
                    await RealtimeConnection.StopAsync();

                    PrimeUpdates();
                }
                catch (Exception exception)
                {
                    ErrorMessage = exception.Message;
                }
            }
        }