Esempio n. 1
0
        /// <summary>
        /// Play preinstalled recording button click handler
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="args">Event arguments</param>
        private async void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            SenseRecording recording       = null;
            WebErrorStatus exceptionDetail = new WebErrorStatus();

            try
            {
                recording = await SenseRecording.LoadFromUriAsync(new Uri("https://github.com/Microsoft/steps/raw/master/Steps/Simulations/short%20walk.txt"));
            }
            catch (Exception ex)
            {
                exceptionDetail = WebError.GetStatus(ex.GetBaseException().HResult);
            }
            if (exceptionDetail == WebErrorStatus.HostNameNotResolved)
            {
                MessageDialog dialog = new MessageDialog("Check your network connection. Host name could not be resolved.", "Information");
                await dialog.ShowAsync();
            }
            if (recording != null)
            {
                _stepCounter = await StepCounterSimulator.GetDefaultAsync(recording);

                MessageDialog dialog = new MessageDialog(
                    "Recorded sensor type: " + recording.Type.ToString() +
                    "\r\nDescription: " + recording.Description +
                    "\r\nRecording date: " + recording.StartTime.ToString() +
                    "\r\nDuration: " + recording.Duration.ToString(),
                    "Recording info"
                    );
                await dialog.ShowAsync();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets number of steps for current day
        /// </summary>
        /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns>
        private async Task <bool> GetStepsAsync()
        {
            // First try the pedometer
            try
            {
                var readings = await Pedometer.GetSystemHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);

                _steps = StepCountData.FromPedometerReadings(readings);
                return(true);
            }
            catch (Exception)
            {
                // Continue to the fallback
            }

            // Fall back to using Lumia Sensor Core.
            IStepCounter stepCounter = null;

            try
            {
                //var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;

                if (DeviceTypeHelper.GetDeviceFormFactorType() == DeviceFormFactorType.Phone)
                {
                    stepCounter = await StepCounter.GetDefaultAsync();

                    StepCount count = await stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);

                    _steps = StepCountData.FromLumiaStepCount(count);
                }
                else
                {
                    var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt");

                    if (!await CallSensorCoreApiAsync(async() => {
                        stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12));
                        StepCount count = await stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);
                        _steps = StepCountData.FromLumiaStepCount(count);
                    }))
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                _lastError = SenseHelper.GetSenseError(e.HResult);
                return(false);
            }
            finally
            {
                if (stepCounter != null && typeof(StepCounter) == stepCounter.GetType())
                {
                    ((StepCounter)stepCounter).Dispose();
                }
            }
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes StepCounterSimulator (requires Lumia.Sense.Testing)
        /// </summary>
        public async Task InitializeSimulatorAsync()
        {
            var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt");

            if (!await CallSensorCoreApiAsync(async() => { _stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12)); }))
            {
                Application.Current.Exit();
            }
            _sensorActive = true;
        }
Esempio n. 4
0
        private async Task InitializeSimulatorAsync()
        {
            var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt");

            bool res = await CallSensorCoreApiAsync(async() => { _stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12)); });

            if (!res)
            {
                Application.Current.Terminate();
            }
        }