public IServiceHubLifetimeManager Create(string hubName) { switch (_options.ServiceTransportType) { case ServiceTransportType.Persistent: { var container = _serviceProvider.GetRequiredService <IServiceConnectionContainer>(); var connectionManager = new ServiceConnectionManager <Hub>(); connectionManager.SetServiceConnection(container); return(ActivatorUtilities.CreateInstance <WebSocketsHubLifetimeManager <Hub> >(_serviceProvider, connectionManager)); } case ServiceTransportType.Transient: { var restHubProtocol = _serviceProvider.GetService <IRestHubProtocol>(); var payloadSerializerSettings = _options.JsonSerializerSettings; //Currently RestHubProtocol only has Newtonsoft if (restHubProtocol != null) { var newtonsoftServiceHubProtocolOptions = _serviceProvider.GetService <IOptions <NewtonsoftServiceHubProtocolOptions> >(); payloadSerializerSettings = newtonsoftServiceHubProtocolOptions.Value.PayloadSerializerSettings; } var httpClientFactory = _serviceProvider.GetRequiredService <IHttpClientFactory>(); var restClient = new RestClient(httpClientFactory, payloadSerializerSettings, _options.EnableMessageTracing); return(new RestHubLifetimeManager(hubName, new ServiceEndpoint(_options.ConnectionString), _options.ProductInfo, _options.ApplicationName, restClient)); } default: throw new InvalidEnumArgumentException(nameof(ServiceManagerOptions.ServiceTransportType), (int)_options.ServiceTransportType, typeof(ServiceTransportType)); } }
public async void ServiceLifetimeManagerIntegrationTest(string methodName, Type messageType) { var proxy = new ServiceConnectionProxy(); var serviceConnectionManager = new ServiceConnectionManager <TestHub>(); serviceConnectionManager.SetServiceConnection(proxy.ServiceConnectionContainer); var serviceLifetimeManager = new ServiceLifetimeManager <TestHub>(serviceConnectionManager, proxy.ClientConnectionManager, HubProtocolResolver, Logger, Marker); var serverTask = proxy.WaitForServerConnectionAsync(1); _ = proxy.StartAsync(); await proxy.WaitForServerConnectionsInited().OrTimeout(); await serverTask.OrTimeout(); var task = proxy.WaitForApplicationMessageAsync(messageType); await InvokeMethod(serviceLifetimeManager, methodName); var message = await task.OrTimeout(); VerifyServiceMessage(methodName, message); }
public ModelSourceMediaRendererUpnpAv(Source aSource) { DidlLite didl = new DidlLite(); audioItem itemAudio = new audioItem(); itemAudio.Title = "Unknown"; didl.Add(itemAudio); kUnknownPlaylistItem = new MrItem(0, null, didl); iSource = aSource; iInstanceId = 0; iTrackId = 0; try { iServiceConnectionManager = new ServiceConnectionManager(iSource.Device, iSource.House.EventServer); } catch (ServiceException) { throw new ModelSourceException(301, "Service failure"); } iActionGetProtocolInfo = iServiceConnectionManager.CreateAsyncActionGetProtocolInfo(); iActionGetProtocolInfo.EventResponse += EventResponseGetProtocolInfo; try { iServiceAVTransport = new ServiceAVTransport(iSource.Device, iSource.House.EventServer); } catch (ServiceException) { throw new ModelSourceException(301, "Service failure"); } iActionPlay = iServiceAVTransport.CreateAsyncActionPlay(); iActionPause = iServiceAVTransport.CreateAsyncActionPause(); iActionStop = iServiceAVTransport.CreateAsyncActionStop(); iActionSeek = iServiceAVTransport.CreateAsyncActionSeek(); iActionNext = iServiceAVTransport.CreateAsyncActionNext(); iActionPrevious = iServiceAVTransport.CreateAsyncActionPrevious(); iActionSetAVTransportURI = iServiceAVTransport.CreateAsyncActionSetAVTransportURI(); iActionGetPositionInfo = iServiceAVTransport.CreateAsyncActionGetPositionInfo(); iActionGetTransportSettings = iServiceAVTransport.CreateAsyncActionGetTransportSettings(); iActionSetPlayMode = iServiceAVTransport.CreateAsyncActionSetPlayMode(); iActionGetPositionInfo.EventResponse += EventResponseGetPositionInfo; iActionGetTransportSettings.EventResponse += EventResponseGetTransportSettings; iActionSetAVTransportURI.EventResponse += EventResponseSetAVTransportURI; iTimer = new Linn.Timer(); // Sets the timer interval to 1 second. iTimer.Interval = 1000; iTimer.Elapsed += TimerElapsed; iTimer.AutoReset = false; iMutex = new Mutex(false); iPlaylist = new List <MrItem>(); }
public async void ServiceLifetimeManagerIntegrationTest(string methodName, Type messageType) { var proxy = new ServiceConnectionProxy(); var serviceConnectionManager = new ServiceConnectionManager <TestHub>(); serviceConnectionManager.SetServiceConnection(proxy.ServiceConnectionContainer); var serviceLifetimeManager = new ServiceLifetimeManager <TestHub>(serviceConnectionManager, proxy.ClientConnectionManager, HubProtocolResolver, Logger, Marker, _globalHubOptions, _localHubOptions); var serverTask = proxy.WaitForServerConnectionAsync(1); _ = proxy.StartAsync(); await proxy.WaitForServerConnectionsInited().OrTimeout(); await serverTask.OrTimeout(); var task = proxy.WaitForApplicationMessageAsync(messageType); var invokeTask = InvokeMethod(serviceLifetimeManager, methodName); if (typeof(IAckableMessage).IsAssignableFrom(messageType)) { await proxy.WriteMessageAsync(new AckMessage(1, (int)AckStatus.Ok)); } // Need to return in time, or it indicate a timeout when sending ack-able messages. await invokeTask.OrTimeout(); var message = await task.OrTimeout(); VerifyServiceMessage(methodName, message); }
private static IDependencyResolver GetDefaultResolver(IReadOnlyList <string> hubs, out IServiceConnectionManager scm) { var resolver = new DefaultDependencyResolver(); resolver.Register(typeof(IServiceProtocol), () => new ServiceProtocol()); var connectionManager = new ServiceConnectionManager(AppName, hubs); resolver.Register(typeof(IServiceConnectionManager), () => connectionManager); resolver.Register(typeof(IMessageParser), () => new SignalRMessageParser(hubs, resolver)); scm = connectionManager; return(resolver); }
private static ServiceHubDispatcher PrepareAndGetDispatcher(HubConfiguration configuration, ServiceOptions options, IServiceEndpointManager endpoint, IEndpointRouter router, string applicationName, IReadOnlyList <string> hubs, ILoggerFactory loggerFactory) { // TODO: Using IOptions looks wierd, thinking of a way removing it // share the same object all through var serviceOptions = Options.Create(options); // For safety, ALWAYS register abstract classes or interfaces // Some third-party DI frameworks such as Ninject, implicit self-binding concrete types: // https://github.com/ninject/ninject/wiki/dependency-injection-with-ninject#skipping-the-type-binding-bit--implicit-self-binding-of-concrete-types configuration.Resolver.Register(typeof(IOptions <ServiceOptions>), () => serviceOptions); var serviceProtocol = new ServiceProtocol(); configuration.Resolver.Register(typeof(IServiceProtocol), () => serviceProtocol); var scm = new ServiceConnectionManager(applicationName, hubs); configuration.Resolver.Register(typeof(Microsoft.Azure.SignalR.AspNet.IServiceConnectionManager), () => scm); var ccm = new ClientConnectionManager(configuration); configuration.Resolver.Register(typeof(IClientConnectionManager), () => ccm); var atm = new AzureTransportManager(configuration.Resolver); configuration.Resolver.Register(typeof(ITransportManager), () => atm); var parser = new SignalRMessageParser(hubs, configuration.Resolver); configuration.Resolver.Register(typeof(IMessageParser), () => parser); var smb = new ServiceMessageBus(configuration.Resolver); configuration.Resolver.Register(typeof(IMessageBus), () => smb); if (hubs?.Count > 0) { return(new ServiceHubDispatcher(hubs, serviceProtocol, scm, ccm, endpoint, router, serviceOptions, loggerFactory)); } else { loggerFactory.CreateLogger <IAppBuilder>().Log(LogLevel.Warning, "No hubs found."); return(null); } }
private static void RegisterServiceObjects(HubConfiguration configuration, ServiceOptions options, string applicationName, IReadOnlyList <string> hubs) { // TODO: Using IOptions looks wierd, thinking of a way removing it // share the same object all through var serviceOptions = Options.Create(options); // For safety, ALWAYS register abstract classes or interfaces // Some third-party DI frameworks such as Ninject, implicit self-binding concrete types: // https://github.com/ninject/ninject/wiki/dependency-injection-with-ninject#skipping-the-type-binding-bit--implicit-self-binding-of-concrete-types configuration.Resolver.Register(typeof(IOptions <ServiceOptions>), () => serviceOptions); var serviceProtocol = new ServiceProtocol(); configuration.Resolver.Register(typeof(IServiceProtocol), () => serviceProtocol); var provider = new EmptyProtectedData(); configuration.Resolver.Register(typeof(IProtectedData), () => provider); var endpoint = new ServiceEndpointProvider(serviceOptions.Value); configuration.Resolver.Register(typeof(IServiceEndpointProvider), () => endpoint); var scm = new ServiceConnectionManager(applicationName, hubs); configuration.Resolver.Register(typeof(IServiceConnectionManager), () => scm); var ccm = new ClientConnectionManager(configuration); configuration.Resolver.Register(typeof(IClientConnectionManager), () => ccm); var atm = new AzureTransportManager(configuration.Resolver); configuration.Resolver.Register(typeof(ITransportManager), () => atm); var parser = new SignalRMessageParser(hubs, configuration.Resolver); configuration.Resolver.Register(typeof(IMessageParser), () => parser); var smb = new ServiceMessageBus(configuration.Resolver); configuration.Resolver.Register(typeof(IMessageBus), () => smb); }
public IServiceHubLifetimeManager Create(string hubName) { switch (_options.ServiceTransportType) { case ServiceTransportType.Persistent: { var container = _serviceProvider.GetRequiredService <IServiceConnectionContainer>(); var connectionManager = new ServiceConnectionManager <Hub>(); connectionManager.SetServiceConnection(container); return(ActivatorUtilities.CreateInstance <WebSocketsHubLifetimeManager <Hub> >(_serviceProvider, connectionManager)); } case ServiceTransportType.Transient: { return(new RestHubLifetimeManager(hubName, new ServiceEndpoint(_options.ConnectionString), _options.ProductInfo, _options.ApplicationName, _options.JsonSerializerSettings)); } default: throw new InvalidEnumArgumentException(nameof(ServiceManagerOptions.ServiceTransportType), (int)_options.ServiceTransportType, typeof(ServiceTransportType)); } }
/// <summary> /// 해당 URL로 가기위해 어느 localId로 가야하는지 알려줌 /// 못찾으면 null return /// </summary> /// <param name="URL">.service 혹은 .node로 끝나는 주소</param> /// <returns>localId</returns> public static IConnection shortestPathTo(string URL) { string serviceName = Tools.getServiceNameFromUrl(URL); if (serviceName == null) { return(null); } Node node = CurrentNode.shortestPathTo(serviceName); if (node == null) { return(null); } else if (node.id == CurrentNode.id) // 목적지는 ServiceConnectionManager 에서 찾아야함. { try { return(ServiceConnectionManager.getConnection(serviceName)); } catch { return(null); } } else // 목적지는 NodeConnectionManager 에서 찾아야함. { try { return(NodeConnectionManager.getConnection(node.id)); } catch { return(null); } } }
public async Task <IServiceHubLifetimeManager> CreateAsync(string hubName, CancellationToken cancellationToken, ILoggerFactory loggerFactoryPerHub = null) { switch (_context.ServiceTransportType) { case ServiceTransportType.Persistent: { var container = _connectionContainerFactory.Create(hubName, loggerFactoryPerHub); var connectionManager = new ServiceConnectionManager <Hub>(); connectionManager.SetServiceConnection(container); _ = connectionManager.StartAsync(); await container.ConnectionInitializedTask.OrTimeout(cancellationToken); return(loggerFactoryPerHub == null?ActivatorUtilities.CreateInstance <WebSocketsHubLifetimeManager <Hub> >(_serviceProvider, connectionManager) : ActivatorUtilities.CreateInstance <WebSocketsHubLifetimeManager <Hub> >(_serviceProvider, connectionManager, loggerFactoryPerHub)); } case ServiceTransportType.Transient: { return(new RestHubLifetimeManager(hubName, _context.ServiceEndpoints.Single(), _context.ProductInfo, _context.ApplicationName)); } default: throw new InvalidEnumArgumentException(nameof(ContextOptions.ServiceTransportType), (int)_context.ServiceTransportType, typeof(ServiceTransportType)); } }