public static TArgs AddNewMsg <TArgs>(TArgs msg) where TArgs : IRtcmMsg { lock (_msgTalkingStick) { Boolean isMaxMsgCtReached = _curMsgCt == _maxMessagesInMemoryCount; Int32 elementsToCopyCount = isMaxMsgCtReached ? _maxMessagesInMemoryCount - 1 // Copy all but the last element (because last element will be removed) : _curMsgCt; // Copy all elements currently in array // Shift elements and insert new msg to first index of new array IRtcmMsg[] tempArr = new IRtcmMsg[_maxMessagesInMemoryCount]; Array.Copy(_msgArr, 0, tempArr, 1, elementsToCopyCount); tempArr[0] = msg; _msgArr = tempArr; if (!isMaxMsgCtReached) { _curMsgCt++; } } return(msg); }
public static IRtcmMsg[] GetMessages() { IRtcmMsg[] result = new IRtcmMsg[0]; if (_curMsgCt == 0) { return(result); } lock (_msgTalkingStick) { result = new IRtcmMsg[_curMsgCt]; Array.Copy(_msgArr, 0, result, 0, _curMsgCt); } return(result); }
public static void PopulateInmateNames(this IRtcmMsg msg) { if (!msg.IsDataValid()) { return; } GetInmateArguments args = new GetInmateArguments(); args.InmateId = msg.Header.Pin; args.SiteId = msg.Header.SiteId; Inmate inmate = InmateRepo.GetInmate(args); if (inmate != null) { msg.Header.InmateFirstName = inmate.FirstName; msg.Header.InmateMiddleName = inmate.MiddleName; msg.Header.InmateLastName = inmate.LastName; } }
private static Boolean IsDataValid(this IRtcmMsg msg) { return(!(String.IsNullOrWhiteSpace(msg?.Header?.Pin) || String.IsNullOrWhiteSpace(msg.Header?.SiteId))); }