diff options
Diffstat (limited to 'TwoStepsAuthenticator.TestApp/ViewModel.cs')
-rw-r--r-- | TwoStepsAuthenticator.TestApp/ViewModel.cs | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/TwoStepsAuthenticator.TestApp/ViewModel.cs b/TwoStepsAuthenticator.TestApp/ViewModel.cs new file mode 100644 index 0000000..51db3a8 --- /dev/null +++ b/TwoStepsAuthenticator.TestApp/ViewModel.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; +using System.Windows.Threading; + +namespace TwoStepsAuthenticatorTestApp +{ + public class ViewModel : INotifyPropertyChanged + { + private string key; + public string Key + { + get + { + return key; + } + set + { + if (key != value) + { + key = value; + RaisePropertyChanged("Key"); + } + } + } + + private string code; + public string Code + { + get + { + return code; + } + set + { + if (code != value) + { + code = value; + RaisePropertyChanged("Code"); + GetCode(); + } + } + } + + private int count; + public int Count + { + get + { + return count; + } + set + { + if (count != value) + { + count = value; + if (count < 0) + { + count = 30; + GetCode(); + } + RaisePropertyChanged("Count"); + } + } + } + + DispatcherTimer timer; + + public ViewModel() + { + timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, timerCallback, App.Current.Dispatcher); + //timer.Elapsed += timer_Elapsed; + timer.Start(); + } + + private void timerCallback(object sender, EventArgs e) + { + Count--; + } + + + public event PropertyChangedEventHandler PropertyChanged; + private void RaisePropertyChanged(string propertyName) + { + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + + internal void GetCode() + { + var auth = new TwoStepsAuthenticator.Authenticator(); + Code = auth.GetCode(this.Key); + } + } +} |