예제 #1
0
        public async Task Init()
        {
            _latestSafetyCheckData = await _repositories.LatestSafetyCheckRepository.GetForDriverAsync(_infoService.CurrentDriverID.Value);

            var hasVehicleSafetyCheck = _latestSafetyCheckData.VehicleSafetyCheck != null;
            var hasTrailerSafetyCheck = _latestSafetyCheckData.TrailerSafetyCheck != null;

            //If there is no safety check data to view, then sends them back to where they came.
            if (!hasVehicleSafetyCheck && !hasTrailerSafetyCheck)
            {
                await Mvx.Resolve <ICustomUserInteraction>().AlertAsync("A safety check profile for your vehicle and/or trailer has not been completed - Refer to your manual safety check.");

                await _navigationService.MoveToNextAsync(_navigationService.CurrentNavData);

                return;
            }

            this.VehicleRegistration = "Vehicle: " + (hasVehicleSafetyCheck ? _latestSafetyCheckData.VehicleSafetyCheck.VehicleRegistration : string.Empty);
            this.TrailerRegistration = "Trailer: " + (hasTrailerSafetyCheck ? _latestSafetyCheckData.TrailerSafetyCheck.VehicleRegistration : string.Empty);
//            this.VehicleSafetyCheckStatus = "Checked: " + (hasVehicleSafetyCheck ? _latestSafetyCheckData.VehicleSafetyCheck.EffectiveDate.ToString("g") : string.Empty);
//            this.TrailerSafetyCheckStatus = "Checked: " + (hasTrailerSafetyCheck ? _latestSafetyCheckData.TrailerSafetyCheck.EffectiveDate.ToString("g") : string.Empty);
            this.VehicleSafetyCheckStatus = "Checked: " + (hasVehicleSafetyCheck ? _latestSafetyCheckData.VehicleSafetyCheck.EffectiveDate.ToUniversalTime().ToString("dd/MM/yyyy HH:mm:ss") : string.Empty);
            this.TrailerSafetyCheckStatus = "Checked: " + (hasTrailerSafetyCheck ? _latestSafetyCheckData.TrailerSafetyCheck.EffectiveDate.ToUniversalTime().ToString("dd/MM/yyyy HH:mm:ss") : string.Empty);

            if (hasVehicleSafetyCheck)
            {
                GenerateSafetyCheckFaultItems(_latestSafetyCheckData.VehicleSafetyCheck.Faults, false);
            }

            if (hasTrailerSafetyCheck)
            {
                GenerateSafetyCheckFaultItems(_latestSafetyCheckData.TrailerSafetyCheck.Faults, true);
            }
        }
예제 #2
0
        protected override void AdditionalSetup()
        {
            _fixture = new Fixture().Customize(new AutoMoqCustomization());
            _fixture.OmitProperty("EffectiveDateString");

            _latestSafetyCheck = _fixture.Create <LatestSafetyCheck>();
            _mobileData        = _fixture.Create <MobileData>();

            _mockInfoService = _fixture.InjectNewMock <IInfoService>();
            _mockInfoService.Setup(m => m.CurrentDriverID).Returns(_fixture.Create <Driver>().ID);

            _mockRepositories = _fixture.InjectNewMock <IRepositories>();
            Ioc.RegisterSingleton <IRepositories>(_mockRepositories.Object);

            _mockNavigationService = _fixture.InjectNewMock <INavigationService>();
            Ioc.RegisterSingleton <INavigationService>(_mockNavigationService.Object);

            _mockLatestSafetyCheckRepository = _fixture.InjectNewMock <ILatestSafetyCheckRepository>();
            _mockLatestSafetyCheckRepository.Setup(mls => mls.GetForDriverAsync(It.IsAny <Guid>())).ReturnsAsync(_latestSafetyCheck);
            _mockRepositories.Setup(r => r.LatestSafetyCheckRepository).Returns(_mockLatestSafetyCheckRepository.Object);

            var mobileDataRepository = Mock.Of <IMobileDataRepository>(mdr => mdr.GetByIDAsync(_mobileData.ID) == Task.FromResult(_mobileData));

            _mockRepositories.Setup(r => r.MobileDataRepository).Returns(mobileDataRepository);

            _mockUserInteraction = Ioc.RegisterNewMock <ICustomUserInteraction>();
            _mockUserInteraction.ConfirmReturnsTrue();
            _mockUserInteraction.AlertInvokeAction();

            _mockMessenger = Ioc.RegisterNewMock <IMvxMessenger>();
            _mockMessenger.Setup(m => m.Unsubscribe <GatewayInstructionNotificationMessage>(It.IsAny <MvxSubscriptionToken>()));
            _mockMessenger.Setup(m => m.Subscribe(It.IsAny <Action <GatewayInstructionNotificationMessage> >(), It.IsAny <MvxReference>(), It.IsAny <string>())).Returns(_fixture.Create <MvxSubscriptionToken>());
        }
