public async Task ReceiveInternalAsync(object state) { var transport = state as IOicTransport ?? throw new ArgumentException(nameof(state)); var ct = _receiveCTS.Token; try { _logger?.LogDebug($"Receive task started for {transport}"); while (!ct.IsCancellationRequested) { var received = await transport.ReceiveMessageAsync(ct); // Middle ware sort of callback? _logger?.LogDebug($"received a message from {received.Endpoint}"); OicRequestHandle requestHandler = null; lock (_requestHandlers) _requestHandlers.TryGetValue(received.Message.RequestId, out requestHandler); if (requestHandler != null) { _logger?.LogDebug($"Setting response to message reqeust ({requestHandler.RequestId})"); _ = requestHandler?.SetReponseAsync(received.Message); } _ = Task.Factory.StartNew( async r => await _handler.HandleReceivedMessage((OicReceivedMessage)r), received, ct, TaskCreationOptions.RunContinuationsAsynchronously, TaskScheduler.Default); } } catch (Exception ex) { if (ct.IsCancellationRequested) { return; } _logger?.LogError(0, ex, $"Exception occured in {nameof(ReceiveInternalAsync)}"); } _logger?.LogDebug($"Receive task for {transport} has finished"); }
public OicRequestHandle GetHandle(OicMessage message) { if (message.RequestId == 0) { message.RequestId = GetNextRequestId(); } lock (_requestHandlers) { if (_requestHandlers.TryGetValue(message.RequestId, out var existingHandle)) { return(existingHandle); } var handle = new OicRequestHandle(this, message.RequestId); _requestHandlers.Add(handle.RequestId, handle); return(handle); } }
internal void RemoveHandle(OicRequestHandle handle) { lock (_requestHandlers) _requestHandlers.Remove(handle.RequestId); }