private PendingDeviceConfigRequest BuildPendingDeviceConfigRequest(DeviceConfigRequestBase deviceConfigMessage, IEnumerable <Guid> deviceUIDs, DateTime currentDateTimeUTC) { IList <AssetDeviceConfigRequestDto> assetDeviceConfigRequestDtos = new List <AssetDeviceConfigRequestDto>(); this._loggingService.Info("Started building pending device config with request : " + JsonConvert.SerializeObject(deviceConfigMessage), "DeviceConfigRepositoryServiceBase.BuildPendingDeviceConfigRequest"); foreach (var config in deviceConfigMessage.ConfigValues) { var keys = config.Key.Split('.'); if (_paramterAttributeDetails.ContainsKey(config.Key)) { assetDeviceConfigRequestDtos.Add(new AssetDeviceConfigRequestDto { DeviceType = deviceConfigMessage.DeviceType, GroupName = deviceConfigMessage.ParameterGroupName, ParameterName = keys[0], AttributeName = keys[1], AttributeValue = config.Value, ActionUTC = currentDateTimeUTC, DeviceUIDs = deviceUIDs }); } } this._loggingService.Info("Ended building pending device config", "DeviceConfigRepositoryServiceBase.BuildPendingDeviceConfigRequest"); return(new PendingDeviceConfigRequest { PendingDeviceConfigs = assetDeviceConfigRequestDtos }); }
protected async virtual Task <List <DeviceConfigDto> > Fetch(DeviceConfigRequestBase request) { this._loggingService.Info("Fetching for DeviceConfigRequestBase with request : " + JsonConvert.SerializeObject(request), "DeviceConfigRepositoryServiceBase.Fetch"); IList <DeviceConfigDto> deviceConfigDtos = new List <DeviceConfigDto>(); await this.GetAttributeIds(request.DeviceType, request.ParameterGroupName); foreach (var attributeId in base._paramterAttributeDetails) { deviceConfigDtos.Add(new DeviceConfigDto { DeviceTypeParameterID = attributeId.Value.DeviceTypeParameterID, DeviceParameterAttributeId = attributeId.Value.DeviceParamAttrID }); } this._loggingService.Info("Started Invoking DeviceConfigRepository with request : " + JsonConvert.SerializeObject(request), "DeviceConfigRepositoryServiceBase.Fetch"); var deviceConfigResponseDtos = await this._deviceConfigRepository.Fetch(request.AssetUIDs, deviceConfigDtos); this._loggingService.Info("Ended Invoking DeviceConfigRepository with response : " + JsonConvert.SerializeObject(deviceConfigResponseDtos), "DeviceConfigRepositoryServiceBase.Fetch"); return(this.AssignPendingInfo(request, deviceConfigResponseDtos)); }
public async Task <ActionResult <DeviceConfigSwitchesResponse> > Fetch(DeviceConfigRequestBase request, [FromQuery] int switchNumber = 0) { request = await base.ReadRequestContentAsync <DeviceConfigRequestBase>(request); if (request == null) { throw new DomainException { Error = new ErrorInfo { ErrorCode = (int)ErrorCodes.RequestInvalid, Message = Utils.GetEnumDescription(ErrorCodes.RequestInvalid), IsInvalid = true } } } ; _loggingService.Info("Request Processing Started", MethodBase.GetCurrentMethod().Name); var switchesRequest = new DeviceConfigSwitchesRequest(); var parameterNames = _iInjectConfig.ResolveKeyed <DeviceConfigParameterNames>("DeviceConfigParameterNames"); switchesRequest.ParameterGroupName = Convert.ToString(parameterNames.Values["SwitchesParameterGroupName"]); switchesRequest.AssetUIDs = request.AssetUIDs; switchesRequest.DeviceType = request.DeviceType; switchesRequest.UserUID = base.GetUserContext(Request); switchesRequest.CustomerUID = base.GetCustomerContext(Request); switchesRequest.ConfigValues = new Dictionary <string, string>(); switchesRequest.SwitchNumber = switchNumber; _loggingService.Info("About to Fetch From Database", MethodBase.GetCurrentMethod().Name); var response = await _deviceConfigService.Fetch(switchesRequest); return(base.SendResponse(HttpStatusCode.OK, new DeviceConfigSwitchesResponse(response.Lists.Select(list => list as DeviceConfigSwitches), response.Errors.Select(error => error as AssetErrorInfo).ToList()))); }
protected virtual void CheckForInvalidRecords(DeviceConfigRequestBase request, List <IErrorInfo> errorInfos, bool assetUIDCheckRequired = true) { this._loggingService.Info("Started Checking for Invalid Records", "DeviceConfigServiceBase.CheckForInvalidRecords"); var invalidRecords = errorInfos.Where(x => x.IsInvalid); if (errorInfos.Where(x => x.IsInvalid).Any()) { this._loggingService.Info("Ignoring request since following records are invalid : " + JsonConvert.SerializeObject(invalidRecords), "DeviceConfigServiceBase.CheckForInvalidRecords"); throw new DomainException { Errors = errorInfos }; } if (assetUIDCheckRequired) { if (request.AssetUIDs == null || !request.AssetUIDs.Any()) { throw new DomainException { Errors = errorInfos.Any() ? errorInfos : new List <IErrorInfo> { new ErrorInfo { ErrorCode = (int)ErrorCodes.AssetUIDListNull, Message = Utils.GetEnumDescription(ErrorCodes.AssetUIDListNull) } } }; } this._loggingService.Info("Ignoring request since following records are invalid : " + JsonConvert.SerializeObject(invalidRecords), "DeviceConfigServiceBase.CheckForInvalidRecords"); } this._loggingService.Info("Ended Checking for Invalid Records", "DeviceConfigServiceBase.CheckForInvalidRecords"); }
private List <DeviceConfigDto> AssignPendingInfo(DeviceConfigRequestBase request, IEnumerable <DeviceConfigDto> deviceConfigDtos) { /* * (CASE * WHEN(DC.LastAttrEventUTC IS NULL OR DC.FutureAttrEventUTC >= DC.LastAttrEventUTC) THEN DC.FutureAttributeValue * ELSE DC.AttributeValue * END) AS AttributeValue, * (CASE * WHEN(DC.FutureAttrEventUTC IS NOT NULL AND DC.FutureAttrEventUTC >= DC.LastAttrEventUTC) THEN DC.FutureAttrEventUTC * WHEN(DC.LastAttrEventUTC IS NOT NULL AND DC.LastAttrEventUTC >= DC.FutureAttrEventUTC) THEN DC.LastAttrEventUTC * ELSE DC.UpdateUTC * END) AS UpdateUTC, * (CASE * WHEN (DC.LastAttrEventUTC IS NOT NULL AND DC.LastAttrEventUTC >= DC.FutureAttrEventUTC) THEN 0 * ELSE 1 * END) AS IsPending */ foreach (var deviceConfigDto in deviceConfigDtos) { deviceConfigDto.AttributeValue = deviceConfigDto.FutureAttributeValue; deviceConfigDto.IsPending = true; deviceConfigDto.UpdateUTC = deviceConfigDto.RowUpdatedUTC; if (deviceConfigDto.FutureAttributeEventUTC.HasValue) { if (_pendingClearOffDeviceTypes.Contains(request.DeviceType) && DateTime.UtcNow.Subtract(deviceConfigDto.FutureAttributeEventUTC.Value).Days > _pendingClearOffDays) { deviceConfigDto.IsPending = false; deviceConfigDto.AttributeValue = deviceConfigDto.CurrentAttributeValue; deviceConfigDto.UpdateUTC = deviceConfigDto.LastAttributeEventUTC.HasValue ? deviceConfigDto.LastAttrEventUTC : deviceConfigDto.RowUpdatedUTC; } else { if (deviceConfigDto.LastAttributeEventUTC.HasValue) { if (deviceConfigDto.LastAttributeEventUTC.Value >= deviceConfigDto.FutureAttributeEventUTC.Value) { deviceConfigDto.AttributeValue = deviceConfigDto.CurrentAttributeValue; deviceConfigDto.UpdateUTC = deviceConfigDto.LastAttrEventUTC; deviceConfigDto.IsPending = false; } else { deviceConfigDto.UpdateUTC = deviceConfigDto.FutureAttrEventUTC; } } } } else { deviceConfigDto.AttributeValue = deviceConfigDto.CurrentAttributeValue; deviceConfigDto.UpdateUTC = deviceConfigDto.LastAttributeEventUTC.HasValue ? deviceConfigDto.LastAttrEventUTC : deviceConfigDto.UpdateUTC; deviceConfigDto.IsPending = false; } } return(deviceConfigDtos.ToList()); }
protected async Task <List <IErrorInfo> > DoValidation(DeviceConfigRequestBase request) { var errorInfos = new List <IErrorInfo>(); var _toValidate = _commonDeviceLevelValidators.Where(validators => string.Compare(validators.GetType().Name, "AllAttributeAsMandatoryValidator", StringComparison.OrdinalIgnoreCase) != 0); errorInfos.AddRange(await this.Validate(_requestInvalidateValidators, request)); errorInfos.AddRange(await this.Validate(_toValidate, request)); base.CheckForInvalidRecords(request, errorInfos); return(errorInfos); }
public DeviceConfigurationSettingsConfig GetSettingsConfig(DeviceConfigRequestBase requestBase, IDictionary <string, DeviceTypeGroupParameterAttributeDetails> attributeIds) { this._loggingService.Info("Device Request Message : " + JsonConvert.SerializeObject(requestBase), "DeviceConfigSettingConfigBase.GetSettingsConfig"); if (requestBase == null || !_groupContainer.ContainsKey(requestBase.ParameterGroupName)) { this._loggingService.Info("Device Message Group Name / Device Type is invalid !!", "DeviceConfigSettingConfigBase.GetSettingsConfig"); return(null); } var groupBuilder = _groupContainer[requestBase.ParameterGroupName]; var groupSettings = groupBuilder.GetSettingsConfig(attributeIds); return(groupSettings); }
private void SetupController(DeviceConfigRequestBase request, Guid?customerUID, Guid?userUID) { _target = _injectConfig.Resolve <DeviceConfigAssetSecurityController>(); _target.ControllerContext = GetMockHttpContext(); if (customerUID != null) { _target.ControllerContext.HttpContext.Request.Headers.Add(Constants.VISIONLINK_CUSTOMERUID, customerUID.ToString()); } if (userUID != null) { _target.ControllerContext.HttpContext.Request.Headers.Add(Constants.USERUID_API, userUID.ToString()); } _target.ControllerContext.HttpContext.Request.Body = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request))); }
private DeviceConfigMessage BuildDeviceConfigMessage(DeviceConfigRequestBase request, string currentDateTimeUTC) { var deviceConfigMessage = new DeviceConfigMessage { Group = new ParamGroup { GroupName = request.ParameterGroupName, Parameters = new List <Parameter>() }, Timestamp = new TimestampDetail { EventUtc = DateTime.Parse(currentDateTimeUTC) } }; foreach (var item in request.ConfigValues) { if (this._paramterAttributeDetails.ContainsKey(item.Key)) { var parameterAttribute = item.Key.Split('.'); var parameter = deviceConfigMessage.Group.Parameters.FirstOrDefault(x => x.ParameterName == parameterAttribute[0]); if (parameter == null) { parameter = new Parameter { ParameterName = parameterAttribute[0] }; } if (parameter.Attributes == null) { parameter.Attributes = new List <AttributeDetails>(); } parameter.Attributes.Add( new AttributeDetails { AttributeName = parameterAttribute[1], AttributeValue = item.Value }); if (!deviceConfigMessage.Group.Parameters.Any(x => x.ParameterName == parameterAttribute[0])) { deviceConfigMessage.Group.Parameters.Add(parameter); } } } return(deviceConfigMessage); }
public void Valid_Fetch_Request() { string AssetUID = "14da462c-f23e-499f-8ed1-50467d8b57ac"; var deviceConfigBaseRequest = new DeviceConfigRequestBase() { AssetUIDs = new System.Collections.Generic.List <string>() { AssetUID }, DeviceType = "PL121", }; //SetupController(deviceConfigBaseRequest, Guid.NewGuid(), Guid.NewGuid()); //var res = _target.Fetch(deviceConfigBaseRequest); Assert.True(1 == 1); }
private OdometerOffset GetOdometerOffsetMessageEvent(DeviceConfigRequestBase requestBase) { _loggingService.Info("Started processing odometer offset values", "MetersMessageBuilder.GetOdometerOffsetMessageEvent"); var odometerOffsetEvent = new OdometerOffset(); var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigMetersRequest>(requestBase); if (requestMessage.OdoMeter != null) { if (requestMessage.OdoMeter.ProposedValue.HasValue) { odometerOffsetEvent.Offset = Math.Round(Convert.ToDouble(requestMessage.OdoMeter.ProposedValue - Convert.ToDouble(requestMessage.OdoMeter.CurrentValue)), 10); } } _loggingService.Info("Ended processing odometer offset values", "MetersMessageBuilder.GetOdometerOffsetMessageEvent"); return(odometerOffsetEvent); }
private async Task ProcessAndSaveDeviceConfig(DeviceConfigRequestBase request, List <DeviceConfigDto> deviceConfigResponseDtos, string currentDateTimeUTC, Dictionary <Guid, Guid> assetDeviceMaps) { this._loggingService.Info("Started Invoking ProcessAndSaveDeviceConfig", "DeviceConfigRepositoryServiceBase.BuildResponse"); var deviceConfigMsgs = new List <DeviceConfigMsg>(); var deviceConfigMessage = this.BuildDeviceConfigMessage(request, currentDateTimeUTC); // To check for following a different path for TAP66/76 devices as these device types will not acknowledge the device config values var settingConfig = _settingsConfig.GetSettingsConfig(request, base._paramterAttributeDetails); this._loggingService.Info("Invoking Message Constructor with DeviceConfigRequest : " + JsonConvert.SerializeObject(deviceConfigMessage) + " and DeviceConfigMessage : " + JsonConvert.SerializeObject(deviceConfigMessage), "DeviceConfigRepositoryServiceBase.BuildResponse"); var deviceConfigProcessedMsg = await ProcessMessage(settingConfig, request, deviceConfigMessage, deviceConfigMsgs); if (deviceConfigProcessedMsg.Item1) { var deviceUIDs = assetDeviceMaps.Values; SaveDeviceConfigAndDeviceConfigMessage(deviceConfigResponseDtos, deviceConfigProcessedMsg.Item2); //Update Current Value for TAP66/76 as the ackowledgement processor will not do this await UpdateCurrentAttributeValues(settingConfig, request); var pendingDeviceConfigMessage = this.BuildPendingDeviceConfigRequest(request, deviceUIDs, DateTime.Parse(currentDateTimeUTC)); //this._loggingService.Info("Invoking Pending Device Config api with url : " + _assetDeviceConfigApiUrl + " with request : " + JsonConvert.SerializeObject(pendingDeviceConfigMessage), "DeviceConfigRepositoryServiceBase.BuildResponse"); //await _apiClient.PutAsync<object>(_assetDeviceConfigApiUrl, pendingDeviceConfigMessage); //this._loggingService.Info("Ended Invoking Device Config api", "DeviceConfigRepositoryServiceBase.BuildResponse"); //Construct DeviceConfiguredMessage to publish for TAP66/76 deviceTypes as the devices will not acknowledge the parameters. Hence we are by passing Acknowledgement processor by publishing from API itself if (settingConfig != null && settingConfig.AllowAdditionalTopic) { var isConfigured = _ackBypasser.PublishConfiguredMessage(deviceConfigMessage, deviceUIDs); } } this._loggingService.Info("Ended Invoking SaveDeviceConfig", "DeviceConfigRepositoryServiceBase.BuildResponse"); }
public IEnumerable <object> ProcessGroupMessages(string assetuid, DeviceConfigRequestBase requestBase, ParamGroup group) { //Get device type parameter names as collection. _loggingService.Info("Started processing group messages", "MetersMessageBuilder.ProcessGroupMessages"); var metersMessages = new List <object>(); foreach (var param in group.Parameters) { if (param.ParameterName == "HoursMeter") { var hourMtroffsetDataObj = GetHourMeterOffsetMessageEvent(requestBase); hourMtroffsetDataObj.AssetId = new Guid(assetuid); metersMessages.Add(hourMtroffsetDataObj); } if (param.ParameterName == "Odometer") { var odoMtroffsetDataObj = GetOdometerOffsetMessageEvent(requestBase); odoMtroffsetDataObj.AssetId = new Guid(assetuid); metersMessages.Add(odoMtroffsetDataObj); } } _loggingService.Info("Ended processing group messages", "MetersMessageBuilder.ProcessGroupMessages"); return(metersMessages); }
public bool ProcessBypassMessage(DeviceConfigRequestBase requestBase, ParamGroup group) { _loggingService.Debug("Device Request Message : " + JsonConvert.SerializeObject(requestBase), ""); var failedAssets = String.Empty; try { if (requestBase == null || !_groupContainer.ContainsKey(requestBase.ParameterGroupName)) { _loggingService.Info("Device Message Group Name / Device Type is invalid !!", ""); return(false); } var groupBuilder = _groupContainer[requestBase.ParameterGroupName]; foreach (var assetuid in requestBase.AssetUIDs) { _loggingService.Info("Started processing group messages - AcknowledgementBypasser.ProcessBypassMessage", ""); var groupMessages = groupBuilder.ProcessGroupMessages(assetuid, requestBase, group); var assetId = new Guid(assetuid); _loggingService.Info("Started publishing messages - AcknowledgementBypasser.ProcessBypassMessage", ""); if (!_kafkaPublisher.PublishMessage(assetId.ToString(), groupMessages, "")) { failedAssets += (failedAssets == String.Empty ? "" : ",") + assetuid; } } if (failedAssets == String.Empty) { return(true); } } catch (Exception ex) { _loggingService.Error("Exception : " + JsonConvert.SerializeObject(ex), "", ex); throw new Exception("Unable to Complete Device Configuration for assetuid " + failedAssets); } return(false); }
public IEnumerable <Tuple <IOutMessageEvent, DeviceDetails> > GetDataOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails) { var dataOutMessages = new List <Tuple <IOutMessageEvent, DeviceDetails> >(); _loggingService.Info("Recieved MovingThresholds Message for A5N2 Device " + deviceDetails.DeviceUid, "MovingThresholdMessageEventBuilder.GetDataOutMessageEvent"); var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigMovingThresholdRequest>(requestBase); var messageEvent = _dataPopulator.ConstructDataOutEvent <MovingCriteriaConfigurationChangedEvent>(deviceDetails); messageEvent.MovementDurationSeconds = requestMessage.MovingThresholdsDuration.HasValue ? requestMessage.MovingThresholdsDuration.Value : 30; messageEvent.MovementRadiusInFeet = requestMessage.Radius.HasValue ? NumericHelper.ConvertMetersToFeet(requestMessage.Radius.Value) : 30; messageEvent.MovementSpeedMPH = requestMessage.MovingOrStoppedThreshold.HasValue ? NumericHelper.ConvertKilometersToMiles((double)requestMessage.MovingOrStoppedThreshold.Value) : 0.2; dataOutMessages.Add(new Tuple <IOutMessageEvent, DeviceDetails>(messageEvent, deviceDetails)); _loggingService.Info("Moving Thresholds Message Event Construction for Device Type " + deviceDetails.DeviceType + " completed !!" + JsonConvert.SerializeObject(requestMessage), "MovingThresholdMessageEventBuilder.GetDataOutMessageEvent"); return(dataOutMessages); }
protected async virtual Task <DeviceConfigRequestBase> GetRequestAndHandleForNullCases(DeviceConfigRequestBase request) { return(request); }
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)); } }
private async Task UpdateCurrentAttributeValues(DeviceConfigurationSettingsConfig settingsConfig, DeviceConfigRequestBase request) { 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 UpdateCurrentAttributeValues", "DeviceConfigRepositoryServiceBase.UpdateCurrentAttributeValues"); var updateDeviceConfigResponseDtos = await this.Fetch(request); UpdateCurrentValues(updateDeviceConfigResponseDtos.ToList()); this._loggingService.Info("Ended Invoking UpdateCurrentAttributeValues", "DeviceConfigRepositoryServiceBase.UpdateCurrentAttributeValues"); } }
protected async virtual Task <IList <DeviceConfigDto> > Save(DeviceConfigRequestBase request) { try { await this.GetAttributeIds(request.DeviceType, request.ParameterGroupName); var deviceConfigResponseDtos = await this.Fetch(request); var availableAssetUIDs = deviceConfigResponseDtos.Select(x => Guid.Parse(x.AssetUIDString)).Distinct().ToList(); var assetDeviceDtos = await this._assetDeviceRepository.FetchByAssetUIDAndDeviceType(request.AssetUIDs, request.DeviceType); var assetDeviceMaps = assetDeviceDtos.ToDictionary(x => x.AssetUID, x => x.DeviceUID); this._loggingService.Info("Already available assets : " + JsonConvert.SerializeObject(availableAssetUIDs), "DeviceConfigRepositoryServiceBase.Save"); var assetsTobeInserted = request.AssetUIDs.Select(x => Guid.Parse(x)).Except(availableAssetUIDs).ToList(); this._loggingService.Info("New assets : " + JsonConvert.SerializeObject(assetsTobeInserted), "DeviceConfigRepositoryServiceBase.Save"); var currentDateTimeUTC = DateTime.UtcNow.ToDateTimeStringWithYearMonthDayFormat(); //for new assets to be inserted foreach (var asset in assetsTobeInserted) { foreach (var attributeId in base._paramterAttributeDetails) { if (request.ConfigValues.ContainsKey(attributeId.Key)) { var configValue = request.ConfigValues[GetAttributeName(attributeId)]; if (assetDeviceMaps.ContainsKey(asset)) { deviceConfigResponseDtos.Add(new DeviceConfigDto { DeviceUIDString = assetDeviceMaps[asset].ToString("N"), AssetUIDString = asset.ToString("N"), DeviceTypeParameterID = attributeId.Value.DeviceTypeParameterID, DeviceParameterAttributeId = attributeId.Value.DeviceParamAttrID, FutureAttrEventUTC = currentDateTimeUTC, RowUpdatedUTC = currentDateTimeUTC, RowInsertedUTC = currentDateTimeUTC, AttributeName = attributeId.Value.AttributeName, ParameterName = attributeId.Value.ParameterName }); } } } } var newAttributes = new List <DeviceConfigDto>(); //for left out attribute which is not in DB foreach (var availableAsset in availableAssetUIDs) { foreach (var attributeId in base._paramterAttributeDetails) { this._loggingService.Info("Already available assets : " + JsonConvert.SerializeObject(availableAssetUIDs), "DeviceConfigRepositoryServiceBase.Save"); if (assetDeviceMaps.ContainsKey(availableAsset)) { if (!isAttributeNameExists(deviceConfigResponseDtos, attributeId, assetDeviceMaps[availableAsset].ToString("N")) && request.ConfigValues.ContainsKey(attributeId.Key)) { var configValue = request.ConfigValues[GetAttributeName(attributeId)]; newAttributes.Add(new DeviceConfigDto { DeviceUIDString = assetDeviceMaps[availableAsset].ToString("N"), AssetUIDString = availableAsset.ToString("N"), DeviceTypeParameterID = attributeId.Value.DeviceTypeParameterID, DeviceParameterAttributeId = attributeId.Value.DeviceParamAttrID, FutureAttrEventUTC = currentDateTimeUTC, RowUpdatedUTC = currentDateTimeUTC, RowInsertedUTC = currentDateTimeUTC, AttributeName = attributeId.Value.AttributeName, ParameterName = attributeId.Value.ParameterName }); } } } } if (newAttributes.Any()) { deviceConfigResponseDtos.AddRange(newAttributes); } //assign the value and update the Event UTC foreach (var config in deviceConfigResponseDtos) { if (request.ConfigValues.ContainsKey(GetConfigAttributeName(config))) { config.FutureAttributeValue = request.ConfigValues[GetConfigAttributeName(config)]; config.RowUpdatedUTC = currentDateTimeUTC; config.FutureAttrEventUTC = currentDateTimeUTC; } } //remove device config dtos which are not configured now(so no updates or insert will be done) deviceConfigResponseDtos.RemoveAll(x => !request.ConfigValues.ContainsKey(GetAttributeNameForConfig(x))); await this.ProcessAndSaveDeviceConfig(request, deviceConfigResponseDtos, currentDateTimeUTC, assetDeviceMaps); var response = await this.Fetch(request); return(response); } catch (Exception ex) { this._loggingService.Error("An Error has occurred", "DeviceConfigRepositoryServiceBase.Save", ex); throw ex; } }
public IEnumerable <Tuple <IMTSOutMessageEvent, DeviceDetails> > GetMtsOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails) { var mtsOutMessages = new List <Tuple <IMTSOutMessageEvent, DeviceDetails> >(); _loggingService.Info("Recieved MovingThresholds Message for MTS Device " + deviceDetails.DeviceUid, "MovingThresholdMessageEventBuilder.GetMtsOutMessageEvent"); var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigMovingThresholdRequest>(requestBase); if (requestMessage.Radius.HasValue) { var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <SetMovingConfigurationEvent>(deviceDetails); mtsMessageEvent.Radius = (ushort)NumericHelper.ConvertMetersToFeet(requestMessage.Radius.Value); var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, "MovingThresholdsRadius"); mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, dvcDetails)); } if (requestMessage.MovingOrStoppedThreshold.HasValue || requestMessage.MovingThresholdsDuration.HasValue) { var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <SetStoppedThresholdEvent>(deviceDetails); var parameterNames = new List <string>(); if (requestMessage.MovingOrStoppedThreshold.HasValue) { mtsMessageEvent.Threshold = NumericHelper.ConvertKilometersToMiles((double)requestMessage.MovingOrStoppedThreshold.Value); parameterNames.Add("MovingOrStoppedThreshold"); } if (requestMessage.MovingThresholdsDuration.HasValue) { mtsMessageEvent.Duration = requestMessage.MovingThresholdsDuration.Value; parameterNames.Add("MovingThresholdsDuration"); } mtsMessageEvent.Enabled = true; //doubt var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, parameterNames.ToArray()); mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, dvcDetails)); } _loggingService.Info("Moving Thresholds Message Event Construction for Device Type " + deviceDetails.DeviceType + " completed !!" + JsonConvert.SerializeObject(requestMessage), "MovingThresholdMessageEventBuilder.GetMtsOutMessageEvent"); return(mtsOutMessages); }
public IEnumerable <Tuple <IPLOutMessageEvent, DeviceDetails> > GetPlOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails) { _loggingService.Info("PL Device Type doesn't support MovingThresholds", "MovingThresholdMessageEventBuilder.GetDataOutMessageEvent"); throw new NotImplementedException("PL Device Type doesn't support MovingThresholds"); }
public IEnumerable <Tuple <IOutMessageEvent, DeviceDetails> > GetDataOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails) { var dataOutMessages = new List <Tuple <IOutMessageEvent, DeviceDetails> >(); _loggingService.Info("Recieved MovingThresholds Message for PL Device " + deviceDetails.DeviceUid, "MetersMessageEventBuilder.GetPlOutMessageEvent"); var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigMetersRequest>(requestBase); if (requestMessage.OdoMeter != null) { if (requestMessage.OdoMeter.ProposedValue.HasValue) { _loggingService.Info("Recieved OdometerModifiedEvent Message" + requestMessage + " for Device " + deviceDetails.DeviceUid + " and DeviceType" + deviceDetails.DeviceType, "MetersMessageEventBuilder.GetPlOutMessageEvent"); var odometerModifiedEvent = _dataPopulator.ConstructDataOutEvent <OdometerModifiedEvent>(deviceDetails); if (requestMessage.OdoMeter.CurrentValue.HasValue) { odometerModifiedEvent.MilesBefore = NumericHelper.ConvertKilometersToMiles(requestMessage.OdoMeter.CurrentValue.Value); } odometerModifiedEvent.MilesAfter = NumericHelper.ConvertKilometersToMiles(requestMessage.OdoMeter.ProposedValue.Value); var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, "Odometer"); dataOutMessages.Add(new Tuple <IOutMessageEvent, DeviceDetails>(odometerModifiedEvent, dvcDetails)); _loggingService.Info("OdometerModifiedEvent message Event Construction for Device" + deviceDetails.DeviceUid + " completed !!" + JsonConvert.SerializeObject(requestBase), "MetersMessageEventBuilder.GetPlOutMessageEvent"); } if (requestMessage.HoursMeter != null) { if (requestMessage.HoursMeter.ProposedValue.HasValue) { _loggingService.Info("Recieved HourMeterModifiedEvent Message" + requestMessage + " for Device " + deviceDetails.DeviceUid + " and DeviceType" + deviceDetails.DeviceType, "MetersMessageEventBuilder.GetPlOutMessageEvent"); var hourmeterModifiedEvent = _dataPopulator.ConstructDataOutEvent <HourMeterModifiedEvent>(deviceDetails); if (requestMessage.HoursMeter.CurrentValue.HasValue) { hourmeterModifiedEvent.HoursBefore = requestMessage.HoursMeter.CurrentValue.Value; } hourmeterModifiedEvent.HoursAfter = Convert.ToDouble(requestMessage.HoursMeter.ProposedValue); var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, "HoursMeter"); dataOutMessages.Add(new Tuple <IOutMessageEvent, DeviceDetails>(hourmeterModifiedEvent, dvcDetails)); _loggingService.Info("HourMeterModifiedEvent message Event Construction for Device" + deviceDetails.DeviceUid + " completed !!" + JsonConvert.SerializeObject(requestBase), "MetersMessageEventBuilder.GetPlOutMessageEvent"); } } } return(dataOutMessages); }
public IEnumerable <Tuple <IPLOutMessageEvent, DeviceDetails> > GetPlOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails) { var dataOutMessages = new List <Tuple <IPLOutMessageEvent, DeviceDetails> >(); var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigMetersRequest>(requestBase); _loggingService.Info("Recieved SendRuntimeAdjustmentConfig Message" + requestMessage + " for Device " + deviceDetails.DeviceUid + " and DeviceType" + deviceDetails.DeviceType, "MetersMessageEventBuilder.GetPlOutMessageEvent"); if (_validator.NullCheck(RequestMessageType, requestMessage.HoursMeter.ProposedValue)) { var plMessageEvent = _dataPopulator.ConstructPlEvent <SendRuntimeAdjustmentConfig>(deviceDetails); plMessageEvent.NewRuntimeValue = new TimeSpan((int)requestMessage.HoursMeter.ProposedValue, 0, 0); dataOutMessages.Add(new Tuple <IPLOutMessageEvent, DeviceDetails>(plMessageEvent, deviceDetails)); } _loggingService.Info("SendRuntimeAdjustmentConfig message Event Construction for Device" + deviceDetails + " completed !!" + JsonConvert.SerializeObject(requestBase), ""); return(dataOutMessages); }