mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
Agent now captures snapshots
This commit is contained in:
parent
9011f358ec
commit
4aa5fd1500
3 changed files with 75 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -326,4 +326,5 @@ ASALocalRun/
|
|||
gs/Private.gs
|
||||
appsettings.development.json
|
||||
appsettings.production.json
|
||||
src/FilterLists.Agent/appsettings.json
|
||||
src/FilterLists.Web/wwwroot/dist
|
||||
|
|
@ -5,4 +5,17 @@
|
|||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.1.2-alpha" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FilterLists.Services\FilterLists.Services.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -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<SnapshotService>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue