69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using AAIntegration.SimmonsBank.API.Configs;
|
|
using AAIntegration.SimmonsBank.API.Entities;
|
|
using AAIntegration.SimmonsBank.API.Models.Transactions;
|
|
using AAIntegration.SimmonsBank.API.Services;
|
|
using Internal;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.Options;
|
|
using PuppeteerSharp;
|
|
using OtpNet;
|
|
using System.Text;
|
|
|
|
namespace AAIntegration.SimmonsBank.API.Processes;
|
|
|
|
public class PuppeteerProcess : IPuppeteerProcess
|
|
{
|
|
private readonly PuppeteerConfig _config;
|
|
private readonly ILogger<PuppeteerProcess> _logger;
|
|
private readonly IMemoryCache _memoryCache;
|
|
private const string DASHBOARD_SELECTOR = "body > banno-web > bannoweb-layout > bannoweb-dashboard";
|
|
private CancellationToken _stoppingToken;
|
|
private IPuppeteerService _puppeteerService;
|
|
|
|
public PuppeteerProcess(
|
|
IOptions<PuppeteerConfig> config,
|
|
ILogger<PuppeteerProcess> logger,
|
|
IMemoryCache memoryCache)
|
|
{
|
|
_config = config.Value;
|
|
_logger = logger;
|
|
_memoryCache = memoryCache;
|
|
_stoppingToken = new CancellationToken();
|
|
}
|
|
|
|
public void SetService(IPuppeteerService puppeteerService)
|
|
{
|
|
_puppeteerService = puppeteerService;
|
|
}
|
|
|
|
public void SetStoppingToken(CancellationToken stoppingToken)
|
|
{
|
|
_stoppingToken = stoppingToken;
|
|
}
|
|
|
|
public async Task StayLoggedIn(User user)
|
|
{
|
|
_logger.LogInformation($"... doing work and processing for user {user.Id} ...");
|
|
|
|
if (!await _puppeteerService.IsLoggedIn(user, _stoppingToken))
|
|
{
|
|
_logger.LogInformation("User determined to not be logged in");
|
|
await _puppeteerService.Login(user, _stoppingToken);
|
|
}
|
|
else
|
|
{
|
|
_logger.LogInformation("User is already logged in");
|
|
}
|
|
}
|
|
|
|
// Helper Functions
|
|
|
|
private async Task Delay(int milliseconds)
|
|
{
|
|
await Task.Delay(TimeSpan.FromMilliseconds(milliseconds), _stoppingToken);
|
|
}
|
|
}
|