protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            // Reset Device List selection
            if (_deviceListBox != null)
            {
                _deviceListBox.SelectedIndex = -1;
            }

            if (_firstEntry)
            {
                Visibility BackgroundAccessProblemVisibility = Visibility.Collapsed;
                _firstEntry = false;

                // Don't show the background access error for now
                SetValue(BackgroundAccessProblemProperty, Visibility.Collapsed);

                // Request for background access
                // Make sure this is done at the end of this function, as it returns
                // once the first blocking call is encountered
                await GlobalSettings.RequestBackgroundAccessAsync();

                if (!GlobalSettings.BackgroundAccessRequested)
                {
                    BackgroundAccessProblemVisibility = Visibility.Visible;
                }
                SetValue(BackgroundAccessProblemProperty, BackgroundAccessProblemVisibility);

                // Populate the Device List off the UI thread, but don't block on it
                Utilities.RunFuncAsTask(PopulateLEDeviceListAsync);
            }
        }
Пример #2
0
        // Navigate to Characteristic's page, once one has been chosen.
        private void OnCharacteristicSelectionChanged(object sender, RoutedEventArgs e)
        {
            ListBox listBox = (ListBox)sender;

            // Looks like we didn't actually select anything.
            if (listBox.SelectedIndex == -1)
            {
                return;
            }

            // Get the characteristic that we've picked.
            foreach (var listBoxItem in listBox.SelectedItems)
            {
                BECharacteristicVM characteristic = (BECharacteristicVM)listBoxItem;
                GlobalSettings.SelectedCharacteristic = characteristic.CharacteristicM;
            }

            // Go to the characteristic page.
            this.Frame.Navigate(typeof(CharacteristicInfo));

            // Since we're navigating away from a page that may change a service, we should save
            // its dictionary.
            if (ServiceVM.ServiceM.DictionaryModelChanged)
            {
                // This is not critical and doesn't have to block execution
                // Make sure this is done at the end of this function, as it returns
                // once the first blocking call is encountered
                Utilities.RunFuncAsTask(GlobalSettings.ServiceDictionaryUnknown.SaveDictionaryAsync);
            }
        }
        private void OnBackPressed(object sender, BackPressedEventArgs e)
        {
            if (this.Frame.CanGoBack)
            {
                DeviceVM.UnregisterVMFromModel();
                this.Frame.GoBack();
                e.Handled = true;

                // Unregister notifications off the UI thrad
                Utilities.RunFuncAsTask(GlobalSettings.SelectedDevice.UnregisterNotificationsAsync);
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            message = "";

            // These must be initialized before the UI loads
            CharacteristicVM.Initialize(GlobalSettings.SelectedCharacteristic);
            ServiceVM.Initialize(GlobalSettings.SelectedCharacteristic.ServiceM);
            DeviceVM.Initialize(GlobalSettings.SelectedCharacteristic.ServiceM.DeviceM);

            // Read the characteristic value on a separate thread
            Utilities.RunFuncAsTask(GlobalSettings.SelectedCharacteristic.ReadValueAsync);
        }
        // Send string to device
        private void writeButton_Click(object sender, RoutedEventArgs e)
        {
            // Send new text
            if (message == "")
            {
                return;
            }

            // Write the message on a separate thread
            Utilities.RunFuncAsTask(
                async() => await CharacteristicVM.CharacteristicM.WriteMessageAsync(message));
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Reset list choice
            if (_serviceListBox != null)
            {
                _serviceListBox.SelectedIndex = -1;
            }

            // These must be initialized before the UI loads
            DeviceVM.Initialize(GlobalSettings.SelectedDevice);
            ServicesVM.Initialize(GlobalSettings.SelectedDevice.ServiceModels);

            // Complete remaining initialization without blocking this callback
            Utilities.RunFuncAsTask(GlobalSettings.SelectedDevice.RegisterNotificationsAsync);
        }
        private void OnBackPressed(object sender, BackPressedEventArgs e)
        {
            if (this.Frame.CanGoBack)
            {
                CharacteristicVM.UnregisterVMFromModel();
                this.Frame.GoBack();
                e.Handled = true;

                if (CharacteristicVM.CharacteristicM.DictionaryModelChanged)
                {
                    // This is not critical and doesn't have to block execution, run on a separate thread
                    Utilities.RunFuncAsTask(GlobalSettings.CharacteristicDictionaryUnknown.SaveDictionaryAsync);
                }
            }
        }
Пример #8
0
        // Set up entry into page
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Reset list choice
            if (_characteristicListBox != null)
            {
                _characteristicListBox.SelectedIndex = -1;
            }

            // These must be initialized before the UI loads
            DeviceVM.Initialize(GlobalSettings.SelectedService.DeviceM);
            ServiceVM.Initialize(GlobalSettings.SelectedService);
            Characteristics.Initialize(ServiceVM.ServiceM.CharacteristicModels);

            // Read all characteristic values
            Utilities.RunFuncAsTask(GlobalSettings.SelectedService.ReadCharacteristicsAsync);
        }
Пример #9
0
        private void OnBackPressed(object sender, BackPressedEventArgs e)
        {
            if (this.Frame.CanGoBack)
            {
                Characteristics.Unregister();
                this.Frame.GoBack();
                e.Handled = true;

                if (ServiceVM.ServiceM.DictionaryModelChanged)
                {
                    // This is not critical and doesn't have to block execution
                    // Make sure this is done at the end of this function, as it returns
                    // once the first blocking call is encountered
                    Utilities.RunFuncAsTask(GlobalSettings.ServiceDictionaryUnknown.SaveDictionaryAsync);
                }
            }
        }
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            if (_firstLaunch)
            {
                // Initialize
                GlobalSettings.Initialize();

                // Initialize the dictionaries on a separate thread
                Utilities.RunFuncAsTask(GlobalSettings.InitializeDictionariesAsync);

                _firstLaunch = false;
            }

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                // TODO: change this value to a cache size that is appropriate for your application
                rootFrame.CacheSize = 1;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
#if WINDOWS_PHONE_APP
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    this._transitions = new TransitionCollection();
                    foreach (var c in rootFrame.ContentTransitions)
                    {
                        this._transitions.Add(c);
                    }
                }

                rootFrame.ContentTransitions = null;
                rootFrame.Navigated         += this.RootFrame_FirstNavigated;
#endif

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
 /// <summary>
 /// Invoked when application execution is being resumed.
 /// </summary>
 /// <param name="sender">The source of the suspend request.</param>
 /// <param name="e">Details about the suspend request.</param>
 private void OnResuming(object sender, object e)
 {
     // Re-register for device notifications, on a separate thread
     Utilities.RunFuncAsTask(GlobalSettings.RegisterAllNotificationsAsync);
 }
 private void toastButton_Click(object sender, RoutedEventArgs e)
 {
     // Handle the registration/unregistration of a toast on a separate thread
     Utilities.RunFuncAsTask(CharacteristicVM.CharacteristicM.ToastClickAsync);
 }
 private void deviceListRefreshButton_Click(object sender, RoutedEventArgs e)
 {
     Utilities.RunFuncAsTask(PopulateLEDeviceListAsync);
 }