Created
August 15, 2018 18:52
-
-
Save ChrisMoney/6b63bc9ab08e7507e69a8279a39d37e3 to your computer and use it in GitHub Desktop.
Console App - Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Finlocker.TaxReturn.StatusHandler.Services; | |
using FinLocker.TaxReturn; | |
using FinLocker.TaxReturn.Api.Helpers.Interfaces; | |
using FinLocker.TaxReturn.Logging; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using System; | |
using System.IO; | |
using System.Threading.Tasks; | |
namespace Finlocker.TaxReturn.StatusHandler | |
{ | |
class Program | |
{ | |
private IServiceProvider dependencyContainer; | |
private IConfiguration configuration; | |
private ILogger<StatusService> logger; | |
private string batchId; | |
public Program() | |
{ | |
SetupConfiguration(); | |
SetupDependencies(); | |
GetBatchStatusFromQueue(); | |
} | |
static async Task Main(string[] args) | |
{ | |
var program = new Program(); | |
await program.Run(); | |
program.batchId = args[0]; | |
} | |
private string GetBatchStatusFromQueue() | |
{ | |
string batchStatus = string.Empty; | |
StatusService statusService = new StatusService(); | |
batchStatus = statusService.GetBatchStatusFromQueueAsync(batchId); | |
return batchStatus; | |
} | |
private void SetupConfiguration() | |
{ | |
var builder = new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json"); | |
configuration = builder.Build(); | |
} | |
private void SetupDependencies() | |
{ | |
dependencyContainer = new ServiceCollection() | |
.AddLogging() | |
.AddLog4NetDependencies(configuration) | |
.AddTaxReturnDependencies(configuration) | |
.BuildServiceProvider(); | |
dependencyContainer | |
.GetService<ILoggerFactory>() | |
.AddLog4Net(dependencyContainer); | |
} | |
public async Task Run() | |
{ | |
var logger = dependencyContainer | |
.GetService<ILoggerFactory>() | |
.CreateLogger<Program>(); | |
logger.LogInformation("Tax Return Status Handler Started."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment