Example #1
0
        private async void ResetDiscovery()
        {
            await _discoveryClient.StopAsync();

            RegisteredServices.Clear();
            _discoveryClient.HubUrl      = HubUrl;
            _discoveryClient.Credentials = new DemoCredentials()
            {
                Name = ClientID
            };

            try
            {
                IsFree = false;
                await _discoveryClient.StartAsync();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Error starting discovery service. Make sure the remote SignalR Hub is running.");
            }
            finally
            {
                IsFree = true;
            }
        }
Example #2
0
        private async void StartDiscovery()
        {
            _discoveryClient = new ResonanceSignalRDiscoveryClient <DemoServiceInformation, DemoCredentials>(
                HubUrl,
                SignalRMode.Legacy,
                new DemoCredentials()
            {
                Name = ClientID
            });

            _discoveryClient.ServiceDiscovered += OnServiceDiscovered;
            _discoveryClient.ServiceLost       += OnServiceLost;
            _discoveryClient.Disconnected      += OnDiscoveryError;

            try
            {
                IsFree = false;
                await _discoveryClient.StartAsync();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Error starting discovery service. Make sure the remote SignalR Hub is running.");
            }
            finally
            {
                IsFree = true;
            }
        }
Example #3
0
        /// <summary>
        /// Registers a listening service on the remote hub and starts a service discovery client
        /// to detect available services.
        /// </summary>
        private async void Connect()
        {
            if (!IsConnected)
            {
                try
                {
                    IsFree = false;

                    String serviceName = ClientID + " Service";


                    Logger.LogInformation("Initializing service and discovery...");
                    Logger.LogInformation($"Registering listening service {serviceName}...");

                    _service = await ResonanceServiceFactory.Default.RegisterServiceAsync <
                        DemoCredentials,
                        DemoServiceInformation,
                        DemoAdapterInformation>(
                        new DemoCredentials()
                    {
                        Name = serviceName
                    },
                        new DemoServiceInformation()
                    {
                        ServiceId = ClientID
                    },
                        HubUrl,
                        SignalRMode.Legacy);

                    _service.ConnectionRequest += OnServiceConnectionRequest;

                    Logger.LogInformation($"Starting service discovery...");

                    _discoveryClient = new ResonanceSignalRDiscoveryClient <DemoServiceInformation, DemoCredentials>(
                        HubUrl,
                        SignalRMode.Legacy,
                        new DemoCredentials()
                    {
                        Name = ClientID + " Discovery"
                    });

                    _discoveryClient.ServiceDiscovered += OnServiceDiscovered;
                    _discoveryClient.ServiceLost       += OnServiceLost;
                    _discoveryClient.Disconnected      += OnDiscoveryError;

                    await _discoveryClient.StartAsync();

                    IsConnected = true;

                    Logger.LogInformation("Listening service and discovery started.");
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, ex.Message);
                }
                finally
                {
                    IsFree = true;
                }
            }
        }