Exemplo n.º 1
0
        public async Task <bool> StopRecordingTrip()
        {
            if (IsBusy || !IsRecording)
            {
                return(false);
            }


            //always will have 1 point, so we can stop.
            CurrentTrip.EndTimeStamp = DateTime.UtcNow;
            try
            {
                if (obdDataProcessor != null)
                {
                    //Disconnect from the OBD device; if still trying to connect, stop polling for the device
                    await obdDataProcessor.DisconnectFromObdDevice();
                }
            }
            catch (Exception ex)
            {
                //22 Logger.Instance.Report(ex);
            }

            /*23
             * List<POI> poiList = new List<POI>();
             * try
             * {
             *  poiList = new List<POI>(await StoreManager.POIStore.GetItemsAsync(CurrentTrip.Id));
             * }
             * catch (Exception ex)
             * {
             *  //Intermittently, Sqlite will cause a crash for WinPhone saying "unable to set temporary directory"
             *  //If this call fails, simply use an empty list of POIs
             *  Logger.Instance.Track("Unable to get POI Store Items.");
             *  Logger.Instance.Report(ex);
             * }
             *
             *
             * CurrentTrip.HardStops = poiList.Where(p => p.POIType == POIType.HardBrake).Count();
             * CurrentTrip.HardAccelerations = poiList.Where(p => p.POIType == POIType.HardAcceleration).Count();
             */

            TripSummary = new TripSummaryViewModel
            {
                TotalTime         = (CurrentTrip.EndTimeStamp - CurrentTrip.RecordedTimeStamp).TotalSeconds,
                TotalDistance     = CurrentTrip.Distance,
                FuelUsed          = CurrentTrip.FuelUsed,
                MaxSpeed          = CurrentTrip.Points.Max(s => s.Speed),
                HardStops         = CurrentTrip.HardStops,
                HardAccelerations = CurrentTrip.HardAccelerations,
                Date = DateTime.UtcNow
            };

            IsRecording = false;
            NeedSave    = true;
            //24 Logger.Instance.Track("StopRecording");
            return(true);
        }
Exemplo n.º 2
0
        public async Task <bool> StopRecordingTrip()
        {
            if (IsBusy || !IsRecording)
            {
                return(false);
            }


            //always will have 1 point, so we can stop.
            CurrentTrip.EndTimeStamp = DateTime.UtcNow;
            try
            {
                if (obdDataProcessor != null)
                {
                    //Disconnect from the OBD device; if still trying to connect, stop polling for the device
                    await obdDataProcessor.DisconnectFromObdDevice();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Report(ex);
            }

            List <POI> poiList = new List <POI>(await StoreManager.POIStore.GetItemsAsync(CurrentTrip.Id));

            CurrentTrip.HardStops         = poiList.Where(p => p.POIType == POIType.HardBrake).Count();
            CurrentTrip.HardAccelerations = poiList.Where(p => p.POIType == POIType.HardAcceleration).Count();

            TripSummary = new TripSummaryViewModel
            {
                TotalTime         = (CurrentTrip.EndTimeStamp - CurrentTrip.RecordedTimeStamp).TotalSeconds,
                TotalDistance     = CurrentTrip.Distance,
                FuelUsed          = CurrentTrip.FuelUsed,
                MaxSpeed          = CurrentTrip.Points.Max(s => s.Speed),
                HardStops         = CurrentTrip.HardStops,
                HardAccelerations = CurrentTrip.HardAccelerations,
                Date = DateTime.UtcNow
            };

            IsRecording = false;
            NeedSave    = true;
            Logger.Instance.Track("StopRecording");
            return(true);
        }