Пример #1
0
        public IEnumerable <Tuple <IPLOutMessageEvent, DeviceDetails> > GetPlOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails)
        {
            var plOutMessages        = new List <Tuple <IPLOutMessageEvent, DeviceDetails> >();
            var digitalConfigDetails = new List <DigitalInputConfigDetails>();

            _loggingService.Info("Recieved Switches Message for Device " + deviceDetails.DeviceType, "SwitchesMessageEventBuilder.GetPlOutMessageEvent");
            var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigSwitchesRequest>(requestBase);

            if (requestMessage.SingleStateSwitches != null && requestMessage.SingleStateSwitches.Any())
            {
                foreach (var singleSwitch in requestMessage.SingleStateSwitches)
                {
                    var digitalInputConfigDetail = new DigitalInputConfigDetails();
                    digitalInputConfigDetail.InputConfig = string.IsNullOrEmpty(singleSwitch.SwitchActiveState) ? (InputConfig?)null : _dataPopulator.GetEventEnumValue <InputConfig>(singleSwitch.SwitchActiveState);
                    digitalInputConfigDetail.DigitalInputMonitoringCondition = string.IsNullOrEmpty(singleSwitch.SwitchMonitoringStatus) ? (DigitalInputMonitoringConditions?)null : _dataPopulator.GetEventEnumValue <DigitalInputMonitoringConditions>(singleSwitch.SwitchMonitoringStatus);
                    digitalInputConfigDetail.Description    = singleSwitch.SwitchName;
                    digitalInputConfigDetail.InputDelayTime = new TimeSpan(0, 0, 0, 0, (int)Math.Round(singleSwitch.SwitchSensitivity * 1000));
                    digitalConfigDetails.Add(digitalInputConfigDetail);
                }
                var plMessageEvent = _dataPopulator.ConstructPlEvent <SendDigitalInputConfig>(deviceDetails);
                plMessageEvent.Config1 = digitalConfigDetails[0];
                plMessageEvent.Config2 = digitalConfigDetails.Count >= 2 ? digitalConfigDetails[1] : new DigitalInputConfigDetails();
                plMessageEvent.Config3 = digitalConfigDetails.Count >= 3 ? digitalConfigDetails[2] : new DigitalInputConfigDetails();
                plMessageEvent.Config4 = digitalConfigDetails.Count >= 4 ? digitalConfigDetails[3] : new DigitalInputConfigDetails();
                plOutMessages.Add(new Tuple <IPLOutMessageEvent, DeviceDetails>(plMessageEvent, deviceDetails));
            }
            _loggingService.Info("Switches Message Event Construction for Device Type " + deviceDetails.DeviceType + " completed !!" + JsonConvert.SerializeObject(requestMessage), "SwitchesMessageEventBuilder.GetPlOutMessageEvent");
            return(plOutMessages);
        }
