Inheritance: IPnpObjectWatcher
コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: JMLIT/WP8Meteo
        async void watcher_Updated(PnpObjectWatcher sender, PnpObjectUpdate args)
        {
            watcher.Stop();

            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                await Task.Delay(5000);
                var viewModel = new MainPageViewModel();
                await viewModel.Init();
                this.ViewModel = viewModel;
            });
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: JMLIT/WP8Meteo
    /// <summary>
    /// Invoqué lorsque cette page est sur le point d'être affichée dans un frame.
    /// </summary>
    /// <param name="e">Données d'événement décrivant la manière dont l'utilisateur a accédé à cette page.
    /// Ce paramètre est généralement utilisé pour configurer la page.</param>
    protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // TODO: préparer la page pour affichage ici.
            var viewModel = new MainPageViewModel();

            if (await viewModel.Init())
            {
                this.ViewModel = viewModel;

            }
            else
            {
                watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { "System.Devices.Connected" }, String.Empty);
                watcher.Updated += watcher_Updated;
                watcher.Start();
            }
        }
コード例 #3
0
ファイル: HeartRateService.cs プロジェクト: mbin/Win81App
        private void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
        {
            IsServiceInitialized = false;

            // This is an appropriate place to save to persistent storage any datapoint the application cares about.
            // For the purpose of this sample we just discard any values.
            datapoints.Clear();

            // Allow the GattDeviceService to get cleaned up by the Windows Runtime.
            // The Windows runtime will clean up resources used by the GattDeviceService object when the application is
            // suspended. The GattDeviceService object will be invalid once the app resumes, which is why it must be 
            // marked as invalid, and reinitalized when the application resumes.
            if (service != null)
            {
                service.Dispose();
                service = null;
            }

            if (characteristic != null)
            {
                characteristic = null;
            }

            if (watcher != null)
            {
                watcher.Stop();
                watcher = null;
            }
        }
コード例 #4
0
ファイル: HeartRateService.cs プロジェクト: mbin/Win81App
        /// <summary>
        /// Invoked when a connection is established to the Bluetooth device
        /// </summary>
        /// <param name="sender">The watcher object that sent the notification</param>
        /// <param name="args">The updated device object properties</param>
        private async void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args)
        {
            var connectedProperty = args.Properties["System.Devices.Connected"];
            bool isConnected = false;
            if ((deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) &&
                isConnected)
            {
                var status = await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(
                    CHARACTERISTIC_NOTIFICATION_TYPE);

                if (status == GattCommunicationStatus.Success)
                {
                    IsServiceInitialized = true;

                    // Once the Client Characteristic Configuration Descriptor is set, the watcher is no longer required
                    watcher.Stop();
                    watcher = null;
                }

                // Notifying subscribers of connection state updates
                if (DeviceConnectionUpdated != null)
                {
                    DeviceConnectionUpdated(isConnected);
                }
            }
        }
コード例 #5
0
ファイル: HeartRateService.cs プロジェクト: mbin/Win81App
        /// <summary>
        /// Register to be notified when a connection is established to the Bluetooth device
        /// </summary>
        private void StartDeviceConnectionWatcher()
        {
            watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer,
                new string[] { "System.Devices.Connected" }, String.Empty);

            watcher.Updated += DeviceConnection_Updated;
            watcher.Start();
        }
コード例 #6
0
 public PnpObjectWatcherEvents(PnpObjectWatcher This)
 {
     this.This = This;
 }