GLDF.Net
0.5.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package GLDF.Net --version 0.5.0
NuGet\Install-Package GLDF.Net -Version 0.5.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GLDF.Net" Version="0.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GLDF.Net --version 0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GLDF.Net, 0.5.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GLDF.Net as a Cake Addin #addin nuget:?package=GLDF.Net&version=0.5.0 // Install GLDF.Net as a Cake Tool #tool nuget:?package=GLDF.Net&version=0.5.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
GLDF .NET library
Intro
.NET Standard 2.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
- No dependencies, small footprint (~400kb)
- 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);
}
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();
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 | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.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.