2022-08-19 19:47:35 +03:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BlueWest.Tools;
|
|
|
|
using BlueWest.WebApi.MySQL;
|
|
|
|
|
|
|
|
namespace BlueWest.WebApi.Interfaces
|
|
|
|
{
|
|
|
|
public struct ExchangeEvent { }
|
2022-08-20 05:47:32 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Interface for getting and storing exchange rates data
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
public sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable
|
2022-08-19 19:47:35 +03:00
|
|
|
{
|
|
|
|
private readonly EventManager _eventManager;
|
|
|
|
private readonly CountryDbContext _countryDbContext;
|
|
|
|
private readonly FinanceDbContext _financeDbContext;
|
|
|
|
private readonly UserDbContext _userDbContext;
|
2022-08-20 05:47:32 +03:00
|
|
|
|
|
|
|
#region Initialization
|
2022-08-19 19:47:35 +03:00
|
|
|
public ExchangeInterface(
|
|
|
|
CountryDbContext countryDbContext,
|
|
|
|
FinanceDbContext financeDbContext,
|
|
|
|
UserDbContext userDbContext,
|
|
|
|
EventManager eventManager)
|
|
|
|
{
|
|
|
|
_countryDbContext = countryDbContext;
|
|
|
|
_financeDbContext = financeDbContext;
|
|
|
|
_userDbContext = userDbContext;
|
|
|
|
_eventManager = eventManager;
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ExchangeInterface() { }
|
|
|
|
|
|
|
|
private void Init()
|
|
|
|
{
|
|
|
|
_eventManager.EventStartListening<ExchangeEvent>(this);
|
|
|
|
Console.WriteLine($"{nameof(ExchangeInterface)} Just started!");
|
|
|
|
}
|
2022-08-20 05:47:32 +03:00
|
|
|
|
|
|
|
#endregion
|
2022-08-19 19:47:35 +03:00
|
|
|
|
2022-08-20 05:47:32 +03:00
|
|
|
/// <summary>
|
|
|
|
/// On Exchange Event
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="eventType"></param>
|
2022-08-19 19:47:35 +03:00
|
|
|
public void OnEvent(ExchangeEvent eventType)
|
|
|
|
{
|
|
|
|
Console.WriteLine($"Service received exchange {nameof(ExchangeEvent)}");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Stop Listening for events
|
|
|
|
/// </summary>
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
_eventManager.EventStopListening<ExchangeEvent>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ValueTask DisposeAsync()
|
|
|
|
{
|
|
|
|
_eventManager.EventStopListening<ExchangeEvent>(this);
|
|
|
|
return ValueTask.CompletedTask;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|