48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
|
using System;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using FarmmapsApi.Models;
|
|||
|
using FarmmapsApi.Services;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
|
|||
|
namespace FarmmapsApiSamples
|
|||
|
{
|
|||
|
public class Application : IApp
|
|||
|
{
|
|||
|
private readonly ILogger<Application> _logger;
|
|||
|
private readonly FarmmapsApiService _farmmapsApiService;
|
|||
|
private readonly FarmmapsEventHub _farmmapsEventHub;
|
|||
|
private readonly NitrogenService _nitrogenService;
|
|||
|
|
|||
|
public Application(ILogger<Application> logger, FarmmapsApiService farmmapsApiService,
|
|||
|
FarmmapsEventHub farmmapsEventHub, NitrogenService nitrogenService)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
_farmmapsApiService = farmmapsApiService;
|
|||
|
_farmmapsEventHub = farmmapsEventHub;
|
|||
|
_nitrogenService = nitrogenService;
|
|||
|
|
|||
|
_farmmapsEventHub.EventCallback += OnEvent;
|
|||
|
}
|
|||
|
|
|||
|
private void OnEvent(EventMessage @event)
|
|||
|
{
|
|||
|
// _logger.LogInformation(@event.EventType);
|
|||
|
}
|
|||
|
|
|||
|
public async Task RunAsync()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
// !! this call is needed the first time an api is called with a fresh clientid and secret !!
|
|||
|
await _farmmapsApiService.GetCurrentUserCodeAsync();
|
|||
|
var roots = await _farmmapsApiService.GetCurrentUserRootsAsync();
|
|||
|
|
|||
|
await _nitrogenService.TestFlow(roots);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|