Exemple #1
0
 public Task Disconnect()
 {
     if (Guider != null)
     {
         Guider.PropertyChanged -= Guider_PropertyChanged;
         Guider.GuideEvent      -= Guider_GuideEvent;
     }
     Guider?.Disconnect();
     GuiderInfo = DeviceInfo.CreateDefaultInstance <GuiderInfo>();
     BroadcastGuiderInfo();
     return(Task.CompletedTask);
 }
Exemple #2
0
        public async Task <bool> Connect()
        {
            ResetGraphValues();

            bool connected = false;

            try {
                if (Guider != null)
                {
                    Guider.PropertyChanged -= Guider_PropertyChanged;
                    Guider.GuideEvent      -= Guider_GuideEvent;
                }
                _cancelConnectGuiderSource?.Dispose();
                _cancelConnectGuiderSource = new CancellationTokenSource();
                Guider = GuiderChooserVM.SelectedGuider;
                Guider.PropertyChanged += Guider_PropertyChanged;
                connected = await Guider.Connect();

                _cancelConnectGuiderSource.Token.ThrowIfCancellationRequested();

                if (connected)
                {
                    Guider.GuideEvent += Guider_GuideEvent;

                    GuiderInfo = new GuiderInfo {
                        Connected = connected
                    };
                    BroadcastGuiderInfo();
                    Notification.ShowSuccess(Locale.Loc.Instance["LblGuiderConnected"]);
                    RaisePropertyChanged(nameof(Guider));
                    profileService.ActiveProfile.GuiderSettings.GuiderName = Guider.Name;
                }
            } catch (OperationCanceledException) {
                Guider.PropertyChanged -= Guider_PropertyChanged;
                Guider?.Disconnect();
                GuiderInfo = new GuiderInfo {
                    Connected = false
                };
                BroadcastGuiderInfo();
            }

            return(connected);
        }