Пример #2
0
        public IEnumerable <Tuple <IMTSOutMessageEvent, DeviceDetails> > GetMtsOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails)
        {
            var mtsOutMessages = new List <Tuple <IMTSOutMessageEvent, DeviceDetails> >();
            var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigMetersRequest>(requestBase);

            //if (_serverSideRunTimeCalibrationDeviceTypes.Contains(deviceDetails.DeviceType) && requestMessage.HoursMeter != null && requestMessage.HoursMeter.ProposedValue.HasValue)
            //{
            //	_kafkaPublisher.PublishMessage(deviceDetails.SerialNumber, new List<MTSServerSideRunTimeCalibration> { new MTSServerSideRunTimeCalibration { DeviceSerialNumber = deviceDetails.SerialNumber, DeviceType = deviceDetails.DeviceType, ProposedRunTimeHours = requestMessage.HoursMeter.ProposedValue.Value, IsDeleted = false, ActionUtc = DateTime.UtcNow } }, String.Empty);
            //	_loggingService.Info($"Published MTSServerSideRunTimeCalibration Event for Device SerialNUmber : {deviceDetails.SerialNumber} with RunTimeHours {requestMessage.HoursMeter.ProposedValue.Value}", "MetersMessageEventBuilder.GetMtsOutMessageEvent");
            //}
            //else if (_newlySupportedServerSideRunTimeCalibrationDeviceTypes.Contains(deviceDetails.DeviceType) && requestMessage.HoursMeter != null && requestMessage.HoursMeter.ProposedValue.HasValue)
            //{
            //	_kafkaPublisher.PublishMessage(deviceDetails.SerialNumber, new List<MTSServerSideRunTimeCalibration> { new MTSServerSideRunTimeCalibration { DeviceSerialNumber = deviceDetails.SerialNumber, DeviceType = deviceDetails.DeviceType, IsDeleted = true, ActionUtc = DateTime.UtcNow } }, String.Empty);
            //	_loggingService.Info($"Published Delete MTSServerSideRunTimeCalibration Event for Device SerialNUmber : {deviceDetails.SerialNumber} with RunTimeHours {requestMessage.HoursMeter.ProposedValue.Value}", "MetersMessageEventBuilder.GetMtsOutMessageEvent");
            //}

            if ((requestMessage.OdoMeter != null) || (requestMessage.HoursMeter != null))
            {
                _loggingService.Info("Recieved SetRuntimeMileageEvent Message" + requestMessage + " for Device " + deviceDetails.DeviceUid + " and DeviceType" + deviceDetails.DeviceType, "MetersMessageEventBuilder.GetMtsOutMessageEvent");
                var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <SetRuntimeMileageEvent>(deviceDetails);
                if (requestMessage.OdoMeter != null)
                {
                    if (requestMessage.OdoMeter.ProposedValue.HasValue || requestMessage.OdoMeter.CurrentValue.HasValue)
                    {
                        mtsMessageEvent.Mileage = requestMessage.OdoMeter.ProposedValue.HasValue ? NumericHelper.ConvertKilometersToMiles(requestMessage.OdoMeter.ProposedValue.Value) : NumericHelper.ConvertKilometersToMiles(requestMessage.OdoMeter.CurrentValue.Value);
                    }
                }
                if (requestMessage.HoursMeter != null)
                {
                    if (requestMessage.HoursMeter.ProposedValue.HasValue || requestMessage.HoursMeter.CurrentValue.HasValue)
                    {
                        mtsMessageEvent.Runtime = requestMessage.HoursMeter.ProposedValue.HasValue ? Convert.ToInt64(requestMessage.HoursMeter.ProposedValue) : Convert.ToInt64(requestMessage.HoursMeter.CurrentValue);
                    }
                }
                var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, "Odometer", "HoursMeter");
                if (mtsMessageEvent != null)
                {
                    mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, dvcDetails));
                }
                _loggingService.Info("SetRuntimeMileageEvent message Event Construction for Device" + deviceDetails.DeviceUid + " completed !!" + JsonConvert.SerializeObject(requestBase), "MetersMessageEventBuilder.GetMtsOutMessageEvent");
            }

            if (requestMessage.HoursMeter != null)
            {
                if (requestMessage.HoursMeter.ProposedValue.HasValue || requestMessage.HoursMeter.CurrentValue.HasValue)
                {
                    _loggingService.Info("Recieved SendOtaConfigurationEvent Message" + requestMessage + " for Device " + deviceDetails.DeviceUid + " and DeviceType" + deviceDetails.DeviceType, "MetersMessageEventBuilder.GetMtsOutMessageEvent");
                    var mtsOtaMessageEvent = _dataPopulator.ConstructMtsEvent <SendOtaConfigurationEvent>(deviceDetails);
                    mtsOtaMessageEvent.Smu    = TimeSpan.FromHours((double)(requestMessage.HoursMeter.ProposedValue.HasValue ? requestMessage.HoursMeter.ProposedValue : requestMessage.HoursMeter.CurrentValue));
                    mtsOtaMessageEvent.Input1 = new OtaConfigDetail();
                    mtsOtaMessageEvent.Input2 = new OtaConfigDetail();
                    mtsOtaMessageEvent.Input3 = new OtaConfigDetail();
                    mtsOtaMessageEvent.Input4 = new OtaConfigDetail();
                    var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, "HoursMeter");
                    mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsOtaMessageEvent, dvcDetails));
                    _loggingService.Info("SendOtaConfigurationEvent message Event Construction for Device" + deviceDetails.DeviceUid + " completed !!" + JsonConvert.SerializeObject(requestBase), "MetersMessageEventBuilder.GetMtsOutMessageEvent");
                }
            }

            if (requestMessage.SmhOdometerConfig != null)
            {
                _loggingService.Info("Recieved SetMachineEventHeaderConfiguration Message" + requestMessage + " for Device " + deviceDetails.DeviceUid + " and DeviceType" + deviceDetails.DeviceType, "MetersMessageEventBuilder.GetMtsOutMessageEvent");
                var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <SetMachineEventHeaderConfiguration>(deviceDetails);
                mtsMessageEvent.PrimaryDataSource = _dataPopulator.GetEventEnumValue <PrimaryDataSourceEnum>(requestMessage.SmhOdometerConfig.Value.ToString());
                var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, "SMHOdometerConfig");
                mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, dvcDetails));
                _loggingService.Info("SetMachineEventHeaderConfiguration message Event Construction for Device" + deviceDetails.DeviceUid + " completed !!" + JsonConvert.SerializeObject(requestBase), "MetersMessageEventBuilder.GetMtsOutMessageEvent");
            }
            return(mtsOutMessages);
        }