コード例 #1
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;
            }
        }
コード例 #2
0
ファイル: MainWindowVM.cs プロジェクト: royben/Resonance
        /// <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;
                }
            }
        }
コード例 #3
0
ファイル: SignalR_TST.cs プロジェクト: royben/Resonance
        public void SignalR_Discovery()
        {
            if (IsRunningOnAzurePipelines)
            {
                return;
            }

            SignalRServer server = new SignalRServer(legacyHostUrl);

            server.Start();

            var registeredService = ResonanceServiceFactory.Default.RegisterService <
                TestCredentials,
                TestServiceInformation,
                TestAdapterInformation>(
                new TestCredentials()
            {
                Name = "Service User"
            },
                new TestServiceInformation()
            {
                ServiceId = "Service 1"
            },
                legacyHubUrl,
                SignalRMode.Legacy);

            ResonanceSignalRDiscoveryClient <TestServiceInformation, TestCredentials> discoveryClient =
                new ResonanceSignalRDiscoveryClient <TestServiceInformation, TestCredentials>(
                    legacyHubUrl,
                    SignalRMode.Legacy,
                    new TestCredentials()
            {
                Name = "Test User"
            });


            var discoveredServices = discoveryClient.Discover(TimeSpan.FromSeconds(10), 1);

            Assert.IsTrue(discoveredServices.Count == 1);
            Assert.IsTrue(discoveredServices[0].DiscoveryInfo.ServiceId == "Service 1");

            registeredService.Dispose();

            discoveredServices = discoveryClient.Discover(TimeSpan.FromSeconds(5), 1);

            Assert.IsTrue(discoveredServices.Count == 0);

            server.Dispose();
        }