/// <summary>
 /// Initializes a new instance of the <see cref="ResonanceSignalRDiscoveryClient{TReportedServiceInformation, TCredentials}"/> class.
 /// </summary>
 /// <param name="hubUrl">The remote hub URL.</param>
 /// <param name="mode">The SignalR client mode (core/legacy).</param>
 /// <param name="credentials">The credentials used to authenticate this discovery client with the remote hub.</param>
 public ResonanceSignalRDiscoveryClient(String hubUrl, SignalRMode mode, TCredentials credentials)
 {
     HubUrl                 = hubUrl;
     Mode                   = mode;
     Credentials            = credentials;
     EnableAutoReconnection = true;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SignalRAdapter{TCredentials}"/> class.
 /// </summary>
 /// <param name="credentials">The credentials that will be used to authenticate with the remote hub.</param>
 /// <param name="url">The hub URL.</param>
 /// <param name="serviceId">The remote service identifier.</param>
 /// <param name="mode">The SignalR mode.</param>
 public SignalRAdapter(TCredentials credentials, String url, String serviceId, SignalRMode mode) : this()
 {
     Mode        = mode;
     Url         = url;
     ServiceId   = serviceId;
     Credentials = credentials;
     Role        = SignalRAdapterRole.Connect;
 }
Ejemplo n.º 3
0
        public ISignalRClient Create(SignalRMode mode, String url)
        {
#if NET461
            if (mode == SignalRMode.Legacy)
            {
                return(new SignalRClient(url));
            }
            return(new SignalRCoreClient(url));
#else
            return(new SignalRCoreClient(url));
#endif
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResonanceRegisteredService{TCredentials, TResonanceServiceInformation, TAdapterInformation}"/> class.
 /// </summary>
 /// <param name="credentials">The credentials.</param>
 /// <param name="serviceInformation">The service information.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="signalRClient">The signal r client.</param>
 internal ResonanceRegisteredService(TCredentials credentials, TResonanceServiceInformation serviceInformation, SignalRMode mode, ISignalRClient signalRClient)
 {
     IsRegistered          = true;
     Mode                  = mode;
     Credentials           = credentials;
     ServiceInformation    = serviceInformation;
     _client               = signalRClient;
     _client.Reconnecting -= OnReconnecting;
     _client.Reconnecting += OnReconnecting;
     _client.Reconnected  -= OnReconnected;
     _client.Reconnected  += OnReconnected;
     _client.Error        -= OnError;
     _client.Error        += OnError;
     _client.On <String, TAdapterInformation>(ResonanceHubMethods.ConnectionRequest, OnConnectionRequest);
 }
Ejemplo n.º 5
0
        private void SignalR_Reading_Writing(String url, SignalRMode mode)
        {
            TestCredentials credentials = new TestCredentials()
            {
                Name = "Test"
            };
            TestServiceInformation serviceInfo = new TestServiceInformation()
            {
                ServiceId = "My Test Service"
            };

            var registeredService = ResonanceServiceFactory.Default.RegisterService <TestCredentials, TestServiceInformation, TestAdapterInformation>(credentials, serviceInfo, url, mode);

            Assert.AreSame(registeredService.Credentials, credentials);
            Assert.AreSame(registeredService.ServiceInformation, serviceInfo);
            Assert.AreEqual(registeredService.Mode, mode);

            bool connected = false;

            ResonanceTransporter serviceTransporter = new ResonanceTransporter();

            registeredService.ConnectionRequest += (_, e) =>
            {
                Assert.IsTrue(e.RemoteAdapterInformation.Information == "No information on the remote adapter");
                serviceTransporter.Adapter = e.Accept();
                serviceTransporter.Connect();
                connected = true;
            };

            var remoteServices = ResonanceServiceFactory.Default.GetAvailableServices <TestCredentials, TestServiceInformation>(credentials, url, mode);

            Assert.IsTrue(remoteServices.Count == 1);

            var remoteService = remoteServices.First();

            Assert.AreEqual(remoteService.ServiceId, registeredService.ServiceInformation.ServiceId);

            ResonanceTransporter clientTransporter = new ResonanceTransporter(new SignalRAdapter <TestCredentials>(credentials, url, remoteService.ServiceId, mode));

            clientTransporter.Connect();

            TestHelper.WaitWhile(() => !connected, TimeSpan.FromSeconds(30));

            TestUtils.Read_Write_Test(this, serviceTransporter, clientTransporter, false, 1000, 20);
        }
Ejemplo n.º 6
0
        private void SignalR_Adapter_Fails_On_Client_Error(ISignalRServer server, String hostUrl, String hubUrl, SignalRMode mode)
        {
            server.Start();

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

            bool connected = false;
            IResonanceAdapter serviceAdapter = null;


            registeredService.ConnectionRequest += (x, e) =>
            {
                serviceAdapter = e.Accept();
                serviceAdapter.Connect();
                connected = true;
            };

            SignalRAdapter <TestCredentials> adapter = new SignalRAdapter <TestCredentials>(
                new TestCredentials()
            {
                Name = "Test User"
            },
                hubUrl, "Service 1", mode);

            adapter.Connect();

            while (!connected)
            {
                Thread.Sleep(10);
            }

            Thread.Sleep(1000);

            server.Dispose();
            serviceAdapter.Dispose();

            TestHelper.WaitWhile(() => adapter.State != ResonanceComponentState.Failed, TimeSpan.FromSeconds(10));

            Assert.IsTrue(adapter.State == ResonanceComponentState.Failed);

            Assert.IsInstanceOfType(adapter.FailedStateException, typeof(WebSocketException));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Registers a new Resonance SignalR service.
        /// </summary>
        /// <typeparam name="TCredentials">The type of the credentials.</typeparam>
        /// <typeparam name="TResonanceServiceInformation">The type of the resonance service information.</typeparam>
        /// <typeparam name="TAdapterInformation">The type of the adapter information.</typeparam>
        /// <param name="credentials">The credentials used to authenticate the service.</param>
        /// <param name="serviceInformation">The service information.</param>
        /// <param name="url">The hub URL.</param>
        /// <param name="mode">The SignalR mode (legacy/core).</param>
        /// <returns></returns>
        public async Task <ResonanceRegisteredService <TCredentials, TResonanceServiceInformation, TAdapterInformation> > RegisterServiceAsync <TCredentials, TResonanceServiceInformation, TAdapterInformation>(TCredentials credentials, TResonanceServiceInformation serviceInformation, String url, SignalRMode mode) where TResonanceServiceInformation : IResonanceServiceInformation
        {
            Logger.LogDebug($"Registering service {{@ServiceInformation}}...", serviceInformation);

            ISignalRClient client = SignalRClientFactory.Default.Create(mode, url);

            client.EnableAutoReconnection = true;

            await client.StartAsync();

            await client.InvokeAsync(ResonanceHubMethods.Login, credentials);

            await client.InvokeAsync(ResonanceHubMethods.RegisterService, serviceInformation);

            return(new ResonanceRegisteredService <TCredentials, TResonanceServiceInformation, TAdapterInformation>(credentials, serviceInformation, mode, client));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the collection of available services for the provided credentials.
 /// </summary>
 /// <typeparam name="TCredentials">The type of the credentials.</typeparam>
 /// <typeparam name="TReportedServiceInformation">The type of the reported service information.</typeparam>
 /// <param name="credentials">The credentials.</param>
 /// <param name="url">The URL.</param>
 /// <param name="mode">The mode.</param>
 /// <returns></returns>
 public List <TReportedServiceInformation> GetAvailableServices <TCredentials, TReportedServiceInformation>(TCredentials credentials, String url, SignalRMode mode) where TReportedServiceInformation : IResonanceServiceInformation
 {
     return(GetAvailableServicesAsync <TCredentials, TReportedServiceInformation>(credentials, url, mode).GetAwaiter().GetResult());
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the collection of available services for the provided credentials.
        /// </summary>
        /// <typeparam name="TCredentials">The type of the credentials.</typeparam>
        /// <typeparam name="TReportedServiceInformation">The type of the reported service information.</typeparam>
        /// <param name="credentials">The credentials.</param>
        /// <param name="url">The URL.</param>
        /// <param name="mode">The mode.</param>
        /// <returns></returns>
        public async Task <List <TReportedServiceInformation> > GetAvailableServicesAsync <TCredentials, TReportedServiceInformation>(TCredentials credentials, String url, SignalRMode mode) where TReportedServiceInformation : IResonanceServiceInformation
        {
            ISignalRClient client = SignalRClientFactory.Default.Create(mode, url);

            await client.StartAsync();

            var services = await client.InvokeAsync <List <TReportedServiceInformation> >(ResonanceHubMethods.GetAvailableServices, credentials);

            await client.DisposeAsync();

            return(services);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Registers a new Resonance SignalR service.
 /// </summary>
 /// <typeparam name="TCredentials">The type of the credentials.</typeparam>
 /// <typeparam name="TResonanceServiceInformation">The type of the resonance service information.</typeparam>
 /// <typeparam name="TAdapterInformation">The type of the adapter information.</typeparam>
 /// <param name="credentials">The credentials used to authenticate the service.</param>
 /// <param name="serviceInformation">The service information.</param>
 /// <param name="url">The hub URL.</param>
 /// <param name="mode">The SignalR mode (legacy/core).</param>
 /// <returns></returns>
 public ResonanceRegisteredService <TCredentials, TResonanceServiceInformation, TAdapterInformation> RegisterService <TCredentials, TResonanceServiceInformation, TAdapterInformation>(TCredentials credentials, TResonanceServiceInformation serviceInformation, String url, SignalRMode mode) where TResonanceServiceInformation : IResonanceServiceInformation
 {
     return(RegisterServiceAsync <TCredentials, TResonanceServiceInformation, TAdapterInformation>(credentials, serviceInformation, url, mode).GetAwaiter().GetResult());
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Returns an initialized adapter based on parameters that should be provided by a <see cref="Resonance.SignalR.Services.ResonanceRegisteredService{TCredentials, TResonanceServiceInformation, TAdapterInformation}.ConnectionRequest"/> event arguments.
        /// </summary>
        /// <param name="credentials">The credentials used to authenticate this adapter with the remote service.</param>
        /// <param name="url">The hub URL.</param>
        /// <param name="serviceId">The service identifier.</param>
        /// <param name="sessionId">The session identifier.</param>
        /// <param name="mode">The SignalR mode.</param>
        /// <returns></returns>
        public static SignalRAdapter <TCredentials> AcceptConnection(TCredentials credentials, String url, String serviceId, String sessionId, SignalRMode mode)
        {
            SignalRAdapter <TCredentials> adapter = new SignalRAdapter <TCredentials>();

            adapter.Mode        = mode;
            adapter.Url         = url;
            adapter.ServiceId   = serviceId;
            adapter.SessionId   = sessionId;
            adapter.Credentials = credentials;
            adapter.Role        = SignalRAdapterRole.Accept;

            return(adapter);
        }
 internal SignalRAdapterBuilderServiceId(ResonanceTransporterBuilder builder, SignalRMode mode, T credentials, String serviceId) : base(builder, mode)
 {
     _credentials = credentials;
     _serviceId   = serviceId;
 }
 internal SignalRAdapterHubUrlBuilder(ResonanceTransporterBuilder builder, SignalRMode mode, T credentials) : base(builder, mode)
 {
     _credetials = credentials;
 }
 internal SignalRAdapterBuilder(ResonanceTransporterBuilder builder, SignalRMode mode) : base(builder, mode)
 {
 }
 internal SignalRAdapterBuilderBase(ResonanceTransporterBuilder builder, SignalRMode mode)
 {
     _builder = builder;
     _mode    = mode;
 }
 /// <summary>
 /// Sets the transporter adapter to <see cref="SignalRAdapter{TCredentials}"/>.
 /// </summary>
 /// <param name="adapterBuilder">The adapter builder.</param>
 /// <param name="mode">The SinglaR mode (legacy/core).</param>
 public static SignalRAdapterBuilder WithSignalRAdapter(this IAdapterBuilder adapterBuilder, SignalRMode mode)
 {
     return(new SignalRAdapterBuilder(adapterBuilder as ResonanceTransporterBuilder, mode));
 }