public static async Task <TArgs> AddAndBroadcast <TArgs>(TArgs msg) where TArgs : IRtcmMsg { IRtcmMsg addedMsg; List <String> domains; switch (msg.Header.EventCode) { case CtrlMsgType.WM_CTRL_MSG_EVENT_CALLSTART: EventCallStartMsg callStartMsg = msg as EventCallStartMsg; addedMsg = CircuitsMsgHandler.AddNewMsg(callStartMsg); domains = Caching.GetDomains(addedMsg.Header.SiteId); await _circuitsHub.Clients.Groups(domains).BroadcastAddCallStartMsg(addedMsg); break; case CtrlMsgType.WM_CTRL_MSG_EVENT_CALLEND: EventCallEndMsg callEndMsg = msg as EventCallEndMsg; addedMsg = CircuitsMsgHandler.AddNewMsg(callEndMsg); domains = Caching.GetDomains(addedMsg.Header.SiteId); await _circuitsHub.Clients.Groups(domains).BroadcastAddCallEndMsg(addedMsg); break; default: throw new ArgumentException($"Message type {msg.Header.EventCode} not supported"); } return((TArgs)addedMsg); }
public async Task <IHttpActionResult> AddCallEndMessage([FromBody] EventCallEndMsg msg) { try { if (msg?.Header == null || msg.Data == null) { _logger.LogWarning("Unable to deserialize EventCallEndMsg object. msg, msg.header, or msg.data was null."); return(BadRequest("Unable to deserialize EventCallEndMsg object.")); } try { msg.PopulateInmateNames(); } catch (Exception prodigyEx) { _logger.LogError(prodigyEx, $"Error getting inmate info within AddCallStartMessage pin: {msg.Header?.Pin ?? "null"} | site ID: {msg.Header?.SiteId ?? "null"}"); } EventCallEndMsg addedMsg = await CircuitsMsgRepo.AddAndBroadcast(msg); if (addedMsg == null) { ArgumentException argEx = new ArgumentException("Unable to broadcast event call end message"); _logger.LogError(argEx, "addedMsg returned null in add call-end message."); return(InternalServerError(argEx)); } return(Ok()); } catch (Exception ex) { _logger.LogError(ex, "Error adding RTCM call-end message."); return(InternalServerError(ex)); } }