-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiscToolsExample.cs
More file actions
45 lines (39 loc) · 1.69 KB
/
Copy pathMiscToolsExample.cs
File metadata and controls
45 lines (39 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Kwerty.DviZe.Linq;
using Kwerty.DviZe.Win.Wnf;
using Kwerty.DviZe.Win.Wnf.Misc;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace ExampleApp1;
public class MiscToolsExample(ILogger<MiscToolsExample> logger, IHostEnvironment env) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var csvPath = Path.Combine(env.ContentRootPath, "wnf.csv");
using var writer = new StreamWriter(csvPath);
writer.WriteLine("StateName,MaxStateSize,InternalName,InternalDescription,Version,Lifetime,Scope,IsDataPersistent");
var registrations = WnfStateRegistrationReader.GetAll(WnfLifetime.WellKnown);
var symbols = WnfStateSymbolDumper.GetAll();
foreach (var pair in registrations.PairWith(symbols, r => r.StateName, s => s.StateName))
{
if (!pair.IsFullPair)
{
continue;
}
var (registration, symbol) = (pair.Left, pair.Right);
var stateNameInfo = WnfStateNameInfo.Parse(registration.StateName);
writer.WriteLine(string.Join(',',
$"0x{registration.StateName:X}",
registration.MaxStateSize,
"\"" + symbol.InternalName.Replace("\"", "\"\"") + "\"",
"\"" + symbol.InternalDescription.Replace("\"", "\"\"") + "\"",
stateNameInfo.Version,
stateNameInfo.Lifetime,
stateNameInfo.Scope,
stateNameInfo.IsDataPersistent));
}
logger.LogInformation("Saved WNF state info to {CsvPath}", csvPath);
}
}