added szfGenerator and fixed up szfFile classes
This commit is contained in:
parent
8fc3719d69
commit
38d0337ff7
1
.vscode/settings.json
vendored
Normal file
1
.vscode/settings.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{}
|
@ -2,5 +2,10 @@ namespace SessionZero.SzfLib.File;
|
||||
|
||||
public interface ISzfFile
|
||||
{
|
||||
public string? SzfType { get; set; }
|
||||
public string? Schema { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Guid { get; set; }
|
||||
public string? Version { get; set; }
|
||||
public string? Content { get; set; }
|
||||
}
|
@ -2,7 +2,10 @@ namespace SessionZero.SzfLib.File;
|
||||
|
||||
public class SzfFile : ISzfFile
|
||||
{
|
||||
public string? SzfType { get; set; }
|
||||
public string? SchemaVersion { get; set; }
|
||||
public string? Content { get; set; }
|
||||
public string? SzfType { get; set; } = string.Empty;
|
||||
public string? Schema { get; set; } = string.Empty;
|
||||
public string? Name { get; set; } = string.Empty;
|
||||
public string? Guid { get; set; } = string.Empty;
|
||||
public string? Version { get; set; } = string.Empty;
|
||||
public string? Content { get; set; } = string.Empty;
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
using SessionZero.SzfLib.File;
|
||||
using SessionZero.SzfLib.Objects;
|
||||
|
||||
namespace SessionZero.SzfLib.Generator;
|
||||
|
||||
public interface ISzfGenerator
|
||||
{
|
||||
|
||||
public SzfFile GenerateSzfFile(SzfObject obj);
|
||||
}
|
@ -1,6 +1,59 @@
|
||||
using System.Text;
|
||||
using SessionZero.SzfLib.File;
|
||||
using SessionZero.SzfLib.Objects;
|
||||
using SessionZero.SzfLib.Parser;
|
||||
|
||||
namespace SessionZero.SzfLib.Generator;
|
||||
|
||||
public class SzfGenerator : ISzfGenerator
|
||||
{
|
||||
|
||||
|
||||
private StringBuilder? _builder;
|
||||
|
||||
|
||||
public SzfFile GenerateSzfFile(SzfObject szfObj)
|
||||
{
|
||||
_builder = new();
|
||||
|
||||
_builder.AppendLine($"!type: {szfObj.SzfType}");
|
||||
_builder.AppendLine($"!schema: {szfObj.SzfVersion}");
|
||||
|
||||
_builder.AppendLine();
|
||||
|
||||
foreach (var section in szfObj.Sections)
|
||||
{
|
||||
WriteSection(section);
|
||||
}
|
||||
|
||||
SzfFile szfFile = new()
|
||||
{
|
||||
SzfType = szfObj.SzfType,
|
||||
Schema = szfObj.SzfVersion,
|
||||
Name = szfObj.GetMetadataField("Name"),
|
||||
Guid = szfObj.GetMetadataField("Guid"),
|
||||
Version = szfObj.GetMetadataField("Version"),
|
||||
Content = _builder.ToString()
|
||||
};
|
||||
|
||||
return szfFile;
|
||||
}
|
||||
|
||||
private void WriteSection(SzfSection section, string parentPath = "")
|
||||
{
|
||||
var sectionName = string.IsNullOrEmpty(parentPath) ? section.Name : $"{parentPath}.{section.Name}";
|
||||
_builder?.AppendLine($"[{sectionName}]");
|
||||
|
||||
foreach (var field in section.Fields)
|
||||
{
|
||||
_builder?.AppendLine($"{field.Key} ({field.Value.SzfType}) = {field.Value.Value}");
|
||||
}
|
||||
|
||||
_builder?.AppendLine();
|
||||
|
||||
foreach (var subsection in section.Subsections.Values)
|
||||
{
|
||||
WriteSection(subsection, sectionName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageIcon>logo_500x500.png</PackageIcon>
|
||||
<Version>0.2.0</Version>
|
||||
<Version>0.3.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user