コード例 #1
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();
        }
コード例 #2
0
        /// <summary>
        /// Initialize SensorCore
        /// </summary>
        /// <param name="rec">Recording instance</param>
        /// <param name="type">Sense type</param>
        /// <returns>Asynchronous task</returns>
        private async Task HandleSensorActivity(Recording rec, SenseType type)
        {
            if (rec.Recorder == null)
            {
                if (await CallSensorcoreApiAsync(async() =>
                {
                    switch (type)
                    {
                    case SenseType.Activity:
                        _aMonitor = await ActivityMonitor.GetDefaultAsync();
                        break;

                    case SenseType.Places:
                        _pMonitor = await PlaceMonitor.GetDefaultAsync();
                        break;

                    case SenseType.Route:
                        _rTracker = await TrackPointMonitor.GetDefaultAsync();
                        break;

                    case SenseType.Steps:
                        _sCounter = await StepCounter.GetDefaultAsync();
                        break;
                    }
                }))
                {
                    Debug.WriteLine("Recorder initialized.");
                    switch (type)
                    {
                    case SenseType.Activity:
                        rec.Recorder = new SenseRecorder(_aMonitor);
                        break;

                    case SenseType.Places:
                        rec.Recorder = new SenseRecorder(_pMonitor);
                        break;

                    case SenseType.Route:
                        rec.Recorder = new SenseRecorder(_rTracker);
                        break;

                    case SenseType.Steps:
                        rec.Recorder = new SenseRecorder(_sCounter);
                        break;
                    }
                }
                else
                {
                    return;
                }
            }
            if (rec.Recorder == null)
            {
                return;
            }
            else
            {
                await ActivateAsync();

                switch (rec.ItemState)
                {
                case Status.Recording:
                    await rec.Recorder.StartAsync();

                    break;

                case Status.Stopped:
                    await rec.Recorder.StopAsync();

                    break;

                case Status.Empty:
                    await rec.Recorder.GetRecording().SaveAsync();

                    break;
                }
            }
        }