Пример #1
0
        public IEnumerable <Tuple <IMTSOutMessageEvent, DeviceDetails> > GetMtsOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails)
        {
            var mtsOutMessages   = new List <Tuple <IMTSOutMessageEvent, DeviceDetails> >();
            var otaConfigDetails = new Dictionary <int, OtaConfigDetail>(4);

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

            if (requestMessage.SingleStateSwitches != null && requestMessage.SingleStateSwitches.Any())
            {
                foreach (var singleSwitch in requestMessage.SingleStateSwitches)
                {
                    var otaInputConfigDetail = new OtaConfigDetail();
                    otaInputConfigDetail.InputConfig         = string.IsNullOrEmpty(singleSwitch.SwitchActiveState) ? (InputConfigType?)null : _dataPopulator.GetEventEnumValue <InputConfigType>(singleSwitch.SwitchActiveState);
                    otaInputConfigDetail.MonitoringCondition = string.IsNullOrEmpty(singleSwitch.SwitchMonitoringStatus) ? (DigitalInputMonitoringConditions?)null : _dataPopulator.GetEventEnumValue <DigitalInputMonitoringConditions>(singleSwitch.SwitchMonitoringStatus);
                    otaInputConfigDetail.InputDesc           = singleSwitch.SwitchName;
                    otaInputConfigDetail.InputDelay          = new TimeSpan(0, 0, 0, 0, (int)Math.Round(singleSwitch.SwitchSensitivity * 1000));
                    otaConfigDetails.Add(singleSwitch.SwitchNumber, otaInputConfigDetail);
                }
                var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <SendOtaConfigurationEvent>(deviceDetails);
                mtsMessageEvent.Input1 = otaConfigDetails.ContainsKey(1) ? otaConfigDetails[1] : new OtaConfigDetail();
                mtsMessageEvent.Input2 = otaConfigDetails.ContainsKey(2) ? otaConfigDetails[2] : new OtaConfigDetail();
                mtsMessageEvent.Input3 = otaConfigDetails.ContainsKey(3) ? otaConfigDetails[3] : new OtaConfigDetail();
                mtsMessageEvent.Input4 = otaConfigDetails.ContainsKey(4) ? otaConfigDetails[4] : new OtaConfigDetail();
                var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, "SingleStateSwitch1", "SingleStateSwitch2", "SingleStateSwitch3", "SingleStateSwitch4");
                mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, dvcDetails));
            }
            var sensorDetails = new Dictionary <int, SensorDetail>(3);

            if (requestMessage.DualStateSwitches != null && requestMessage.DualStateSwitches.Any())
            {
                var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <ConfigureSensorsEvent>(deviceDetails);

                foreach (var dualSwitch in requestMessage.DualStateSwitches)
                {
                    var sensorDetail = new SensorDetail();
                    sensorDetail.HasPosPolarity = false;
                    sensorDetail.IgnReqired     = false;
                    sensorDetail.HystHalfSec    = dualSwitch.SwitchSensitivity * 2;
                    sensorDetail.Enabled        = dualSwitch.SwitchEnabled;
                    sensorDetails.Add(dualSwitch.SwitchNumber, sensorDetail);
                }
                mtsMessageEvent.Sensor1 = sensorDetails.ContainsKey(5) ? sensorDetails[5] : null;
                mtsMessageEvent.Sensor2 = sensorDetails.ContainsKey(6) ? sensorDetails[6] : null;
                mtsMessageEvent.Sensor3 = sensorDetails.ContainsKey(7) ? sensorDetails[7] : null;
                var dvcDetails = ConstructorHelpers.GetDeviceConfigMsg(deviceDetails, "MTSDualStateSwitch5", "MTSDualStateSwitch6", "MTSDualStateSwitch7");
                mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, dvcDetails));
            }
            _loggingService.Info("Switches Message Event Construction for Device Type " + deviceDetails.DeviceType + " completed !!" + JsonConvert.SerializeObject(requestMessage), "SwitchesMessageEventBuilder.GetMtsOutMessageEvent");

            return(mtsOutMessages);
        }
