Пример #1
0
 /// <summary>
 /// Leave the parameters to be null when called by Azure Function infrastructure.
 /// Or you can pass in your parameters in testing.
 /// </summary>
 protected ServerlessHub(IServiceHubContext hubContext = null, IServiceManager serviceManager = null)
 {
     HubName         = GetType().Name;
     hubContext      = hubContext ?? StaticServiceHubContextStore.Get().GetAsync(HubName).GetAwaiter().GetResult();
     _serviceManager = serviceManager ?? StaticServiceHubContextStore.Get().ServiceManager;
     Clients         = hubContext.Clients;
     Groups          = hubContext.Groups;
     UserGroups      = hubContext.UserGroups;
 }
Пример #2
0
        public async Task InitAsync()
        {
            var serviceManager = new ServiceManagerBuilder().WithOptions(option =>
            {
                option.ConnectionString     = _connectionString;
                option.ServiceTransportType = _serviceTransportType;
            }).Build();

            _hubContext = await serviceManager.CreateHubContextAsync(HubName, new LoggerFactory());
        }
Пример #3
0
        private async Task Initialize()
        {
            serviceManager = new ServiceManagerBuilder().WithOptions(option =>
            {
                option.ConnectionString = shared.connectionstring;
                // we choose the REST API. we could also go for websockets transport
                option.ServiceTransportType = ServiceTransportType.Transient;
            }).Build();

            _hubContext = await serviceManager.CreateHubContextAsync(Shared.hubname, new LoggerFactory());
        }
Пример #4
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var serviceManager = new ServiceManagerBuilder().WithOptions(option =>
            {
                option.ConnectionString = _config[ENV_SIGNALR];
            }).Build();

            _notificationHub = await serviceManager.CreateHubContextAsync(HubName);

            ConnectToQueue();
        }
        /// <summary>
        /// Leave the parameters to be null when called by Azure Function infrastructure.
        /// Or you can pass in your parameters in testing.
        /// </summary>
        protected ServerlessHub(IServiceHubContext hubContext = null, IServiceManager serviceManager = null)
        {
            var hubContextAttribute = GetType().GetCustomAttribute <SignalRConnectionAttribute>(true);
            var connectionString    = hubContextAttribute?.Connection ?? Constants.AzureSignalRConnectionStringName;

            HubName         = GetType().Name;
            hubContext      = hubContext ?? StaticServiceHubContextStore.Get(connectionString).GetAsync(HubName).GetAwaiter().GetResult();
            _serviceManager = serviceManager ?? StaticServiceHubContextStore.Get(connectionString).ServiceManager;
            Clients         = hubContext.Clients;
            Groups          = hubContext.Groups;
            UserGroups      = hubContext.UserGroups;
            _hubContext     = hubContext as ServiceHubContext;
            ClientManager   = _hubContext?.ClientManager;
        }
Пример #6
0
        private static async Task SendToGroupCore(IServiceHubContext serviceHubContext, Func <Task> sendTask)
        {
            await Task.WhenAll(from i in Enumerable.Range(0, _userNames.Length)
                               select serviceHubContext.UserGroups.AddToGroupAsync(_userNames[i], _groupNames[i % _groupNames.Length]));

            await Task.Delay(_timeout);

            await sendTask();

            await Task.Delay(_timeout);

            await Task.WhenAll(from i in Enumerable.Range(0, _userNames.Length)
                               select serviceHubContext.UserGroups.RemoveFromGroupAsync(_userNames[i], _groupNames[i % _groupNames.Length]));

            await Task.Delay(_timeout);

            await sendTask();

            await Task.Delay(_timeout);
        }
Пример #7
0
        private static async Task SendToGroupCore(
            IServiceHubContext serviceHubContext,
            IDictionary <string, List <string> > userGroupDict,
            Func <Task> sendTask, Func <IServiceHubContext, IDictionary <string, List <string> >, Task> userAddToGroupTask,
            Func <IServiceHubContext, IDictionary <string, List <string> >, Task> userRemoveFromGroupTask)
        {
            await userAddToGroupTask(serviceHubContext, userGroupDict);

            await Task.Delay(_timeout);

            await sendTask();

            await Task.Delay(_timeout);

            await userRemoveFromGroupTask(serviceHubContext, userGroupDict);

            await Task.Delay(_timeout);

            await sendTask();

            await Task.Delay(_timeout);
        }
Пример #8
0
 /// <summary>
 /// Leave the parameters to be null when called by Azure Function infrastructure.
 /// Or you can pass in your parameters in testing.
 /// </summary>
 protected ServerlessHub(IServiceHubContext hubContext = null, IServiceManager serviceManager = null)
 {
     _hubContext     = hubContext ?? StaticServiceHubContextStore.Get(ConnectionName).GetAsync(HubName).GetAwaiter().GetResult();
     _serviceManager = serviceManager ?? StaticServiceHubContextStore.Get(ConnectionName).ServiceManager;
 }
Пример #9
0
 // Use default value = null to reconcile testing and production purpose.
 public MyHub(IServiceHubContext hubContext = null, IServiceManager serviceManager = null) : base(hubContext, serviceManager)
 {
 }
 static Task Empty(IServiceHubContext context, IDictionary <string, List <string> > dict) =>
 Task.CompletedTask;
Пример #11
0
 protected override async Task RestSendMessage(IServiceHubContext hubContext)
 {
     await RestBroadcastMessage(hubContext);
 }
Пример #12
0
 private static Task UserRemoveFromAllGroupsAsync(IServiceHubContext serviceHubContext, IDictionary <string, List <string> > userGroupDict)
 {
     return(Task.WhenAll(from user in userGroupDict.Keys
                         select serviceHubContext.UserGroups.RemoveFromAllGroupsAsync(user)));
 }
Пример #13
0
 private static Task UserRemoveFromGroupsOneByOneAsync(IServiceHubContext serviceHubContext, IDictionary <string, List <string> > userGroupDict)
 {
     return(Task.WhenAll(from usergroup in userGroupDict
                         select Task.WhenAll(from grp in usergroup.Value
                                             select serviceHubContext.UserGroups.RemoveFromGroupAsync(usergroup.Key, grp))));
 }
Пример #14
0
 public Functions(IServiceHubContext hubContext = null, IServiceManager serviceManager = null) : base(hubContext, serviceManager)
 {
 }
Пример #15
0
 internal ServerlessHub(IServiceManagerStore store)
 {
     _hubContext     = store.GetOrAddByConnectionStringKey(ConnectionName).GetAsync(HubName).GetAwaiter().GetResult();
     _serviceManager = store.GetOrAddByConnectionStringKey(ConnectionName).ServiceManager;
 }
Пример #16
0
 public GameController(ILogger <GameController> logger, IServiceHubContext hub)
 {
     _logger = logger;
     _hub    = hub;
 }
 public AppointmentsController(Task <IServiceHubContext> serviceHubContextTask, ConnectionMultiplexer redisConnection)
 {
     this.hubContext = serviceHubContextTask.Result;
     this.redis      = redisConnection.GetDatabase();
 }