Ejemplo n.º 1
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var factory = new PersistentConnectionFactory(_resolver);
            PersistentConnection connection = factory.CreateInstance(_handlerType);

            return(new AspNetHandler(_resolver, connection));
        }
Ejemplo n.º 2
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var factory = new PersistentConnectionFactory(_resolver);
            PersistentConnection connection = factory.CreateInstance(_handlerType);

            return new AspNetHandler(_resolver, connection);
        }
Ejemplo n.º 3
0
        public bool TryGetConnection(string path, out PersistentConnection connection)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            connection = null;

            if (!String.IsNullOrEmpty(_hubPath) &&
                path.StartsWith(_hubPath, StringComparison.OrdinalIgnoreCase))
            {
                connection = new HubDispatcher(_hubPath);
                return(true);
            }

            foreach (var pair in _connectionMapping)
            {
                // If the url matches then create the connection type
                if (path.StartsWith(pair.Key, StringComparison.OrdinalIgnoreCase))
                {
                    var factory = new PersistentConnectionFactory(_resolver);
                    connection = factory.CreateInstance(pair.Value);
                    return(true);
                }
            }

            return(false);
        }
            public void ThrowsIfTypeIsNull()
            {
                // Arrange
                var resolver = new Mock<IDependencyResolver>();
                var factory = new PersistentConnectionFactory(resolver.Object);

                // Act & Assert
                Assert.Throws<ArgumentNullException>(() => factory.CreateInstance(null));
            }
            public void ThrowsIfTypeIsNotPersistentConnection()
            {
                // Arrange
                var resolver = new Mock<IDependencyResolver>();
                var factory = new PersistentConnectionFactory(resolver.Object);

                // Act & Assert
                Assert.Throws<InvalidOperationException>(() => factory.CreateInstance(typeof(PersistentConnectionFactoryFacts)));
            }
Ejemplo n.º 6
0
            public void ThrowsIfTypeIsNotPersistentConnection()
            {
                // Arrange
                var resolver = new Mock <IDependencyResolver>();
                var factory  = new PersistentConnectionFactory(resolver.Object);

                // Act & Assert
                Assert.Throws <InvalidOperationException>(() => factory.CreateInstance(typeof(PersistentConnectionFactoryFacts)));
            }
Ejemplo n.º 7
0
            public void ThrowsIfTypeIsNull()
            {
                // Arrange
                var resolver = new Mock <IDependencyResolver>();
                var factory  = new PersistentConnectionFactory(resolver.Object);

                // Act & Assert
                Assert.Throws <ArgumentNullException>(() => factory.CreateInstance(null));
            }
Ejemplo n.º 8
0
 /// <summary>
 /// Sends all requests to a PersistentConnection type. RunSignalR should be used as the last item in a pipeline, or
 /// inside a Map statement.
 /// </summary>
 /// <typeparam name="T">PersistentConnection type to expose</typeparam>
 /// <param name="builder"></param>
 /// <param name="resolver">Used by components to acquire the services they depend on</param>
 /// <returns></returns>
 public static IAppBuilder RunSignalR <T>(this IAppBuilder builder, IDependencyResolver resolver) where T : PersistentConnection
 {
     return(builder.Use <AppDelegate>(_ => ExecuteConnection(env =>
     {
         var factory = new PersistentConnectionFactory(resolver);
         var connection = factory.CreateInstance(typeof(T));
         connection.Initialize(resolver);
         return connection;
     })));
 }
            public void CreatesInstanceIfTypeIsPersistentConnection()
            {
                // Arrange
                var resolver = new Mock<IDependencyResolver>();
                var factory = new PersistentConnectionFactory(resolver.Object);

                // Act
                PersistentConnection connection = factory.CreateInstance(typeof(MyConnection));

                // Assert
                Assert.NotNull(connection);
            }
Ejemplo n.º 10
0
            public void CreatesInstanceIfTypeIsPersistentConnection()
            {
                // Arrange
                var resolver = new Mock <IDependencyResolver>();
                var factory  = new PersistentConnectionFactory(resolver.Object);

                // Act
                PersistentConnection connection = factory.CreateInstance(typeof(MyConnection));

                // Assert
                Assert.NotNull(connection);
            }
Ejemplo n.º 11
0
        public Task Invoke(IDictionary<string, object> environment)
        {
            var path = environment.Get<string>(OwinConstants.RequestPath);
            if (path == null || !path.StartsWith(_path, StringComparison.OrdinalIgnoreCase))
            {
                return _app.Invoke(environment);
            }

            var connectionFactory = new PersistentConnectionFactory(_resolver);
            var connection = connectionFactory.CreateInstance(_connectionType);

            var handler = new CallHandler(_resolver, connection);
            return handler.Invoke(environment);
        }
            public void UsesDependencyResolver()
            {
                // Arrange
                var resolver = new Mock<IDependencyResolver>();
                var factory = new PersistentConnectionFactory(resolver.Object);
                var otherConnection = new MyOtherConnection();
                resolver.Setup(m => m.GetService(typeof(MyConnection)))
                        .Returns(otherConnection);

                // Act
                PersistentConnection connection = factory.CreateInstance(typeof(MyConnection));

                // Assert
                Assert.NotNull(connection);
                Assert.Same(otherConnection, connection);
            }
Ejemplo n.º 13
0
        public Task Invoke(IDictionary <string, object> environment)
        {
            var path = environment.Get <string>(OwinConstants.RequestPath);

            if (path == null || !PrefixMatcher.IsMatch(_path, path))
            {
                return(_next(environment));
            }

            var connectionFactory = new PersistentConnectionFactory(_configuration.Resolver);
            var connection        = connectionFactory.CreateInstance(_connectionType);

            var handler = new CallHandler(_configuration, connection);

            return(handler.Invoke(environment));
        }
Ejemplo n.º 14
0
        public Task Invoke(IDictionary <string, object> environment)
        {
            var path = environment.Get <string>(OwinConstants.RequestPath);

            if (path == null || !path.StartsWith(_path, StringComparison.OrdinalIgnoreCase))
            {
                return(_app.Invoke(environment));
            }

            var connectionFactory = new PersistentConnectionFactory(_resolver);
            var connection        = connectionFactory.CreateInstance(_connectionType);

            var handler = new CallHandler(_resolver, connection);

            return(handler.Invoke(environment));
        }
Ejemplo n.º 15
0
            public void UsesDependencyResolver()
            {
                // Arrange
                var resolver        = new Mock <IDependencyResolver>();
                var factory         = new PersistentConnectionFactory(resolver.Object);
                var otherConnection = new MyOtherConnection();

                resolver.Setup(m => m.GetService(typeof(MyConnection)))
                .Returns(otherConnection);

                // Act
                PersistentConnection connection = factory.CreateInstance(typeof(MyConnection));

                // Assert
                Assert.NotNull(connection);
                Assert.Same(otherConnection, connection);
            }
Ejemplo n.º 16
0
        public override Task Invoke(IOwinContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (JsonUtility.TryRejectJSONPRequest(_configuration, context))
            {
                return(TaskAsyncHelper.Empty);
            }

            var connectionFactory           = new PersistentConnectionFactory(_configuration.Resolver);
            PersistentConnection connection = connectionFactory.CreateInstance(_connectionType);

            connection.Initialize(_configuration.Resolver);

            return(connection.ProcessRequest(context.Environment));
        }