Пример #2
0
        public IEnumerable <Tuple <IMTSOutMessageEvent, DeviceDetails> > GetMtsOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails)
        {
            var mtsOutMessages = new List <Tuple <IMTSOutMessageEvent, DeviceDetails> >();

            _loggingService.Info("Recieved SpeedingThresholds Message for MTS Device " + deviceDetails.DeviceUid, "SpeedingThresholdMessageEventBuilder.GetMtsOutMessageEvent");
            var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigSpeedingThresholdsRequest>(requestBase);

            if (_validator.NullCheck(RequestMessageType, requestMessage.SpeedThresholdEnabled.Value))
            {
                var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <SetSpeedingThresholdEvent>(deviceDetails);
                if (requestMessage.SpeedThresholdEnabled.Value)
                {
                    if (requestMessage.SpeedThresholdDuration.HasValue)
                    {
                        mtsMessageEvent.Duration = requestMessage.SpeedThresholdDuration.Value;
                    }
                    if (requestMessage.SpeedThreshold.HasValue)
                    {
                        mtsMessageEvent.Threshold = NumericHelper.ConvertKilometersToMiles(requestMessage.SpeedThreshold.Value);
                    }
                }
                mtsMessageEvent.Enabled = requestMessage.SpeedThresholdEnabled.Value;
                mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, deviceDetails));
            }
            _loggingService.Info("Speeding Threshold Message Event Construction for Device Type " + deviceDetails.DeviceType + " completed !!" + JsonConvert.SerializeObject(requestMessage), "SpeedingThresholdMessageEventBuilder.GetMtsOutMessageEvent");
            return(mtsOutMessages);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public IEnumerable <Tuple <IMTSOutMessageEvent, DeviceDetails> > GetMtsOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails)
        {
            var mtsOutMessages = new List <Tuple <IMTSOutMessageEvent, DeviceDetails> >();

            _loggingService.Info("Recieved ReportingSchedule Message for MTS Device " + deviceDetails.DeviceUid, "ReportingScheduleMessageEventBuilder.GetMtsOutMessageEvent");
            var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigReportingScheduleRequest>(requestBase);

            if (_validator.NullCheck(RequestMessageType, requestMessage.DailyReportingTime.Value))
            {
                var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <SendDailyReportConfigEvent>(deviceDetails);
                mtsMessageEvent.Enabled               = true;
                mtsMessageEvent.DailyReportTimeHour   = (byte)(new DateTime() + requestMessage.DailyReportingTime.Value).Hour;
                mtsMessageEvent.DailyReportTimeMinute = (byte)(new DateTime() + requestMessage.DailyReportingTime.Value).Minute;
                mtsMessageEvent.TimezoneName          = "UTC";
                mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, deviceDetails));
            }
            _loggingService.Info("Reporting Schedule Message Event Construction for Device Type " + deviceDetails.DeviceType + " completed !!" + JsonConvert.SerializeObject(requestMessage), "ReportingScheduleMessageEventBuilder.GetMtsOutMessageEvent");
            return(mtsOutMessages);
        }
Пример #5
0
        public IEnumerable <Tuple <IMTSOutMessageEvent, DeviceDetails> > GetMtsOutMessageEvent(DeviceConfigRequestBase requestBase, DeviceDetails deviceDetails)
        {
            var mtsOutMessages = new List <Tuple <IMTSOutMessageEvent, DeviceDetails> >();

            _loggingService.Info("Recieved Maintenance Mode Message for Device " + deviceDetails.DeviceType, "MaintenanceModeMessageEventBuilder.GetMtsOutMessageEvent");
            var requestMessage = _dataPopulator.GetRequestModel <DeviceConfigMaintenanceModeRequest>(requestBase);

            if (_validator.NullCheck(RequestMessageType, requestMessage.Status))
            {
                var mtsMessageEvent = _dataPopulator.ConstructMtsEvent <SendOtaConfigurationEvent>(deviceDetails);
                mtsMessageEvent.Input1 = mtsMessageEvent.Input2 = mtsMessageEvent.Input3 = mtsMessageEvent.Input4 = new OtaConfigDetail();
                if (requestMessage.Status.Value && _validator.NullCheck(RequestMessageType, requestMessage.MaintenanceModeDuration))
                {
                    mtsMessageEvent.MaintenanceModeDuration = new TimeSpan(requestMessage.MaintenanceModeDuration.Value, 0, 0);
                }
                mtsMessageEvent.MaintenanceModeEnabled = requestMessage.Status.Value;
                mtsOutMessages.Add(new Tuple <IMTSOutMessageEvent, DeviceDetails>(mtsMessageEvent, deviceDetails));
            }
            _loggingService.Info("Maintenance Mode Message Event Construction for Device Type " + deviceDetails.DeviceType + " completed !!" + JsonConvert.SerializeObject(requestMessage), "MaintenanceModeMessageEventBuilder.GetMtsOutMessageEvent");
            return(mtsOutMessages);
        }
Пример #6
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);
        }