示例#1
0
        /// <summary>
        /// Tries to establish a connection to the wordclock
        /// </summary>
        /// <returns></returns>
        async Task ConnectToWordclock()
        {
            bool isInputValid = await ValidateUserInput();

            if (isInputValid)
            {
                IsBusy = true;
                Connect.ChangeCanExecute();

                var isConnectionEstablished = false;

                try
                {
                    EndpointConfigurationFactory.Initialize(_server, _port);
                    isConnectionEstablished = await Task.Run(() => _connectionService.IsConnectionEstablished());
                }
                catch (Exception ex)
                {
                    await _dialogService.ShowError(ex);
                }
                finally
                {
                    IsBusy = false;
                    Connect.ChangeCanExecute();
                }

                if (isConnectionEstablished)
                {
                    SaveConnectionInformation();

                    //Use absolute Uri to reset the navigation stack. So it is not possible to navigate to the ConnectPage anymore
                    await _navigationService.NavigateAsync(new Uri("/MenuPage", UriKind.Absolute));
                }
            }
        }
 public MainViewModel()
 {
     App.Connection.PropertyChanged += (sender, args) => Device.BeginInvokeOnMainThread(() =>
     {
         Connect.ChangeCanExecute();
         Disconnect.ChangeCanExecute();
         Debug.WriteLine(App.Connection.State);
     });
 }