diff --git a/OTPFactory-overview.md b/OTPFactory-overview.md new file mode 100644 index 0000000..3495ea8 --- /dev/null +++ b/OTPFactory-overview.md @@ -0,0 +1,61 @@ +In case you are working on an authenticator app, you can use `OTPFactory` to handle code re-generation and timer updates +## Configure factory +To configure factory just simply pass an `OTPConfiguration` object to constructor: +```csharp +OTPFactory factory = new (config); +``` +You can update configuration any time by updating `Configuration` property + +## Subscribe to events +To keep code up to date on the UI side, subscribe to `CodeUpdated` event: +```csharp +factory.CodeUpdated += (newCode) => +{ + // Update your data here + this.codeLabel.Text = newCode.GetCode(); +}; +``` +Also it could be useful to subscribe to `PropertyChanged` event, since it occurs every second to keep code countdown up to date (countdown update frequency is set on instance constructor by parameter `timeUpdateInterval` in milliseconds) +```csharp +OTPFactory factory = new (config); // use 'new (config, 100)' to update countdown every 100 milliseconds +factory.PropertyChanged += (s, e) => +{ + if (e.PropertyName == nameof(factory.TimeLeft)) + this.countdownLabel.Text = factory.TimeLeft.ToString(); +}; +``` + +## Use MVVM pattern with OTPFactory +`OTPFactory` object is MVVM ready, so you can use it as is in your ViewModel +```csharp +public class MyViewModel : ViewModelBase +{ + private OTPFactory _factory = new (OTPConfiguration.GenerateConfiguration("FoxDev Studio", "eugene@xfox111.net")); // Example value + public OTPFactory Factory + { + get => _factory; + set => SetProperty(ref _factory, value); + } +} +``` +```xaml + + + + + + + + + ... + +``` + +## Dispose OTPFactory +When you don't need `OTPFactory` anymore it is important to dispose it to prevent memory leaks. To do so just simply call `OTPFactory.Dispose()` or use it with `using keyword` \ No newline at end of file