public async Task <JsonResult> Communicate(string clientId, string channels = null, string indexes = null, string sendChannel = null, string sendData = null) { if (sendChannel != null && sendData != null) { _ = ChannelHub.SendMessageAsync(clientId, sendChannel, sendData); } if (channels == null) { return(new JsonResult(new List <object>())); } if (indexes == null) { indexes = "0"; } var channelData = await ChannelHub.GetMessagesSinceEpochAsync(clientId, channels.Split('|'), indexes.Split('|').Select(a => long.Parse(indexes)).ToArray()); return(new JsonResult(channelData)); }
public async Task <JsonResult> Communicate([FromBody] CommunicateData data) { if (data == null) { return(new JsonResult("Error")); } // Receive all messages since epoch, and optionally send data if (data.SendChannel != null && data.SendData != null) { _ = ChannelHub.SendMessageAsync(data.ClientId, data.SendChannel, data.SendData); } if (data.Channels == null) { return(new JsonResult(new List <object>())); } var channelData = await ChannelHub.GetMessagesSinceEpochAsync(data.ClientId, data.Channels, data.Indexes); return(new JsonResult(channelData)); }
protected override async ValueTask DisposeInternalAsync(bool disposing) { ChannelHub.Attached -= OnChannelAttachedHandler; // Must go first ChannelHub.Detached -= OnChannelDetachedHandler; var channelProcessors = ChannelProcessors; while (!channelProcessors.IsEmpty) { var tasks = channelProcessors .Take(HardwareInfo.ProcessorCount * 4) .ToList() .Select(p => { var(_, channelProcessor) = (p.Key, p.Value); return(channelProcessor.DisposeAsync().AsTask()); }); await Task.WhenAll(tasks).ConfigureAwait(false); } var publications = PublicationsById; while (!publications.IsEmpty) { var tasks = publications .Take(HardwareInfo.ProcessorCount * 4) .ToList() .Select(p => { var(_, publication) = (p.Key, p.Value); return(publication.DisposeAsync().AsTask()); }); await Task.WhenAll(tasks).ConfigureAwait(false); } if (OwnsChannelHub) { await ChannelHub.DisposeAsync().ConfigureAwait(false); } await base.DisposeInternalAsync(disposing).ConfigureAwait(false); }