private async Task <Tuple <bool, List <DeviceConfigMsg> > > ProcessMessage(DeviceConfigurationSettingsConfig settingsConfig, DeviceConfigRequestBase request, DeviceConfigMessage deviceConfigMessage, List <DeviceConfigMsg> deviceConfigMsgs) { if (settingsConfig != null && !settingsConfig.SendToDevice) { //Dont insert into DeviceConfigMessage table. Just process the msg and publish to new Kafka topics this._loggingService.Info("Started Invoking ProcessBypassMessage", "DeviceConfigRepositoryServiceBase.ProcessMessage"); return(Tuple.Create <bool, List <DeviceConfigMsg> >(_ackBypasser.ProcessBypassMessage(request, deviceConfigMessage.Group), null)); } else { this._loggingService.Info("Started Invoking ProcessMessage", "DeviceConfigRepositoryServiceBase.ProcessMessage"); return(_messageConstructor.ProcessMessage(await GetRequestAndHandleForNullCases(request), deviceConfigMessage)); } }
public async Task <DevicePingStatusResponse> PostDevicePingRequest(DevicePingLogRequest request) { PingRequestStatus pingRequestStatus = new PingRequestStatus(); DevicePingStatusResponse response; DevicePingLogRequest validatedRequest = new DevicePingLogRequest(); Guid devicePingLogUID = Guid.Empty; List <IErrorInfo> errorInfos = new List <IErrorInfo>(); response = new DevicePingStatusResponse { AssetUID = request.AssetUID.ToString(), DeviceUID = request.DeviceUID.ToString(), }; errorInfos.AddRange(await base.Validate(this._validators, request)); errorInfos.AddRange(await this._pingValidator.Validate(request)); //errorInfos.AddRange(await this.ValidateDuplicateRequest(request)); var latestRequest = await _devicePingRepository.Fetch(request); if (latestRequest != null) { if (((latestRequest.RequestStatusID == (int)RequestStatus.Pending) || (latestRequest.RequestStatusID == (int)RequestStatus.Acknowledged)) && DateTime.UtcNow <= latestRequest.RequestExpiryTimeUTC) { errorInfos.AddRange(new List <IErrorInfo>() { (new ErrorInfo() { Message = Utils.GetEnumDescription(ErrorCodes.DuplicatePingRequest), ErrorCode = (int)ErrorCodes.DuplicatePingRequest }) }); response.AssetUID = latestRequest.AssetUID.ToString(); response.DeviceUID = latestRequest.DeviceUID.ToString(); response.DevicePingLogUID = latestRequest.DevicePingLogUID.ToString(); response.RequestExpiryTimeUTC = latestRequest.RequestExpiryTimeUTC; response.RequestStatusID = latestRequest.RequestStatusID; RequestStatus rs = (RequestStatus)latestRequest.RequestStatusID; response.RequestState = rs.ToString(); response.RequestTimeUTC = latestRequest.RequestTimeUTC; } } if (errorInfos.Count <= 0) { try { DeviceTypeFamily deviceTypeFamily = await _devicePingRepository.GetDeviceTypeFamily(request.DeviceUID); if (deviceTypeFamily == null) { errorInfos.Add(new ErrorInfo { ErrorCode = (int)ErrorCodes.DeviceTypeFamilyNotSupported, Message = Utils.GetEnumDescription(ErrorCodes.DeviceTypeFamilyNotSupported), IsInvalid = true, }); response.Errors = errorInfos; return(response); } request.FamilyName = deviceTypeFamily.FamilyName; devicePingLogUID = _messageConstructor.ProcessMessage(request.AssetUID, request.DeviceUID, deviceTypeFamily.FamilyName); if (devicePingLogUID == Guid.Empty) { errorInfos.Add(new ErrorInfo { ErrorCode = (int)ErrorCodes.UnexpectedError, Message = Utils.GetEnumDescription(ErrorCodes.UnexpectedError), IsInvalid = true, }); response.Errors = errorInfos; return(response); } request.DevicePingLogUID = devicePingLogUID; this._loggingService.Info("Started Invoking DevicePingRepository with request : " + JsonConvert.SerializeObject(request), "DevicePingService.Insert"); pingRequestStatus = await this._devicePingRepository.Insert(request); this._loggingService.Info("Ended Invoking DevicePingRepository with response : " + JsonConvert.SerializeObject(pingRequestStatus), "DevicePingService.Insert"); response = _mapper.Map <DevicePingStatusResponse>(pingRequestStatus); } catch (Exception ex) { response.Errors.Add(new ErrorInfo { ErrorCode = (int)ErrorCodes.UnexpectedError, Message = Utils.GetEnumDescription(ErrorCodes.UnexpectedError), IsInvalid = true, }); this._loggingService.Error("Exception occurred while saving Ping Request", "PingController.PostDevicePingRequest", ex); throw ex; } } else { response.Errors = errorInfos; } return(response); }