-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Needs proper merging into the ecosystem
- Loading branch information
1 parent
37402fd
commit 783a991
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
OpenLyricsClient/Backend/Handler/License/LicenseHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using DevBase.Api.Apis.OpenLyricsClient.Structure.Enum; | ||
using DevBase.Api.Apis.OpenLyricsClient.Structure.Json; | ||
using DevBase.Async.Task; | ||
using OpenLyricsClient.Backend.Structure.Enum; | ||
|
||
namespace OpenLyricsClient.Backend.Handler.License; | ||
|
||
public class LicenseHandler : IHandler | ||
{ | ||
private TaskSuspensionToken _refreshSuspensionToken; | ||
|
||
private bool _disposed; | ||
|
||
private JsonOpenLyricsClientSubscriptionModel _license; | ||
private DevBase.Api.Apis.OpenLyricsClient.OpenLyricsClient _openLyricsClientApi; | ||
|
||
public LicenseHandler() | ||
{ | ||
this._disposed = false; | ||
|
||
this._openLyricsClientApi = new DevBase.Api.Apis.OpenLyricsClient.OpenLyricsClient(Core.INSTANCE.Sealing.ServerPublicKey); | ||
|
||
JsonOpenLyricsClientSubscriptionModel model = new JsonOpenLyricsClientSubscriptionModel | ||
{ | ||
Model = EnumSubscriptions.OPENLYRICSCLIENT_STANDARD | ||
}; | ||
this._license = model; | ||
|
||
Core.INSTANCE.TaskRegister.Register( | ||
out _refreshSuspensionToken, | ||
new Task(async () => await RefreshLicense(), Core.INSTANCE.CancellationTokenSource.Token, TaskCreationOptions.LongRunning), | ||
EnumRegisterTypes.REFRESH_LICENSE); | ||
} | ||
|
||
public async Task RefreshLicense() | ||
{ | ||
while (!this._disposed) | ||
{ | ||
string userID = Core.INSTANCE.SettingsHandler.Settings<AccountSection>()!.GetValue<string>("UserID"); | ||
string userSecret = Core.INSTANCE.SettingsHandler.Settings<AccountSection>()!.GetValue<string>("UserSecret"); | ||
|
||
JsonOpenLyricsClientSubscription subscription = new JsonOpenLyricsClientSubscription | ||
{ | ||
UserID = userID, | ||
UserSecret = userSecret | ||
}; | ||
|
||
JsonOpenLyricsClientSubscriptionModel model = await this._openLyricsClientApi.CheckSubscription(subscription); | ||
this._license = model; | ||
|
||
await Task.Delay((int)TimeSpan.FromMinutes(1).TotalMilliseconds); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
this._disposed = true; | ||
Core.INSTANCE.TaskRegister.Kill(EnumRegisterTypes.REFRESH_LICENSE); | ||
} | ||
|
||
public JsonOpenLyricsClientSubscriptionModel License | ||
{ | ||
get => _license; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters