using System.Diagnostics;
using System.Text.Json;
namespace XFEEDToolBox;
public partial class App
{
private static async Task RunMarketCacheCheckAsync(string path)
{
path=Path.GetFullPath(path);Directory.CreateDirectory(Path.GetDirectoryName(path)!);
object? result=null;string? failure=null;
try
{
if(!ViewModel.OfflinePreview||Runtime.Journal.Sequence!=0||Runtime.FlightDriver is not null)
throw new InvalidOperationException("Cache-only acceptance cannot start game or Journal sources.");
var before=Runtime.Markets.Statistics();
var sealedGeneration=await Runtime.Markets.FlushVerifiedGenerationAsync(completeFullValidation:false);
if(!sealedGeneration)throw new InvalidDataException("The completed validation did not leave a sealable generation; no replacement receipt was invented.");
var watch=Stopwatch.StartNew();await Task.Run(Runtime.Markets.Initialize);watch.Stop();
var after=Runtime.Markets.Statistics();
if(before!=after||watch.Elapsed>TimeSpan.FromSeconds(2))throw new InvalidDataException("The same validated generation did not reopen through the fast path.");
using var receipt=JsonDocument.Parse(await File.ReadAllTextAsync(Runtime.Markets.DatabasePath+".verified-generation.json"));
result=new{passed=true,Runtime.DataDirectory,database=Runtime.Markets.DatabasePath,
before=new{before.Stations,before.Quotes,before.Latest},after=new{after.Stations,after.Quotes,after.Latest},sealedGeneration,
secondInitializeMilliseconds=watch.Elapsed.TotalMilliseconds,receipt=receipt.RootElement.Clone(),
journalEvents=Runtime.Journal.Sequence,gameConnected=false,gameCommandsInvoked=false,marketWritesSubmitted=false};
}
catch(Exception error){failure=error.ToString();}
await File.WriteAllTextAsync(path,JsonSerializer.Serialize(new{pid=Environment.ProcessId,result,failure},new JsonSerializerOptions{WriteIndented=true}));
MainWindow.Close();
}
}
using System.Diagnostics;
using System.Text.Json;
namespace XFEEDToolBox;
public partial class App
{
private static async Task RunMarketCacheCheckAsync(string path)
{
path=Path.GetFullPath(path);Directory.CreateDirectory(Path.GetDirectoryName(path)!);
object? result=null;string? failure=null;
try
{
if(!ViewModel.OfflinePreview||Runtime.Journal.Sequence!=0||Runtime.FlightDriver is not null)
throw new InvalidOperationException("Cache-only acceptance cannot start game or Journal sources.");
var before=Runtime.Markets.Statistics();
var sealedGeneration=await Runtime.Markets.FlushVerifiedGenerationAsync(completeFullValidation:false);
if(!sealedGeneration)throw new InvalidDataException("The completed validation did not leave a sealable generation; no replacement receipt was invented.");
var watch=Stopwatch.StartNew();await Task.Run(Runtime.Markets.Initialize);watch.Stop();
var after=Runtime.Markets.Statistics();
if(before!=after||watch.Elapsed>TimeSpan.FromSeconds(2))throw new InvalidDataException("The same validated generation did not reopen through the fast path.");
using var receipt=JsonDocument.Parse(await File.ReadAllTextAsync(Runtime.Markets.DatabasePath+".verified-generation.json"));
result=new{passed=true,Runtime.DataDirectory,database=Runtime.Markets.DatabasePath,
before=new{before.Stations,before.Quotes,before.Latest},after=new{after.Stations,after.Quotes,after.Latest},sealedGeneration,
secondInitializeMilliseconds=watch.Elapsed.TotalMilliseconds,receipt=receipt.RootElement.Clone(),
journalEvents=Runtime.Journal.Sequence,gameConnected=false,gameCommandsInvoked=false,marketWritesSubmitted=false};
}
catch(Exception error){failure=error.ToString();}
await File.WriteAllTextAsync(path,JsonSerializer.Serialize(new{pid=Environment.ProcessId,result,failure},new JsonSerializerOptions{WriteIndented=true}));
MainWindow.Close();
}
}