コード例 #1
0
        private async Task <bool> CallSensorCoreApiAsync(Func <Task> action)
        {
            Exception failure = null;

            try
            {
                await action();
            }
            catch (Exception e)
            {
                failure = e;
            }

            if (failure != null)
            {
                switch (SenseHelper.GetSenseError(failure.HResult))
                {
                case SenseError.LocationDisabled:
                    MessageBoxResult res = MessageBox.Show(
                        "Location has been disabled. Do you want to open Location settings now?",
                        "Information",
                        MessageBoxButton.OKCancel
                        );
                    if (res == MessageBoxResult.OK)
                    {
                        await SenseHelper.LaunchLocationSettingsAsync();
                    }

                    return(false);

                case SenseError.SenseDisabled:

                    MessageBoxResult res2 = MessageBox.Show(
                        "Motion data has been disabled. Do you want to open Motion data settings now?",
                        "Information",
                        MessageBoxButton.OKCancel
                        );

                    if (res2 == MessageBoxResult.OK)
                    {
                        await SenseHelper.LaunchSenseSettingsAsync();
                    }

                    return(false);


                default:
                    MessageBoxResult res3 = MessageBox.Show(
                        "Error:" + SenseHelper.GetSenseError(failure.HResult),
                        "Information",
                        MessageBoxButton.OK);

                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
コード例 #2
0
        private async void LocationActivationButton_Click(object sender, RoutedEventArgs e)
        {
            await SenseHelper.LaunchLocationSettingsAsync();

            // Although asynchoneous, this completes before the user has actually done anything.
            // The application will loose control, the system settings will be displayed.
            // We will get the control back to our application via an OnNavigatedTo event.
        }
コード例 #3
0
        /// <summary>
        /// Performs asynchronous SensorCore SDK operation and handles any exceptions
        /// </summary>
        /// <param name="action"></param>
        /// <returns><c>true</c> if call was successful, <c>false</c> otherwise</returns>
        private async Task <bool> CallSenseApiAsync(Func <Task> action)
        {
            Exception failure = null;

            try
            {
                await action();
            }
            catch (Exception e)
            {
                failure = e;
            }

            if (failure != null)
            {
                bool          status = false;
                MessageDialog dialog = null;
                switch (SenseHelper.GetSenseError(failure.HResult))
                {
                case SenseError.LocationDisabled:
                    dialog = 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 Location settings now? if no, application will close", "Information");
                    dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) =>
                    {
                        status = true;
                        await SenseHelper.LaunchLocationSettingsAsync();
                    })));
                    dialog.Commands.Add(new UICommand("No"));
                    await dialog.ShowAsync();

                    return(status);

                case SenseError.SenseDisabled:
                    dialog = new MessageDialog("In order to collect and view tracks of visited places you need to enable Places visited in Motion data settings. Do you want to open Motion data settings now?  if no, application will close", "Information");
                    dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) =>
                    {
                        status = true;
                        await SenseHelper.LaunchSenseSettingsAsync();
                    })));
                    dialog.Commands.Add(new UICommand("No"));
                    await dialog.ShowAsync();

                    return(status);

                case SenseError.IncompatibleSDK:
                    dialog = new MessageDialog("This application has become outdated. Please update to the latest version.", "Information");
                    await dialog.ShowAsync();

                    return(false);

                default:
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
コード例 #4
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();
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Performs asynchronous SensorCore SDK operation and handles any exceptions
        /// </summary>
        /// <param name="action"></param>
        /// <returns><c>true</c> if call was successful, <c>false</c> otherwise</returns>
        private 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("Location has been disabled. Do you want to open Location settings now?", "Information");
                    dialog.Commands.Add(new UICommand("Yes", async cmd => await SenseHelper.LaunchLocationSettingsAsync()));
                    dialog.Commands.Add(new UICommand("No"));
                    await dialog.ShowAsync();

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

                case SenseError.SenseDisabled:
                    dialog = new MessageDialog("Motion data has been disabled. Do you want to open Motion data settings now?", "Information");
                    dialog.Commands.Add(new UICommand("Yes", async cmd => await SenseHelper.LaunchSenseSettingsAsync()));
                    dialog.Commands.Add(new UICommand("No"));
                    await dialog.ShowAsync();

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

                case SenseError.SensorNotAvailable:
                    dialog = new MessageDialog("The sensor is not supported on this device", "Information");
                    await dialog.ShowAsync();

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

                default:
                    dialog = new MessageDialog("Failure: " + SenseHelper.GetSenseError(failure.HResult), "");
                    await dialog.ShowAsync();

                    return(false);
                }
            }

            return(true);
        }
