Exemplo n.º 1
0
        /// <summary>
        /// Makes sure necessary settings are enabled in order to use SensorCore
        /// </summary>
        /// <returns>Asynchronous task</returns>
        public static async Task ValidateSettingsAsync()
        {
            if (await StepCounter.IsSupportedAsync())
            {
                // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
                // location setting and Motion data had to be enabled.
                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                if (settings.Version < 2)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable location in system settings. Do you want to open settings now? If not, application will exit.", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                    if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable Motion data in Motion data settings. Do you want to open settings now? If not, application will exit.", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check motion data settings
        /// </summary>
        private async void CheckMotionDataSettings()
        {
            if (!(await TrackPointMonitor.IsSupportedAsync()) || !(await PlaceMonitor.IsSupportedAsync()) || !(await StepCounter.IsSupportedAsync()) || !(await ActivityMonitor.IsSupportedAsync()))
            {
                MessageBoxResult dlg = MessageBox.Show("Unfortunately this device does not support SensorCore service");
                Application.Current.Terminate();
            }
            else
            {
                uint apiSet = await SenseHelper.GetSupportedApiSetAsync();

                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                // Devices with old location settings
                if (!settings.LocationEnabled)
                {
                    MessageBoxResult dlg = MessageBox.Show("In order to recognize activities and view visited places you need to enable location in system settings. Do you want to open settings now? if no, applicatoin will exit", "Information", MessageBoxButton.OKCancel);
                    if (dlg == MessageBoxResult.OK)
                    {
                        await SenseHelper.LaunchLocationSettingsAsync();
                    }
                }
                if (!settings.PlacesVisited)
                {
                    MessageBoxResult dlg = new MessageBoxResult();
                    if (settings.Version < 2)
                    {
                        //device which has old motion data settings.
                        //this is equal to motion data settings on/off in old system settings(SDK1.0 based)
                        dlg = MessageBox.Show("In order to count steps you need to enable Motion data collection in Motion data settings. Do you want to open settings now?", "Information", MessageBoxButton.OKCancel);
                        if (dlg == MessageBoxResult.Cancel)
                        {
                            Application.Current.Terminate();
                        }
                    }
                    else
                    {
                        dlg = MessageBox.Show("In order to recognize activities you need to 'enable Places visited' and 'DataQuality to detailed' in Motion data settings. Do you want to open settings now? ", "Information", MessageBoxButton.OKCancel);
                    }
                    if (dlg == MessageBoxResult.OK)
                    {
                        await SenseHelper.LaunchSenseSettingsAsync();
                    }
                }
                else if (apiSet >= 3 && settings.DataQuality == DataCollectionQuality.Basic)
                {
                    MessageBoxResult dlg = MessageBox.Show("In order to recognize biking activity you need to enable detailed data collection in Motion data settings. Do you want to open settings now?", "Information", MessageBoxButton.OKCancel);
                    if (dlg == MessageBoxResult.OK)
                    {
                        await SenseHelper.LaunchSenseSettingsAsync();
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Performs asynchronous Sensorcore SDK operation and handles any exceptions
        /// </summary>
        /// <param name="action">Action for which the SensorCore will be activated.</param>
        /// <returns><c>true</c> if call was successful, <c>false</c> otherwise</returns>
        public async Task <bool> CallSensorcoreApiAsync(Func <Task> action)
        {
            Exception failure = null;

            try
            {
                await action();
            }
            catch (Exception e)
            {
                failure = e;
            }
            if (failure != null)
            {
                MessageDialog dialog;
                switch (SenseHelper.GetSenseError(failure.HResult))
                {
                case SenseError.LocationDisabled:
                    dialog = new MessageDialog("In order to collect and view visited tracks you need to enable location in system settings. Do you want to open settings now? If not, application will exit.", "Information");
                    dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                    dialog.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                    await dialog.ShowAsync();

                    new System.Threading.ManualResetEvent(false).WaitOne(500);
                    return(false);

                case SenseError.SenseDisabled:
                {
                    MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                    if (settings.Version < 2)
                    {
                        // Device has old Motion data settings
                        dialog = new MessageDialog("In order to collect and view visited tracks you need to enable 'Motion data collection' in Motion data settings. Do you want to open settings now? If not, application will exit.", "Information");
                    }
                    else
                    {
                        dialog = new MessageDialog("In order to collect and view visited tracks you need to enable 'Places visited' in Motion data settings. Do you want to open settings now? if not, application will exit.", "Information");
                    }
                    dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                    dialog.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                    await dialog.ShowAsync();

                    new System.Threading.ManualResetEvent(false).WaitOne(500);
                    return(false);
                }

                default:
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Validate if settings have been configured correctly to run SensorCore.
        /// </summary>
        /// <returns>Asynchronous task/returns>
        public static async Task ValidateSettingsAsync()
        {
            if (!(await ActivityMonitor.IsSupportedAsync()))
            {
                MessageDialog dlg = new MessageDialog(_resourceLoader.GetString("FeatureNotSupported/Message"), _resourceLoader.GetString("FeatureNotSupported/Title"));
                await dlg.ShowAsync();

                Application.Current.Exit();
            }
            else
            {
                uint apiSet = await SenseHelper.GetSupportedApiSetAsync();

                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                if (settings.Version < 2)
                {
                    // Device which has old Motion data settings which requires system location and Motion data be enabled in order to access
                    // ActivityMonitor.
                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to recognize activities you need to enable location in system settings. Do you want to open settings now? If not, application will exit.", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                    else if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = new MessageDialog("In order to recognize activities you need to enable Motion data in Motion data settings. Do you want to open settings now? If not, application will exit.", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                }
                else if (apiSet >= 3)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to recognize biking you need to enable location in system settings. Do you want to open settings now?", "Helpful tip");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No"));
                        await dlg.ShowAsync();
                    }
                    else if (settings.DataQuality == DataCollectionQuality.Basic)
                    {
                        MessageDialog dlg = new MessageDialog("In order to recognize biking you need to enable detailed data collection in Motion data settings. Do you want to open settings now?", "Helpful tip");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No"));
                        await dlg.ShowAsync();
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Makes sure necessary settings are enabled in order to use SensorCore
        /// </summary>
        /// <returns>Asynchronous task</returns>
        private async Task ValidateSettingsAsync()
        {
            try
            {
                if (!(await TrackPointMonitor.IsSupportedAsync()))
                {
                    MessageDialog dlg = new MessageDialog("Unfortunately this device does not support viewing tracks");
                    await dlg.ShowAsync();

                    Application.Current.Exit();
                }
                else
                {
                    _apiSet = await SenseHelper.GetSupportedApiSetAsync();

                    MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to collect and view visited tracks you need to enable location in system settings. Do you want to open settings now? if not, application will exit", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                    if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = null;
                        if (settings.Version < 2)
                        {
                            // Device has old Motion data settings
                            dlg = new MessageDialog("In order to collect and view visited tracks you need to enable 'Motion data collection' in Motion data settings. Do you want to open settings now? If not, application will exit.", "Information");
                        }
                        else
                        {
                            dlg = new MessageDialog("In order to collect and view visited tracks you need to enable 'Places visited' in Motion data settings. Do you want to open settings now? If not, application will exit.", "Information");
                        }
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Check motion data settings
        /// </summary>
        private async void CheckMotionDataSettings()
        {
            if (!(await StepCounter.IsSupportedAsync()))
            {
                MessageDialog dlg = new MessageDialog("Unfortunately this device does not support step counting");
                await dlg.ShowAsync();

                Application.Current.Exit();
            }
            else
            {
                // MotionDataSettings settings = await SenseHelper.GetSettingsAsync();
                // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
                // location setting and Motion data had to be enabled.
                uint apiSet = await SenseHelper.GetSupportedApiSetAsync();

                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                if (apiSet > 2)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable location in system settings. Do you want to open settings now?", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No"));
                        await dlg.ShowAsync();
                    }
                    if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = null;
                        if (settings.Version < 2)
                        {
                            dlg = new MessageDialog("In order to count steps you need to enable Motion data collection in Motion data settings. Do you want to open settings now?", "Information");
                        }
                        else
                        {
                            dlg = new MessageDialog("In order to collect and view visited places you need to enable Places visited in Motion data settings. Do you want to open settings now? if no, application will exit", "Information");
                        }
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Makes sure necessary settings are enabled in order to use SensorCore
        /// </summary>
        /// <returns>Asynchronous task</returns>
        public async Task ValidateSettingsAsync()
        {
            if (!await StepCounter.IsSupportedAsync())
            {
                MessageBoxResult dlg = MessageBox.Show("Unfortunately this device does not support step counting");
                Application.Current.Terminate();
            }
            else
            {
                // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
                // location setting and Motion data had to be enabled.
                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                if (settings.Version < 2)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageBoxResult dlg = MessageBox.Show("In order to count steps you need to enable location in system settings. Do you want to open settings now? If not, application will exit.", "Information", MessageBoxButton.OKCancel);
                        if (dlg == MessageBoxResult.OK)
                        {
                            await SenseHelper.LaunchLocationSettingsAsync();
                        }
                        else
                        {
                            Application.Current.Terminate();
                        }
                    }
                    if (!settings.PlacesVisited)
                    {
                        MessageBoxResult rc = MessageBox.Show("In order to count steps you need to enable Motion data collection in Motion data settings. Do you want to open settings now? If not, application will exit.", "Information", MessageBoxButton.OKCancel);
                        if (rc == MessageBoxResult.OK)
                        {
                            await SenseHelper.LaunchSenseSettingsAsync();
                        }
                        else
                        {
                            Application.Current.Terminate();
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes sensor
        /// </summary>
        /// <returns>Asynchronous task</returns>
        private async Task Initialize()
        {
            if (!await StepCounter.IsSupportedAsync())
            {
                MessageDialog dlg = new MessageDialog("Unfortunately this device does not support step counting");
                await dlg.ShowAsync();
            }
            else
            {
                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
                // location setting and Motion data had to be enabled.
                if (settings.Version < 2)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable location in system settings. Do you want to open settings now?", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No"));
                        await dlg.ShowAsync();
                    }
                    else if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable Motion data collection in Motion data settings. Do you want to open settings now?", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No"));
                        await dlg.ShowAsync();
                    }
                }
            }

            if (!await CallSenseApiAsync(async() =>
            {
                _stepCounter = await StepCounter.GetDefaultAsync();
            }))
            {
                Application.Current.Exit();
            }
            await SetSelectedDayAsync(_selectedDay);
        }
Exemplo n.º 9
0
        /// <summary>
        /// initializes the sensor services
        /// </summary>
        /// <returns></returns>
        private async Task Initialize()
        {
            //following code assumes that device has new software(SensorCoreSDK1.1 based)
            try
            {
                if (!(await TrackPointMonitor.IsSupportedAsync()))
                {
                    MessageDialog dlg = new MessageDialog("Unfortunately this device does not support Trackpoints of visited places");
                    await dlg.ShowAsync();

                    Application.Current.Exit();
                }
                else
                {
                    uint apiSet = await SenseHelper.GetSupportedApiSetAsync();

                    MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to collect and view tracks of visited places you need to enable location in system settings. Do you want to open settings now? if no, applicatoin will close", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) =>
                        {
                            Application.Current.Exit();
                        })));
                        await dlg.ShowAsync();
                    }

                    if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = null;
                        if (settings.Version < 2)
                        {
                            //device which has old motion data settings.
                            //this is equal to motion data settings on/off in old system settings(SDK1.0 based)
                            dlg = new MessageDialog("In order to collect and view tracks of visited places you need to enable Motion data in Motion data settings. Do you want to open settings now? if no, application will close", "Information");
                        }
                        else
                        {
                            dlg = new MessageDialog("In order to collect and view tracks of visited places you need to 'enable Places visited' and 'DataQuality to detailed' in Motion data settings. Do you want to open settings now? if no, application will close", "Information");
                        }
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) =>
                        {
                            Application.Current.Exit();
                        })));
                        await dlg.ShowAsync();
                    }
                }
            }
            catch (Exception)
            {
            }

            //in case if the device has old software(earlier than SDK1.1) or system settings changed after sometime, CallSenseApiAsync() method handles the system settings prompts.
            if (_trackMonitor == null)
            {
                if (!await CallSenseApiAsync(async() =>
                {
                    _trackMonitor = await TrackPointMonitor.GetDefaultAsync();
                }))
                {
                    Application.Current.Exit();
                }
            }

            //setting current loation in the map
            try
            {
                TracksMapControl.MapServiceToken = "4eSgIBUeMtjFyJP6YxkyPQ";
                Geoposition geoposition = await new Geolocator().GetGeopositionAsync(maximumAge: TimeSpan.FromMinutes(5), timeout: TimeSpan.FromSeconds(5));
                TracksMapControl.Center = geoposition.Coordinate.Point;
            }
            catch (Exception)
            {
                // if current position can't get, setting default position to Espoo, Finland.
                TracksMapControl.Center = new Geopoint(new BasicGeoposition()
                {
                    Latitude  = 60.17,
                    Longitude = 24.83
                });
            }
            await GetHistory();

            UpdateScreenAsync();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes sensors
        /// </summary>
        /// <returns>Asynchronous task</returns>
        private async Task Initialize()
        {
            if (!(await ActivityMonitor.IsSupportedAsync()))
            {
                MessageDialog dlg = new MessageDialog("Unfortunately this device does not support activities.");
                await dlg.ShowAsync();

                Application.Current.Exit();
            }
            else
            {
                uint apiSet = await SenseHelper.GetSupportedApiSetAsync();

                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                // devices with old sensorCore SDK service
                if (settings.Version < 2 && !settings.LocationEnabled)
                {
                    MessageDialog dlg = new MessageDialog("In order to recognize activities you need to enable location in system settings. Do you want to open settings now? if no, applicatoin will exit", "Information");
                    dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                    dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) =>
                    {
                        Application.Current.Exit();
                    })));
                    await dlg.ShowAsync();
                }

                if (!settings.PlacesVisited)
                {
                    MessageDialog dlg = null;
                    if (settings.Version < 2)
                    {
                        //device which has old motion data settings.
                        //this is equal to motion data settings on/off in old system settings(SDK1.0 based)
                        dlg = new MessageDialog("In order to recognize activities you need to enable Motion data in Motion data settings. Do you want to open settings now? if no, application will exit", "Information");
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) =>
                        {
                            Application.Current.Exit();
                        })));
                    }
                    else
                    {
                        dlg = new MessageDialog("In order to recognize activities you need to 'enable Places visited' and 'DataQuality to detailed' in Motion data settings. Do you want to open settings now? ", "Information");
                        dlg.Commands.Add(new UICommand("No"));
                    }
                    dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                    await dlg.ShowAsync();
                }
                else if (apiSet >= 3 && settings.DataQuality == DataCollectionQuality.Basic)
                {
                    MessageDialog dlg = new MessageDialog("In order to recognize biking you need to enable detailed data collection in Motion data settings. Do you want to open settings now?", "Information");
                    dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                    dlg.Commands.Add(new UICommand("No"));
                    await dlg.ShowAsync();
                }
            }

            //in case if the device has old software(earlier than SDK1.1) or system settings changed after sometime, CallSenseApiAsync() method handles the system settings prompts.
            if (_activityMonitor == null)
            {
                if (!await CallSenseApiAsync(async() =>
                {
                    _activityMonitor = await ActivityMonitor.GetDefaultAsync();
                }))
                {
                    Application.Current.Exit();
                }
            }
            await UpdateScreenAsync();
        }