Beispiel #1
0
        public async void getCurrentReading(string options)
        {
            PluginResult result = new PluginResult(PluginResult.Status.OK);
            result.KeepCallback = true;

            try
            {
                PedometerReading reading = new PedometerReading();
                if (!isReady)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, latestReading ?? reading));
                    return;
                }

                StepCounterReading current = await stepCounter.GetCurrentReadingAsync();
                StepCounterReading today = await stepCounter.GetStepCountAtAsync(DateTimeOffset.Now.Date);

                if (null == current && null == today)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, latestReading ?? reading));
                    return;
                }

                if (null == today) today = new StepCounterReading(0, TimeSpan.FromMilliseconds(0), 0, TimeSpan.FromMilliseconds(0), DateTimeOffset.Now.Date);

                reading.todayWalkingSteps = Convert.ToInt32(current.WalkingStepCount - today.WalkingStepCount);
                reading.todayWalkingMinutes = Convert.ToInt32(current.WalkTime.TotalMinutes - today.WalkTime.TotalMinutes);
                reading.todayRunningSteps = Convert.ToInt32(current.RunningStepCount - today.RunningStepCount);
                reading.todayRunningMinutes = Convert.ToInt32(current.RunTime.TotalMinutes - today.RunTime.TotalMinutes);

                if (runStarted.HasValue)
                {
                    StepCounterReading lastRun = await stepCounter.GetStepCountAtAsync(runStarted.Value);
                    reading.lastRunSteps = Convert.ToInt32(current.WalkingStepCount - lastRun.WalkingStepCount);
                    reading.lastRunMinutes = Convert.ToInt32(current.RunTime.TotalMinutes - lastRun.RunTime.TotalMinutes);
                }

                latestReading = reading;

                result.Message = JsonHelper.Serialize(reading);
                DispatchCommandResult(result);
            }
            catch (Exception ex)
            {
                result.Message = JsonHelper.Serialize(new { error = "getCurrentReading", message = ex.Message });
                DispatchCommandResult(result);
            }
        }