91 lines
2.6 KiB
C#
91 lines
2.6 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using BlueWest.Tools;
|
|
using BlueWest.WebApi.EF;
|
|
|
|
namespace BlueWest.WebApi.Interfaces
|
|
{
|
|
/// <summary>
|
|
/// Empty constructor
|
|
/// </summary>
|
|
|
|
public struct ExchangeEvent { }
|
|
/// <summary>
|
|
/// Interface for getting and storing exchange rates data
|
|
/// </summary>
|
|
///
|
|
public sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable
|
|
{
|
|
private readonly EventManager _eventManager;
|
|
private readonly CountryDbContext _countryDbContext;
|
|
private readonly FinanceDbContext _financeDbContext;
|
|
private readonly UserDbContext _userDbContext;
|
|
|
|
#region Initialization
|
|
|
|
/// <summary>
|
|
/// Exchange Interface Object
|
|
/// </summary>
|
|
/// <param name="countryDbContext">Country context</param>
|
|
/// <param name="financeDbContext">Finance context</param>
|
|
/// <param name="userDbContext">User context</param>
|
|
/// <param name="eventManager">Event manager injection</param>
|
|
|
|
|
|
public ExchangeInterface(
|
|
CountryDbContext countryDbContext,
|
|
FinanceDbContext financeDbContext,
|
|
UserDbContext userDbContext,
|
|
EventManager eventManager)
|
|
{
|
|
_countryDbContext = countryDbContext;
|
|
_financeDbContext = financeDbContext;
|
|
_userDbContext = userDbContext;
|
|
_eventManager = eventManager;
|
|
Init();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Empty constructor
|
|
/// </summary>
|
|
public ExchangeInterface() { }
|
|
|
|
private void Init()
|
|
{
|
|
_eventManager.EventStartListening<ExchangeEvent>(this);
|
|
Console.WriteLine($"{nameof(ExchangeInterface)} Just started!");
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// On Exchange Event
|
|
/// </summary>
|
|
/// <param name="eventType"></param>
|
|
public void OnEvent(ExchangeEvent eventType)
|
|
{
|
|
Console.WriteLine($"Service received exchange {nameof(ExchangeEvent)}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stop Listening for events on dispose
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
_eventManager.EventStopListening<ExchangeEvent>(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stop Listening for events on dispose async
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
_eventManager.EventStopListening<ExchangeEvent>(this);
|
|
return ValueTask.CompletedTask;
|
|
|
|
}
|
|
}
|
|
}
|
|
|