private static void ConfigureConnector(IApplicationBuilder app, DeviceConnectorService connectorService, AuthorizationService authorizationService) { app.Map("/Connector", config => { config.UseWebSockets(new WebSocketOptions { KeepAliveInterval = TimeSpan.FromMinutes(2), ReceiveBufferSize = 4096 }); config.Use(async(context, next) => { if (!context.WebSockets.IsWebSocketRequest) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } try { var authorizationContext = await authorizationService.AuthorizeDeviceAsync(context).ConfigureAwait(false); var deviceSessionIdentifier = new DeviceSessionIdentifier( authorizationContext.IdentityUid, authorizationContext.ChannelUid); using (var webSocket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false)) { await connectorService.RunAsync(deviceSessionIdentifier, webSocket, context.RequestAborted).ConfigureAwait(false); } } catch (UnauthorizedAccessException) { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; } finally { context.Abort(); } }); }); }
public void DeleteChannelStatistics(string identityUid, string channelUid = "default") { var deviceSessionIdentifier = new DeviceSessionIdentifier(identityUid, channelUid); _deviceConnectorService.ResetChannelStatistics(deviceSessionIdentifier); }
public IActionResult GetChannelStatistics(string identityUid, string channelUid = "default") { var deviceSessionIdentifier = new DeviceSessionIdentifier(identityUid, channelUid); return(new ObjectResult(_deviceConnectorService.GetChannelStatistics(deviceSessionIdentifier))); }