コード例 #6
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();
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: ActivitySensor.cs プロジェクト: djamsoft/activities
        /// <summary>
        /// Performs asynchronous Sense SDK operation and handles any exceptions
        /// </summary>
        /// <param name="action">The function delegate to execute asynchronously when one task in the tasks completes</param>
        /// <returns><c>true</c> if call was successful, <c>false</c> otherwis:)
        /// e</returns>
        private async Task <bool> CallSensorCoreApiAsync(Func <Task> action)
        {
            Exception failure = null;

            try
            {
                await action();
            }
            catch (Exception e)
            {
                failure = e;
                Debug.WriteLine("Failure:" + e.Message);
            }
            if (failure != null)
            {
                try
                {
                    MessageDialog dialog = null;
                    switch (SenseHelper.GetSenseError(failure.HResult))
                    {
                    case SenseError.LocationDisabled:
                    {
                        dialog = 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");
                        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:
                    {
                        dialog = 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");
                        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();

                        return(false);
                    }

                    default:
                        dialog = new MessageDialog("Failure: " + SenseHelper.GetSenseError(failure.HResult), "");
                        await dialog.ShowAsync();

                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Failed to handle failure. Message:" + ex.Message);
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
コード例 #8
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();
                    }
                }
            }
        }
コード例 #9
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>
        private async Task <bool> CallSensorCoreApiAsync(Func <Task> action)
        {
            Exception failure = null;

            try
            {
                await action();
            }
            catch (Exception e)
            {
                failure = e;
            }
            if (failure != null)
            {
                MessageDialog dlg = null;
                switch (SenseHelper.GetSenseError(failure.HResult))
                {
                case SenseError.LocationDisabled:
                {
                    dlg = new MessageDialog(_resourceLoader.GetString("FeatureDisabled/Location"), _resourceLoader.GetString("FeatureDisabled/Title"));
                    dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                    dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { /* do nothing */ })));
                    await dlg.ShowAsync();

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

                case SenseError.SenseDisabled:
                {
                    dlg = new MessageDialog(_resourceLoader.GetString("FeatureDisabled/MotionData"), _resourceLoader.GetString("FeatureDisabled/Title"));
                    dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                    dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { /* do nothing */ })));
                    await dlg.ShowAsync();

                    return(false);
                }

                case SenseError.SenseNotAvailable:
                {
                    dlg = new MessageDialog(_resourceLoader.GetString("FeatureNotSupported/Message"), _resourceLoader.GetString("FeatureNotSupported/Title"));
                    await dlg.ShowAsync();

                    return(false);
                }

                default:
                {
                    dlg = new MessageDialog("Failure: " + SenseHelper.GetSenseError(failure.HResult), "");
                    await dlg.ShowAsync();

                    return(false);
                }
                }
            }
            else
            {
                return(true);
            }
        }
コード例 #10
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();
                    }
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Performs asynchronous SensorCore SDK operation and handles any exceptions
        /// </summary>
        /// <param name="action"></param>
        /// <returns><c>true</c> if call was successful, <c>false</c> otherwise</returns>
        private async Task <bool> CallSenseApiAsync(Func <Task> action)
        {
            Exception failure = null;

            try
            {
                await action();
            }
            catch (Exception e)
            {
                failure = e;
            }

            if (failure != null)
            {
                MessageDialog dialog = null;
                switch (SenseHelper.GetSenseError(failure.HResult))
                {
                case SenseError.LocationDisabled:
                    dialog = new MessageDialog("Location has been disabled. Do you want to open Location settings now?", "Information");
                    dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                    dialog.Commands.Add(new UICommand("No"));
                    await dialog.ShowAsync();

                    return(true);

                case SenseError.SenseDisabled:
                    dialog = new MessageDialog("Motion data has been disabled. Do you want to open Motion data settings now?", "Information");
                    dialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                    dialog.Commands.Add(new UICommand("No"));
                    await dialog.ShowAsync();

                    return(true);

                case SenseError.IncompatibleSDK:
                    dialog = new MessageDialog("This application has become outdated. Please update to the latest version.", "Information");
                    await dialog.ShowAsync();

                    return(false);

                default:
                    dialog = new MessageDialog("Failure: " + SenseHelper.GetSenseError(failure.HResult), "");
                    await dialog.ShowAsync();

                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
コード例 #12
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);
        }
コード例 #13
0
ファイル: ActivitySensor.cs プロジェクト: djamsoft/activities
        /// <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();
                    }
                }
            }
        }
コード例 #14
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();
        }
コード例 #15
0
ファイル: MapPage.xaml.Sensors.cs プロジェクト: smych/places
        /// <summary>
        /// Performs asynchronous Sensorcore SDK operation and handles any exceptions
        /// </summary>
        /// <param name="action">The function delegate to execute asynchronously when one task in the tasks completes.</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)
            {
                switch (SenseHelper.GetSenseError(failure.HResult))
                {
                case SenseError.LocationDisabled:
                    MessageDialog dialog = new MessageDialog("In order to collect and view visited places 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();

                    MessageDialog dlg = null;
                    if (settings.Version < 2)
                    {
                        // Device has old Motion data settings
                        dlg = new MessageDialog("In order to collect and view visited places you need to enable Motion data 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 places 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();

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

                case SenseError.GeneralFailure:
                    return(false);

                case SenseError.IncompatibleSDK:
                    MessageDialog dialog2 = new MessageDialog("This application has become outdated. Please update to the latest version.", "Information");
                    await dialog2.ShowAsync();

                    return(false);

                default:
                    return(false);
                }
            }
            return(true);
        }
コード例 #16
0
ファイル: MapPage.xaml.Sensors.cs プロジェクト: smych/places
        /// <summary>
        /// Makes sure necessary settings are enabled in order to use SensorCore
        /// </summary>
        /// <returns>Asynchronous task</returns>
        private async Task ValidateSettingsAsync()
        {
            try
            {
                if (!(await PlaceMonitor.IsSupportedAsync()))
                {
                    MessageDialog dlg = new MessageDialog("Unfortunately this device does not support viewing visited places");
                    await dlg.ShowAsync();

                    Application.Current.Exit();
                }
                else
                {
                    MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to collect and view visited places 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 places you need to enable Motion data 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 places 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)
            {
            }
        }
コード例 #17
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();
        }