2020-04-06 09:51:42 +00:00
|
|
|
|
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;
|
2020-04-06 11:37:11 +00:00
|
|
|
|
private readonly HerbicideService _herbicideService;
|
2020-04-06 09:51:42 +00:00
|
|
|
|
|
|
|
|
|
public Application(ILogger<Application> logger, FarmmapsApiService farmmapsApiService,
|
2020-04-06 11:37:11 +00:00
|
|
|
|
FarmmapsEventHub farmmapsEventHub, NitrogenService nitrogenService,
|
|
|
|
|
HerbicideService herbicideService)
|
2020-04-06 09:51:42 +00:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_farmmapsApiService = farmmapsApiService;
|
|
|
|
|
_farmmapsEventHub = farmmapsEventHub;
|
|
|
|
|
_nitrogenService = nitrogenService;
|
2020-04-06 11:37:11 +00:00
|
|
|
|
_herbicideService = herbicideService;
|
2020-04-06 09:51:42 +00:00
|
|
|
|
|
|
|
|
|
_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();
|
|
|
|
|
|
2020-04-06 11:37:11 +00:00
|
|
|
|
// await _nitrogenService.TestFlow(roots);
|
|
|
|
|
await _herbicideService.TestFlow(roots);
|
2020-04-06 09:51:42 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|