95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using BlueWest.Domain;
|
|
using BlueWest.Domain;
|
|
using BlueWest.Tools;
|
|
using BlueWest.WebApi.Context;
|
|
|
|
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 ApplicationUserDbContext _applicationUserDbContext;
|
|
private readonly EventManager _eventManager;
|
|
private readonly CountryDbContext _countryDbContext;
|
|
private readonly FinanceDbContext _financeDbContext;
|
|
private readonly UserDbContext _userDbContext;
|
|
|
|
#region Initialization
|
|
|
|
/// <summary>
|
|
/// Database Ef context constructor
|
|
/// </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(
|
|
ApplicationUserDbContext applicationUserDbContext,
|
|
CountryDbContext countryDbContext,
|
|
FinanceDbContext financeDbContext,
|
|
UserDbContext userDbContext,
|
|
EventManager eventManager)
|
|
{
|
|
_applicationUserDbContext = applicationUserDbContext;
|
|
_countryDbContext = countryDbContext;
|
|
_financeDbContext = financeDbContext;
|
|
_userDbContext = userDbContext;
|
|
_eventManager = eventManager;
|
|
Init();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Database Ef context 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;
|
|
|
|
}
|
|
}
|
|
}
|
|
|