/// <summary> /// Callback which is fired when a client connected /// </summary> /// <returns></returns> public override async Task OnConnected() { // Search account from request. var httpContext = Context.Request.GetHttpContext(); // Http context is invalid. if (httpContext == null) { return; } // Search account from request. var account = (Account)httpContext.Items[ClaimTypes.Actor]; if (account == null) { return; } // Begin new life time scope. using (var lifeTimeScope = LifetimeScope.BeginLifetimeScope()) { // Search unit of work of life time scope. var unitOfWork = lifeTimeScope.Resolve <IUnitOfWork>(); var timeService = lifeTimeScope.Resolve <ITimeService>(); try { // Search and update connection to the account. var signalrConnection = new SignalrConnection(); signalrConnection.OwnerIndex = account.Id; signalrConnection.Index = Context.ConnectionId; signalrConnection.Created = timeService.DateTimeUtcToUnix(DateTime.UtcNow); unitOfWork.RepositorySignalrConnections.Insert(signalrConnection); await unitOfWork.CommitAsync(); Log.Info( $"Connection (Id: {Context.ConnectionId}) has been established from account (Email: {account.Email})"); } catch (Exception exception) { Log.Error(exception.Message, exception); } } }
public void Add(SignalrConnection connection) => _connections.Add(connection);