/// <summary> /// Initializes a new instance of the <see cref="MainViewModel"/> class /// </summary> /// <param name="navigation"> /// Navigation instance /// </param> public MainViewModel(INavigation navigation) { Navigation = navigation; PlayCommand = new Command(async() => { _isPlaying = true; _cts = new CancellationTokenSource(); _audioStreamPolicy = new AudioStreamPolicy(AudioStreamType.Media); PlayCommand.ChangeCanExecute(); CancelCommand.ChangeCanExecute(); try { await TonePlayer.StartAsync(ToneType.Default, _audioStreamPolicy, Duration * _secUnit, _cts.Token); } catch (TaskCanceledException) { Tizen.Log.Info("TonePlayer", "A task for playing media was canceled."); } finally { _isPlaying = false; _cts?.Dispose(); _audioStreamPolicy?.Dispose(); } PlayCommand.ChangeCanExecute(); CancelCommand.ChangeCanExecute(); }, CanPlay); CancelCommand = new Command(() => { if (_isPlaying) { _cts?.Cancel(); _isPlaying = false; } PlayCommand.ChangeCanExecute(); CancelCommand.ChangeCanExecute(); }, CanCancel); }
/// <summary> /// Determines whether this instance cancel login. /// </summary> /// <returns><c>true</c> if this instance cancel login; otherwise, <c>false</c>.</returns> private void CancelLogin() { if (IsBusy) { return; } Page.EndEditing(); IsBusy = true; CancelCommand.ChangeCanExecute(); try { LoginPassword = string.Empty; SelectedUserId = 0; } catch (Exception ex) { Debug.WriteLine("Error On logout. Exception: {0}", ex); } finally { IsBusy = false; CancelCommand.ChangeCanExecute(); } }