Ejemplo n.º 1
0
 public ChatController(
     IHubContext <ChatHub> hubContext,
     IQueueIntegration queueIntegration,
     IChatConfiguration configuration,
     ILogger <ChatController> logger)
 {
     _queueIntegration           = queueIntegration;
     _allowedCommands            = configuration.AllowedCommands;
     _broadCastMessageMethodName = configuration.BroadCastMethodName;
     _hubContext = hubContext;
     _logger     = logger;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Instantiate a object to publish a message in rabbitmq
        /// </summary>
        public RabbitMqIntegration(
            IModel channel,
            IChatConfiguration configuration)
        {
            _queueName = configuration.QueueName;
            _channel   = channel;
            _channel.QueueDeclare(queue: _queueName,
                                  durable: false,
                                  exclusive: false,
                                  autoDelete: false,
                                  arguments: null);

            var consumer = new EventingBasicConsumer(_channel);
        }
Ejemplo n.º 3
0
        public ChatControllerTests()
        {
            _hubContext       = Mock.Create <IHubContext <ChatHub> >();
            _logger           = Mock.Create <ILogger <ChatController> >();
            _queueIntegration = Mock.Create <IQueueIntegration>();
            _configuration    = Mock.Create <IChatConfiguration>();

            Mock.Arrange(() => _configuration.AllowedCommands).Returns(
                new System.Collections.Generic.HashSet <string>
            {
                "/STOCK"
            });

            _controller = new ChatController(_hubContext, _queueIntegration, _configuration, _logger);
        }
Ejemplo n.º 4
0
        private static void SetupSignalR(IChatConfiguration ChatConfig, IKernel kernel, IAppBuilder app)
        {
            var resolver          = new NinjectSignalRDependencyResolver(kernel);
            var connectionManager = resolver.Resolve <IConnectionManager>();
            var heartbeat         = resolver.Resolve <ITransportHeartbeat>();
            var hubPipeline       = resolver.Resolve <IHubPipeline>();
            var configuration     = resolver.Resolve <IConfigurationManager>();

            // Enable service bus scale out
            if (!String.IsNullOrEmpty(ChatConfig.ServiceBusConnectionString) &&
                !String.IsNullOrEmpty(ChatConfig.ServiceBusTopicPrefix))
            {
                var sbConfig = new ServiceBusScaleoutConfiguration(ChatConfig.ServiceBusConnectionString,
                                                                   ChatConfig.ServiceBusTopicPrefix)
                {
                    TopicCount = 5
                };

                resolver.UseServiceBus(sbConfig);
            }

            if (ChatConfig.ScaleOutSqlServer)
            {
                resolver.UseSqlServer(ChatConfig.SqlConnectionString.ConnectionString);
            }

            kernel.Bind <IConnectionManager>()
            .ToConstant(connectionManager);

            // We need to extend this since the inital connect might take a while
            configuration.TransportConnectTimeout = TimeSpan.FromSeconds(30);

            var config = new HubConfiguration
            {
                Resolver = resolver
            };

            hubPipeline.AddModule(kernel.Get <LoggingHubPipelineModule>());

            app.MapSignalR(config);
            //心跳定时任务
            var monitor = new PresenceMonitor(kernel, connectionManager, heartbeat);

            monitor.Start();
        }
Ejemplo n.º 5
0
        public HomeModule(ApplicationSettings settings,
                          IMembershipService membershipService,
                          IUserAuthenticator authenticator,
                          IRepository <ChatUser> repository,
                          IChatConfiguration configuration
                          )
        {
            Get["/"] = _ =>
            {
                if (IsAuthenticated)
                {
                    var viewModel = new SettingsViewModel
                    {
                        GoogleAnalytics         = settings.GoogleAnalytics,
                        AppInsights             = settings.AppInsights,
                        Sha                     = configuration.DeploymentSha,
                        Branch                  = configuration.DeploymentBranch,
                        Time                    = configuration.DeploymentTime,
                        DebugMode               = (bool)Context.Items["_debugMode"],
                        Version                 = Constants.ChatVersion,
                        IsAdmin                 = Principal.HasClaim(ChatClaimTypes.Admin),
                        ClientLanguageResources = BuildClientResources(),
                        MaxMessageLength        = settings.MaxMessageLength,
                        AllowRoomCreation       = settings.AllowRoomCreation || Principal.HasClaim(ChatClaimTypes.Admin)
                    };

                    return(View["index", viewModel]);
                }

                if (Principal != null && Principal.HasPartialIdentity())
                {
                    // If the user is partially authenticated then take them to the register page
                    return(Response.AsRedirect("~/account/register"));
                }

                return(HttpStatusCode.Unauthorized);
            };
        }
Ejemplo n.º 6
0
 public StartupDoMigrations(IChatConfiguration config, IKernel kernel)
 {
     _kernel = kernel;
     _config = config;
 }
Ejemplo n.º 7
0
 public ChatHub(IChatConfiguration configuration)
 {
     _broadCastMessageMethodName = configuration.BroadCastMethodName;
 }