Exemplo n.º 1
0
        private Task AcknowledgeInstructionsAsync(IEnumerable <MobileData> instructions)
        {
            //Sends acknowledgement to bluesphere that the device has received the new instructions
            var syncAckActions = instructions.Select(i => new Models.GatewayServiceRequest.Action <Models.SyncAck>
            {
                Command    = "fwSyncAck",
                Parameters = new[]
                {
                    new Parameter {
                        Name = "MobileApplicationDataID", Value = i.ID.ToString()
                    },
                    new Parameter {
                        Name = "SyncAck", Value = "1"
                    },
                }
            });

            return(_gatewayQueuedService.AddToQueueAsync(syncAckActions));
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method sends the instructions that have been acknowledged by the driver.
        /// This is in the form of a 'Read' Chunk
        /// </summary>
        /// <param name="instructions">The instruction that have been acknowledged</param>
        public async Task SendReadChunkAsync(IEnumerable <MobileData> instructions, Guid currentDriverID, string currentVehicleRegistration)
        {
            //The data chunk to be sent.
            MobileApplicationDataChunkCollection dataChunkCollection = new MobileApplicationDataChunkCollection {
                MobileApplicationDataChunkCollectionObject = new List <MobileApplicationDataChunk>()
            };

            foreach (var instruction in instructions)
            {
                MobileApplicationDataChunk dataChunk = new MobileApplicationDataChunk();
                MobileApplicationDataChunkContentActivity dataChunkActivity = new MobileApplicationDataChunkContentActivity();

                //These variables make up the Data variable in the MobileApplicationDataChunk object.
                MobileApplicationDataChunkContentActivities dataChunkActivities = new MobileApplicationDataChunkContentActivities {
                    MobileApplicationDataChunkContentActivitiesObject = new List <MobileApplicationDataChunkContentActivity>()
                };
                MobileApplicationDataChunkContentOrder dataChunkOrder = new MobileApplicationDataChunkContentOrder {
                    MobileApplicationDataChunkContentOrderActivities = new List <MobileApplicationDataChunkContentActivities>()
                };

                instruction.LatestDataChunkSequence++;

                dataChunkActivity.Activity            = 10;
                dataChunkActivity.DriverId            = currentDriverID;
                dataChunkActivity.EffectiveDate       = DateTime.Now;
                dataChunkActivity.EffectiveDate       = dataChunkActivity.EffectiveDate.AddMilliseconds(-dataChunkActivity.EffectiveDate.Millisecond);
                dataChunkActivity.MwfVersion          = "";
                dataChunkActivity.VehicleRegistration = currentVehicleRegistration;
                dataChunkActivity.Smp      = _gpsService.GetSmpData(Enums.ReportReason.Begin);
                dataChunkActivity.Title    = "READ";
                dataChunkActivity.Sequence = instruction.LatestDataChunkSequence;

                dataChunkActivities.MobileApplicationDataChunkContentActivitiesObject.Add(dataChunkActivity);
                dataChunkOrder.MobileApplicationDataChunkContentOrderActivities.Add(dataChunkActivities);

                dataChunk.EffectiveDate           = dataChunkActivity.EffectiveDate;
                dataChunk.ID                      = Guid.NewGuid();
                dataChunk.MobileApplicationDataID = instruction.ID;
                dataChunk.SyncState               = Enums.SyncState.Add;
                dataChunk.Title                   = "READ";
                dataChunk.Data                    = dataChunkOrder;
                dataChunk.Sequence                = instruction.Sequence;

                dataChunkCollection.MobileApplicationDataChunkCollectionObject.Add(dataChunk);

                if (instruction.SyncState != Enums.SyncState.Delete)
                {
                    var mobileDataToUpdate = await _repositories.MobileDataRepository.GetByIDAsync(instruction.ID);

                    if (mobileDataToUpdate != null)
                    {
                        await _repositories.MobileDataRepository.DeleteAsync(mobileDataToUpdate);
                    }

                    try
                    {
                        await _repositories.MobileDataRepository.InsertAsync(instruction);
                    }
                    catch (Exception ex)
                    {
                        MvxTrace.Error("\"{0}\" in {1}.{2}\n{3}", ex.Message, "MobileDataRepository", "InsertAsync", ex.StackTrace);
                        throw;
                    }
                }
            }

            await _gatewayQueuedService.AddToQueueAsync("fwSyncChunkToServer", dataChunkCollection);
        }