public async Task RenewActiveConnectionAsync(string connectionId) { _logger?.Verbose("Renewing last activity. connection-id={ConnectionId}", connectionId); try { using (var context = new RelayContext()) { var activeConnection = await context.ActiveConnections.FirstOrDefaultAsync(ac => ac.ConnectionId == connectionId).ConfigureAwait(false); if (activeConnection != null) { activeConnection.LastActivity = DateTime.UtcNow; context.Entry(activeConnection).State = EntityState.Modified; await context.SaveChangesAsync().ConfigureAwait(false); } } } catch (Exception ex) { _logger?.Error(ex, "Error during renewing an active connection. connection-id={ConnectionId}", connectionId); } }
public async Task AddOrRenewActiveConnectionAsync(Guid linkId, Guid originId, string connectionId, int connectorVersion, string assemblyVersion) { _logger?.Verbose("Adding or updating connection. connection-id={ConnectionId}, link-id={LinkId}, connector-version={ConnectorVersion}, connector-assembly-version={ConnectorAssemblyVersion}", connectionId, linkId, connectorVersion, assemblyVersion); try { using (var context = new RelayContext()) { var activeConnection = await context.ActiveConnections .FirstOrDefaultAsync(ac => ac.LinkId == linkId && ac.OriginId == originId && ac.ConnectionId == connectionId).ConfigureAwait(false); if (activeConnection != null) { activeConnection.LastActivity = DateTime.UtcNow; activeConnection.ConnectorVersion = connectorVersion; activeConnection.AssemblyVersion = assemblyVersion; context.Entry(activeConnection).State = EntityState.Modified; } else { context.ActiveConnections.Add(new DbActiveConnection() { LinkId = linkId, OriginId = originId, ConnectionId = connectionId, ConnectorVersion = connectorVersion, AssemblyVersion = assemblyVersion, LastActivity = DateTime.UtcNow, }); } await context.SaveChangesAsync().ConfigureAwait(false); } } catch (Exception ex) { _logger?.Error(ex, "Error during adding or renewing an active connection. link-id={LinkId}, connection-id={ConnectionId}, connector-version={ConnectorVersion}, connector-assembly-version={ConnectorAssemblyVersion}", linkId, connectionId, connectorVersion, assemblyVersion); } }
public async Task RemoveActiveConnectionAsync(string connectionId) { _logger?.Verbose("Deleting active connection. connection-id={ConnectionId}", connectionId); try { using (var context = new RelayContext()) { var activeConnection = await context.ActiveConnections.FirstOrDefaultAsync(ac => ac.ConnectionId == connectionId).ConfigureAwait(false); if (activeConnection != null) { context.ActiveConnections.Remove(activeConnection); await context.SaveChangesAsync().ConfigureAwait(false); } } } catch (Exception ex) { _logger?.Error(ex, "Error during removing an active connection. connection-id={ConnectionId}", connectionId); } }