示例#1
0
        private async void PebbleAssociate(IUICommand command)
        {
            Log.Add("Associating " + PebbleDeviceName.Name);

            try
            {
                PebbleConnector _pc = PebbleConnector.GetInstance();
                if (await _pc.AssociatePebble(PebbleDeviceName))
                {
                    Log.Add("Success");

                    var successDialog = new Windows.UI.Popups.MessageDialog(String.Format("Association {0} completed successfully.", PebbleDeviceName.Name));
                    successDialog.Commands.Add(new UICommand("Ok"));

                    await successDialog.ShowAsync();
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception exp)
            {
                if (exp.Message.Length > 0)
                {
                    Log.Add(String.Format("An error occurred while associating {0}: {1}", PebbleDeviceName, exp.Message));
                }
                else
                {
                    Log.Add("Failed");
                }

                var messageDialog = new Windows.UI.Popups.MessageDialog(String.Format("Association {0} failed.", PebbleDeviceName.Name));
                messageDialog.Commands.Add(new UICommand("Ok"));

                await messageDialog.ShowAsync();
            }
            finally
            {
                NotifyPropertyChanged("IsDeviceAssociated");
                NotifyPropertyChanged("AssociatedDeviceFirmware");
                NotifyPropertyChanged("AssociatedDeviceName");
                NotifyPropertyChanged("AssociatedDeviceBoard");
                NotifyPropertyChanged("AssociatedDeviceId");
            }
        }