-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Ali-YousefiTelori/develop
Refactor, Use Serilog
- Loading branch information
Showing
15 changed files
with
217 additions
and
144 deletions.
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
Empty file.
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
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
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
55 changes: 55 additions & 0 deletions
55
...IdentityMicroservice.Logics/BackgroundServices/InternalTokenGeneratorBackgroundService.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,55 @@ | ||
using EasyMicroservices.IdentityMicroservice.Helpers; | ||
using EasyMicroservices.IdentityMicroservice.Interfaces; | ||
using EasyMicroservices.Logger.Interfaces; | ||
using Microsoft.Extensions.Hosting; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.IdentityMicroservice.BackgroundServices; | ||
public class InternalTokenGeneratorBackgroundService : IHostedService, IDisposable | ||
{ | ||
private Timer _timer = null; | ||
readonly IAppUnitOfWork _unitOfWork; | ||
public InternalTokenGeneratorBackgroundService(IAppUnitOfWork unitOfWork) | ||
{ | ||
_unitOfWork = unitOfWork; | ||
} | ||
|
||
public Task StartAsync(CancellationToken stoppingToken) | ||
{ | ||
_timer = new Timer(DoWork, null, TimeSpan.Zero, | ||
TimeSpan.FromHours(1)); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private void DoWork(object state) | ||
{ | ||
_ = Task.Run(async () => | ||
{ | ||
var logger = _unitOfWork.GetLogger(); | ||
try | ||
{ | ||
logger.Debug("Try login..."); | ||
AppUnitOfWork.Token = await _unitOfWork.GetIdentityHelper().GetFullAccessPersonalAccessToken(); | ||
logger.Debug($"Login success {AppUnitOfWork.Token}"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.Error(ex); | ||
} | ||
}); | ||
} | ||
|
||
public Task StopAsync(CancellationToken stoppingToken) | ||
{ | ||
_timer?.Change(Timeout.Infinite, 0); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_timer?.Dispose(); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.