GLDF.Net
0.6.0-dev.2
See the version list below for details.
dotnet add package GLDF.Net --version 0.6.0-dev.2
NuGet\Install-Package GLDF.Net -Version 0.6.0-dev.2
<PackageReference Include="GLDF.Net" Version="0.6.0-dev.2" />
paket add GLDF.Net --version 0.6.0-dev.2
#r "nuget: GLDF.Net, 0.6.0-dev.2"
// Install GLDF.Net as a Cake Addin
#addin nuget:?package=GLDF.Net&version=0.6.0-dev.2&prerelease
// Install GLDF.Net as a Cake Tool
#tool nuget:?package=GLDF.Net&version=0.6.0-dev.2&prerelease
GLDF .NET library
Intro
.NET 6.0 library for the Global Lighting Data Format GLDF
Features
- Serialize and deserialize GLDF XML
- 100% format coverage of version 1.0.0
- Validate GLDF XML with the GLDF XmlSchema (XSD)
- Read and write .gldf container files, including all assets and signature file
- Validate .gldf container files
- Parse XML/container either into 1:1 .NET POCOs or alternatively with resolved references
- No dependencies, small footprint (~450kb)
- Windows & Unix compatible
If you would like to read the GLDF L3D format as well, have a look on GLDF.L3d
How to get started
Requirements
- .NET Standard 2.0 compatible project
Nuget package
Add the package within your IDE or using the CLI
dotnet add package GLDF.Net
XML Serialization
Serialize GLDF domain DTOs to XML string
All models in the following examples are incomplete. For valid GLDF luminaires/sensors read the docs.
var serializer = new GldfXmlSerializer();
var root = new Root {Header = new Header {Author = "Github Example"}};
var xml = serializer.SerializeToString(root);
Serialize GLDF domain DTOs to .xml file
var serializer = new GldfXmlSerializer();
var root = new Root {Header = new Header {Author = "Github Example"}};
serializer.SerializeToFile(root, @"c:\some\file\path\luminaire.xml");
Deserialize GLDF XML string to domain DTOs
var serializer = new GldfXmlSerializer();
var xml = @"<Root><Header><Author>Github Example</Author></Header></Root>";
Root root = serializer.DeserializeFromString(xml);
Deserialize GLDF .xml file to domain DTOs
var serializer = new GldfXmlSerializer();
var filePath = @"c:\some\file\path\luminaire.xml";
Root root = serializer.DeserializeFromFile(filePath);
Set custom XML Serializer settings
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF32; // UTF-8 by default
settings.Indent = false; // true by default
// ...more settings
var serializer = new GldfXmlSerializer(settings);
XML validation
Validate XML string with GLDF XmlSchema
var gldfXmlValidator = new GldfXmlValidator();
var xml = @"<Root><Header><Author>Github Example</Author></Header></Root>";
IEnumerable<ValidationHint> validationResult = gldfXmlValidator.ValidateString(xml);
foreach (var validationHint in validationResult)
{
Console.Write(validationHint.Severity); // Error/Info/Warning
Console.Write(validationHint.ErrorType); // For XML validation its always XmlSchema
Console.Write(validationHint.Message); // E.g. missing XML Elements etc.
Console.Write(Environment.NewLine);
}
Validate a .xml file with GLDF XmlSchema
var gldfXmlValidator = new GldfXmlValidator();
var filePath = @"c:\some\file\path\luminaire.xml";
IEnumerable<ValidationHint> validationResult = gldfXmlValidator.ValidateFile(filePath);
foreach (var validationHint in validationResult)
{
Console.Write(validationHint.Severity); // Error/Info/Warning
Console.Write(validationHint.ErrorType); // For XML validation its always XmlSchema
Console.Write(validationHint.Message); // E.g. missing XML Elements etc.
Console.Write(Environment.NewLine);
}
Set Encoding (only required when validating .xml files)
var encoding = Encoding.UTF32;
var gldfXmlValidator = new GldfXmlValidator(encoding);
var filePath = @"c:\some\file\path\luminaire.xml";
gldfXmlValidator.ValidateFile(filePath);
Container read/write
Write a .gldf container file
var containerWriter = new GldfContainerWriter();
var gldfArchive = new GldfContainer
{
Product = new Root {Header = new Header {Author = "Github example"}},
Assets = new GldfAssets(),
Signature = "some checksum"
};
var filePath = @"c:\some\file\path\luminaire.gldf";
containerWriter.WriteToFile(filePath, gldfArchive);
Read a .gldf container file
var containerReader = new GldfContainerReader();
var filePath = @"c:\some\file\path\luminaire.gldf";
GldfContainer container = containerReader.ReadFromFile(filePath);
Console.WriteLine($"Luminaire author: {container.Product.Header.Author}");
Extract a .gldf container content to a directory
var containerReader = new GldfContainerReader();
var sourceFilePath = @"c:\some\file\path\luminaire.gldf";
var targetFolder = @"c:\some\file\path\extractedContent\";
containerReader.ExtractToDirectory(sourceFilePath, targetFolder);
Create a .gldf container from content in a directory
var containerWriter = new GldfContainerWriter();
var sourceDirectory = @"c:\some\file\path\extractedContent\";
var targetFile = @"c:\some\file\path\luminaire.gldf";
containerWriter.CreateFromDirectory(sourceDirectory, targetFile);
Container Validation
Validate a GldfArchive domain DTO
var validator = new GldfContainerValidator();
var gldfContainer = new GldfContainer
{
Product = new Root {Header = new Header {Author = "Github example"}},
Assets = new GldfAssets(),
Signature = "some checksum"
};
var validationResult = validator.Validate(gldfContainer);
foreach (var validationHint in validationResult)
{
Console.Write(validationHint.Severity); // Enum: Error/Info/Warning
Console.Write(validationHint.ErrorType); // Enum: E.g. InvalidZipFile
Console.Write(validationHint.Message); // E.g. Not a valid ZIP file etc.
Console.Write(Environment.NewLine);
}
Validate a .gldf container file
var validator = new GldfContainerValidator();
var filePath = @"c:\some\file\path\luminaire.gldf";
var validationResult = validator.Validate(filePath);
foreach (var validationHint in validationResult)
{
Console.Write(validationHint.Severity); // Enum: Error/Info/Warning
Console.Write(validationHint.ErrorType); // Enum: E.g. InvalidZipFile
Console.Write(validationHint.Message); // E.g. Not a valid ZIP file etc.
Console.Write(Environment.NewLine);
}
Deserialize with resolved references
The GldfXmlSerializer
and GldfContainerReader
classes produce an exact 1:1 representation of the GLDF XML in .NET (Root
). Which implies that any references such as Variant ➜ Emitter ➜ Equipment ➜ LightSource ➜ Photometry ➜ File are mapped in the form of Ids, which have to be resolved manually in your application. With the GldfParser
you have an option to let it resolve during deserialisation for you. And optionally load the GLDF File
element content as well:
Parse into POCOs with resolved references
var gldfParser = new GldfParser(new ParserSettings
{
LocalFileLoadBehaviour = LocalFileLoadBehaviour.Load,
OnlineFileLoadBehaviour = OnlineFileLoadBehaviour.Skip
});
var rootTyped = gldfParser.ParseFromContainerFile(/* GLDF container filepath */);
// Or
var rootTyped = gldfParser.ParseFromXmlFile(/* GLDF XML filepath */)
// Or
var rootTyped = gldfParser.ParseFromRoot(/* Root result from i.e. GldfXmlSerializer/GldfContainerReader */)
// Or
var rootTyped = gldfParser.ParseFromXml(/* GLDF XML content */)
Interfaces
There are also Interfaces you can use:
// 1) Serialize XML
IGldfXmlSerializer serializer = new GldfXmlSerializer();
// 2) Validate XML
IGldfXmlValidator xmlValidator = new GldfXmlValidator();
// 3) Read GLDF container
IGldfContainerReader containerReader = new GldfContainerReader();
// 4) Write GLDF container
IGldfContainerWriter containerWriter = new GldfContainerWriter();
// 5) Validate GLDF Container
IGldfContainerValidator containerValidator = new GldfContainerValidator();
// 6) Parse GLDF with resolved references
IGldfParser gldfParser = new GldfParser();
Questions, Issues & Contribution
Please use the discussion section for questions or create issues, when something seems to be wrong. PRs are welcome.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.