mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2026-04-06 15:04:34 +00:00
Add applies-to docfx overwrites generator.
This commit is contained in:
parent
7a4e264af3
commit
b87e4c18f5
23 changed files with 8692 additions and 0 deletions
8
docs/AppliesToGenerator/DocFXAppliesToGenerator.csproj
Normal file
8
docs/AppliesToGenerator/DocFXAppliesToGenerator.csproj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
130
docs/AppliesToGenerator/Program.cs
Normal file
130
docs/AppliesToGenerator/Program.cs
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Json;
|
||||
|
||||
namespace DocFXAppliesToGenerator
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
Console.Write("Missing api list input");
|
||||
return 1;
|
||||
}
|
||||
var output = args[0];
|
||||
var fi = new FileInfo(output);
|
||||
if(!fi.Exists)
|
||||
{
|
||||
Console.Write("File not found: " + output);
|
||||
return 2;
|
||||
}
|
||||
|
||||
var settings = new DataContractJsonSerializerSettings();
|
||||
settings.UseSimpleDictionaryFormat = true;
|
||||
var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(AppliesToDataModel), settings);
|
||||
var list = (AppliesToDataModel)serializer.ReadObject(File.OpenRead(fi.FullName));
|
||||
|
||||
var result = BuildApiList(list, fi.Directory.FullName);
|
||||
var outfile = new FileInfo(Path.Combine(fi.Directory.FullName, list.Output));
|
||||
if (!outfile.Directory.Exists) outfile.Directory.Create();
|
||||
using (StreamWriter sw = new StreamWriter(outfile.FullName))
|
||||
{
|
||||
foreach (var item in result.Values)
|
||||
{
|
||||
sw.WriteLine("---");
|
||||
sw.WriteLine($"uid: {item.Id}");
|
||||
sw.WriteLine($"appliesTo:");
|
||||
foreach(var p in item.AppliesTo.GroupBy(p=>p.Platform))
|
||||
{
|
||||
sw.WriteLine($" - platform: {p.Key}");
|
||||
if (p.Where(t => !string.IsNullOrEmpty(t.Version)).Any())
|
||||
sw.WriteLine($" versions: {string.Join(", ", p.Select(t => t.Version))}");
|
||||
}
|
||||
sw.WriteLine("---");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static Dictionary<string, Api> BuildApiList(AppliesToDataModel manifestFolder, string rootFolder)
|
||||
{
|
||||
Dictionary<string, Api> apilist = new Dictionary<string, Api>();
|
||||
|
||||
foreach(var platform in manifestFolder.Metadata)
|
||||
{
|
||||
foreach (var manifest in platform.Versions)
|
||||
{
|
||||
var file = Path.Combine(rootFolder, manifest.Manifest);
|
||||
if (File.Exists(file))
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(file))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var line = sr.ReadLine()?.Trim();
|
||||
if (line == null)
|
||||
break;
|
||||
|
||||
if (line.StartsWith('"'))
|
||||
{
|
||||
var name = line.Substring(1, line.IndexOf("\":") - 1);
|
||||
if (!apilist.ContainsKey(name))
|
||||
apilist[name] = new Api() { Id = name };
|
||||
apilist[name].AppliesTo.Add(new AppliesTo() { Platform = platform.PlatformName, Version = manifest.Name });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Manifest file not found: " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
return apilist;
|
||||
}
|
||||
|
||||
public class Api
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public List<AppliesTo> AppliesTo { get; } = new List<AppliesTo>();
|
||||
}
|
||||
public class AppliesTo
|
||||
{
|
||||
public string Version { get; set; }
|
||||
public string Platform { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class AppliesToDataModel
|
||||
{
|
||||
[DataMember]
|
||||
public string Output { get; set; }
|
||||
[DataMember]
|
||||
public Metadata[] Metadata { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Metadata
|
||||
{
|
||||
[DataMember]
|
||||
public string PlatformName { get; set; }
|
||||
[DataMember]
|
||||
public ManifestVersion[] Versions { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class ManifestVersion
|
||||
{
|
||||
[DataMember]
|
||||
public string Name { get; set; }
|
||||
[DataMember]
|
||||
public string Manifest { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
8
docs/AppliesToGenerator/Properties/launchSettings.json
Normal file
8
docs/AppliesToGenerator/Properties/launchSettings.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"profiles": {
|
||||
"DocFXAppliesToGenerator": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "e:\\GitHub\\dotMorten\\NmeaParser.DocFX\\docs\\appliesToList.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue