|
| 1 | +using Helldivers.Core.Contracts.Collections; |
| 2 | +using Helldivers.Core.Extensions; |
| 3 | +using Helldivers.Models.Domain.Localization; |
| 4 | +using Helldivers.Models.V1; |
| 5 | +using Helldivers.Models.V2; |
| 6 | +using Helldivers.Sync.Configuration; |
| 7 | +using Helldivers.Sync.Extensions; |
| 8 | +using Helldivers.Sync.Hosted; |
| 9 | +using Microsoft.Extensions.DependencyInjection; |
| 10 | +using Microsoft.Extensions.Hosting; |
| 11 | +using Microsoft.Extensions.Logging; |
| 12 | +using System.Diagnostics; |
| 13 | +using System.Globalization; |
| 14 | +using System.Text.Json; |
| 15 | +using Dispatch = Helldivers.Models.V1.Dispatch; |
| 16 | + |
| 17 | +var maxRuntime = new CancellationTokenSource(TimeSpan.FromSeconds(30)); |
| 18 | +var builder = new HostApplicationBuilder(args); |
| 19 | + |
| 20 | +LocalizedMessage.FallbackCulture = new CultureInfo("en-US"); |
| 21 | +builder.Services.AddHelldivers(); |
| 22 | +builder.Services.AddHelldiversSync(); |
| 23 | +builder.Services.Configure<HelldiversSyncConfiguration>(configuration => |
| 24 | +{ |
| 25 | + configuration.RunOnce = true; |
| 26 | + // Add all languages we want to CI test here. |
| 27 | + configuration.Languages = |
| 28 | + [ |
| 29 | + "en-US", |
| 30 | + "de-DE", |
| 31 | + "es-ES", |
| 32 | + "ru-RU", |
| 33 | + "fr-FR", |
| 34 | + "it-IT", |
| 35 | + "pl-PL", |
| 36 | + "zh-Hans", |
| 37 | + "zh-Hant" |
| 38 | + ]; |
| 39 | +}); |
| 40 | + |
| 41 | +var stopwatch = new Stopwatch(); |
| 42 | +var app = builder.Build(); |
| 43 | + |
| 44 | +// Run our host, but make it shutdown after *max* 30 seconds. |
| 45 | +stopwatch.Start(); |
| 46 | +var arrowhead = app.Services.GetRequiredService<ArrowHeadSyncService>(); |
| 47 | +var steam = app.Services.GetRequiredService<SteamSyncService>(); |
| 48 | +await arrowhead.StartAsync(maxRuntime.Token); |
| 49 | +await steam.StartAsync(maxRuntime.Token); |
| 50 | + |
| 51 | +// now we await completion of both. |
| 52 | +await Task.WhenAll([ |
| 53 | + arrowhead.ExecuteTask!, |
| 54 | + steam.ExecuteTask!, |
| 55 | +]).WaitAsync(maxRuntime.Token); |
| 56 | +stopwatch.Stop(); |
| 57 | + |
| 58 | +app.Services.GetRequiredService<ILogger<Program>>().LogInformation("Sync succeeded in {}", stopwatch.Elapsed); |
| 59 | + |
| 60 | +// Fetch all information from the stores to write to disk. |
| 61 | +var assignments = await app.Services.GetRequiredService<IStore<Assignment, long>>().AllAsync(maxRuntime.Token); |
| 62 | +var campaigns = await app.Services.GetRequiredService<IStore<Campaign, int>>().AllAsync(maxRuntime.Token); |
| 63 | +var dispatchesv1 = await app.Services.GetRequiredService<IStore<Dispatch, int>>().AllAsync(maxRuntime.Token); |
| 64 | +var planets = await app.Services.GetRequiredService<IStore<Planet, int>>().AllAsync(maxRuntime.Token); |
| 65 | +var war = await app.Services.GetRequiredService<Helldivers.Core.Contracts.IStore<War>>().Get(maxRuntime.Token); |
| 66 | +var dispatchesv2 = await app.Services.GetRequiredService<IStore<Helldivers.Models.V2.Dispatch, int>>().AllAsync(maxRuntime.Token); |
| 67 | +var store = await app.Services.GetRequiredService<IStore<SpaceStation, long>>().AllAsync(maxRuntime.Token); |
| 68 | + |
| 69 | +Directory.CreateDirectory("v1"); |
| 70 | +Directory.CreateDirectory("v2"); |
| 71 | + |
| 72 | +var options = new JsonSerializerOptions { WriteIndented = true }; |
| 73 | +await File.WriteAllBytesAsync("v1/assignments.json", JsonSerializer.SerializeToUtf8Bytes(assignments, options), maxRuntime.Token); |
| 74 | +await File.WriteAllBytesAsync("v1/campaigns.json", JsonSerializer.SerializeToUtf8Bytes(campaigns, options), maxRuntime.Token); |
| 75 | +await File.WriteAllBytesAsync("v1/dispatches.json", JsonSerializer.SerializeToUtf8Bytes(dispatchesv1, options), maxRuntime.Token); |
| 76 | +await File.WriteAllBytesAsync("v1/planets.json", JsonSerializer.SerializeToUtf8Bytes(planets, options), maxRuntime.Token); |
| 77 | +await File.WriteAllBytesAsync("v1/war.json", JsonSerializer.SerializeToUtf8Bytes(war, options), maxRuntime.Token); |
| 78 | +await File.WriteAllBytesAsync("v2/dispatches.json", JsonSerializer.SerializeToUtf8Bytes(dispatchesv2, options), maxRuntime.Token); |
| 79 | +await File.WriteAllBytesAsync("v2/space-stations.json", JsonSerializer.SerializeToUtf8Bytes(store, options), maxRuntime.Token); |
| 80 | + |
| 81 | +return 0; |
0 commit comments