diff --git a/.gitignore b/.gitignore index 52b386e71..c217e628d 100644 --- a/.gitignore +++ b/.gitignore @@ -326,4 +326,5 @@ ASALocalRun/ gs/Private.gs appsettings.development.json appsettings.production.json +src/FilterLists.Agent/appsettings.json src/FilterLists.Web/wwwroot/dist \ No newline at end of file diff --git a/src/FilterLists.Agent/FilterLists.Agent.csproj b/src/FilterLists.Agent/FilterLists.Agent.csproj index ce1697ae8..3d808c6b8 100644 --- a/src/FilterLists.Agent/FilterLists.Agent.csproj +++ b/src/FilterLists.Agent/FilterLists.Agent.csproj @@ -5,4 +5,17 @@ netcoreapp2.0 + + + + + + + + + + + + + diff --git a/src/FilterLists.Agent/Program.cs b/src/FilterLists.Agent/Program.cs index 6bb9de8e8..ced8b3da6 100644 --- a/src/FilterLists.Agent/Program.cs +++ b/src/FilterLists.Agent/Program.cs @@ -1,14 +1,72 @@ using System; +using System.IO; +using FilterLists.Services.DependencyInjection.Extensions; +using FilterLists.Services.SnapshotService; +using Microsoft.ApplicationInsights; +using Microsoft.ApplicationInsights.Extensibility; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace FilterLists.Agent { public class Program { + private static TelemetryClient telemetryClient; + private static ServiceProvider serviceProvider; + private static IConfigurationRoot configurationRoot; + public static void Main(string[] args) { - Console.WriteLine("Hello World!"); - Console.Write("\nPress any key to exit..."); - Console.ReadKey(true); + InstantiateConfigurationRoot(); + InstantiateTelemetryClient(); + InstantiateServiceProvider(); + + //TODO: capture batchSize from args + const int batchSize = 1; + CaptureSnapshots(batchSize); + } + + private static void InstantiateConfigurationRoot() + { + configurationRoot = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", false, true) + .Build(); + } + + private static void InstantiateTelemetryClient() + { + TelemetryConfiguration.Active.InstrumentationKey = + configurationRoot["ApplicationInsights:InstrumentationKey"]; + telemetryClient = new TelemetryClient(); + } + + private static void InstantiateServiceProvider() + { + var serviceCollection = new ServiceCollection(); + ConfigureServices(serviceCollection); + serviceProvider = serviceCollection.BuildServiceProvider(); + } + + private static void ConfigureServices(IServiceCollection serviceCollection) + { + serviceCollection.AddFilterListsServices(configurationRoot); + } + + private static void CaptureSnapshots(int batchSize) + { + var snapshotService = serviceProvider.GetService(); + + Log("Capturing FilterList snapshots..."); + snapshotService.CaptureSnapshotsAsync(batchSize).Wait(); + Log("\nSnapshots captured."); + telemetryClient.Flush(); + } + + private static void Log(string message) + { + Console.WriteLine(message); + telemetryClient.TrackTrace(message); } } } \ No newline at end of file