예제 #3
0
        public async Task CommitSafetyCheckDataAsync(bool trailerOnly = false)
        {
            // Add the safety checks to the gateway queue
            var safetyCheckData = this.GetCurrentSafetyCheckData();

            var safetyCheckFailed = false;

            // Store the latest safety check so the driver can display it at a later point if required
            var latestSafetyCheck = new LatestSafetyCheck {
                DriverID = _infoService.CurrentDriverID.Value
            };

            if (safetyCheckData.Any())
            {
                var overallStatus = SafetyCheckData.GetOverallStatus(safetyCheckData.Select(scd => scd.GetOverallStatus()));
                safetyCheckFailed = overallStatus == Enums.SafetyCheckStatus.Failed;

                // Submit the safety checks to the gateway service
                var smp = _gpsService.GetSmpData(Enums.ReportReason.SafetyReport);

                // Don't include milliseconds in the EffectiveDate submitted to BlueSphere
                var effectiveDateTime = DateTime.Now;
                effectiveDateTime = effectiveDateTime.AddMilliseconds(-effectiveDateTime.Millisecond);

                if (this.CurrentVehicleSafetyCheckData != null && this.CurrentVehicleSafetyCheckData.Faults.Any())
                {
                    latestSafetyCheck.VehicleSafetyCheck = this.CurrentVehicleSafetyCheckData;

                    if (!trailerOnly)
                    {
                        latestSafetyCheck.VehicleSafetyCheck.EffectiveDate = effectiveDateTime;
                    }
                }

                if (this.CurrentTrailerSafetyCheckData != null && this.CurrentTrailerSafetyCheckData.Faults.Any())
                {
                    latestSafetyCheck.TrailerSafetyCheck = this.CurrentTrailerSafetyCheckData;
                    latestSafetyCheck.TrailerSafetyCheck.EffectiveDate = effectiveDateTime;
                }

                await _repositories.LatestSafetyCheckRepository.SetForDriverAsync(latestSafetyCheck);

                // Submit the safety check data to BlueSphere
                var safetyCheckDataToSubmit = new List <SafetyCheckData>(safetyCheckData.Count());

                foreach (var scd in safetyCheckData)
                {
                    if (trailerOnly && !scd.IsTrailer)
                    {
                        continue;
                    }

                    var safetyCheck = Models.SafetyCheckData.ShallowCopy(scd);

                    // Passed safety check items shouldn't be submitted to the gateway service, only Fails and Discretionary Passes.
                    safetyCheck.Faults = scd.Faults.Where(scf => scf.Status != Enums.SafetyCheckStatus.Passed).ToList();

                    // Add the SMP, mileage and effective-date to the safety check
                    safetyCheck.SMP           = smp;
                    safetyCheck.Mileage       = _infoService.Mileage;
                    safetyCheck.EffectiveDate = effectiveDateTime;

                    safetyCheckDataToSubmit.Add(safetyCheck);
                }

                if (safetyCheckDataToSubmit.Any())
                {
                    var actions = safetyCheckDataToSubmit.Select(scd => new Models.GatewayServiceRequest.Action <Models.SafetyCheckData> {
                        Command = "fwSetSafetyCheckData", Data = scd
                    });
                    await _gatewayQueuedService.AddToQueueAsync(actions);
                }
            }
            else
            {
                await _repositories.LatestSafetyCheckRepository.SetForDriverAsync(latestSafetyCheck);
            }
        }