Beispiel #1
0
        private async void DisconnectClient(ResonanceSignalRClient client)
        {
            if (client != null)
            {
                await client.DisposeAsync();

                Clients.Remove(client);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles a client's stage changed event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ResonanceComponentStateChangedEventArgs"/> instance containing the event data.</param>
        private void OnClientStateChanged(object sender, ResonanceComponentStateChangedEventArgs e)
        {
            ResonanceSignalRClient client = sender as ResonanceSignalRClient;

            if (e.NewState == ResonanceComponentState.Failed)
            {
                Logger.LogWarning($"Client {client.RemoteAdapterInformation.Name} disconnected.");

                InvokeUI(() =>
                {
                    Clients.Remove(client);
                });
            }
        }
Beispiel #3
0
        private async void _service_ConnectionRequest(object sender, ConnectionRequestEventArgs <DemoCredentials, DemoAdapterInformation> e)
        {
            if (!await ShowQuestionMessage($"Client wants to connect to this service. Do you accept?"))
            {
                e.Decline();
                return;
            }

            ResonanceSignalRClient newClient = new ResonanceSignalRClient();

            newClient.RemoteAdapterInformation = e.RemoteAdapterInformation;

            newClient.StateChanged += OnClientStateChanged;

            var adapter = e.Accept();

            adapter.Credentials.Name = $"{ServiceId} {adapter}";

            newClient.CreateBuilder()
            .WithAdapter(adapter)
            .WithJsonTranscoding()
            .Build();

            newClient.RegisterRequestHandler <EchoTextRequest, EchoTextResponse>((request) =>
            {
                Logger.LogInformation($"{newClient.RemoteAdapterInformation.Name} says: {request.Message}");
                return(new EchoTextResponse()
                {
                    Message = "OK"
                });
            });

            await newClient.ConnectAsync();

            InvokeUI(() =>
            {
                Clients.Add(newClient);
            });

            Logger.LogInformation($"{newClient.RemoteAdapterInformation.Name} is now connected.");
        }