Skip to content

Instantly share code, notes, and snippets.

@GeorgDangl
Last active May 24, 2019 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeorgDangl/b0292e22944beb6ced5bacad47728766 to your computer and use it in GitHub Desktop.
Save GeorgDangl/b0292e22944beb6ced5bacad47728766 to your computer and use it in GitHub Desktop.
Working with GAEB files in C++ with the Dangl.GAEB & Dangl.AVA Libraries, see https://www.dangl-it.com/articles/create-read-and-edit-gaeb-files-in-cplusplus-with-the-danglgaeb-danglava-libraries/
Console::WriteLine(L"Creating new GAEB file:");
GaebTargetType targetType = GaebTargetType::GaebXml;
Project^ projectToExport = gcnew Project();
ServiceSpecification^ servSpec = gcnew ServiceSpecification();
servSpec->ExchangePhase = ExchangePhase::Grant;
projectToExport->ServiceSpecifications->Add(servSpec);
Position^ position = gcnew Position();
position->ShortText = "C++ Position";
position->ItemNumber->StringRepresentation = "01";
Dangl::AVA::Contents::ServiceSpecificationContents::PositionExtensions::SetUnitPrice(position, *gcnew System::Decimal(12));
Dangl::AVA::Contents::ServiceSpecificationContents::PositionExtensions::SetQuantity(position, *gcnew System::Decimal(5));
servSpec->Elements->Add(position);
Dangl::AVA::Interop::AvaConverter::ExportToGaeb(projectToExport, args[1], GaebTargetType::GaebXml);
Console::WriteLine(args[1]);
public static class AvaConverter
{
public static Project ConvertGaebToAva(string gaebFilePath)
{
using (var fs = File.OpenRead(gaebFilePath))
{
var gaebFile = Dangl.GAEB.Reader.GAEBReader.ReadGaeb(fs);
var avaProject = Dangl.AVA.Converter.Converter.ConvertFromGaeb(gaebFile);
return avaProject;
}
}
public static Position[] GetPositionsInProject(Project avaProject)
{
return avaProject.ServiceSpecifications
.First()
.RecursiveElements()
.OfType<Position>()
.ToArray();
}
public static void ExportToGaeb(Project avaProject, string gaebFilePath, GaebTargetType gaebTargetType)
{
var gaebFile = Dangl.AVA.Converter.Converter.ConvertToGaeb(avaProject, destinationType: gaebTargetType.ToDestinationType());
using (var fs = File.Create(gaebFilePath))
{
using (var gaebStream = Dangl.GAEB.Writer.GAEBWriter.GetStream(gaebFile))
{
gaebStream.CopyTo(fs);
}
}
}
private static AVA.Converter.DestinationGAEBType ToDestinationType(this GaebTargetType gaebTargetType)
{
switch (gaebTargetType)
{
case GaebTargetType.Gaeb90:
return AVA.Converter.DestinationGAEBType.GAEB90;
case GaebTargetType.Gaeb2000:
return AVA.Converter.DestinationGAEBType.GAEB2000;
default:
return AVA.Converter.DestinationGAEBType.GAEBXML_V3_2;
}
}
}
Dangl::AVA::Project^ project = Dangl::AVA::Interop::AvaConverter::ConvertGaebToAva(args[0]);
array<Position^> ^positions = AvaConverter::GetPositionsInProject(project);
Console::WriteLine(L"Printing positions in imported GAEB file:");
Console::WriteLine(L"********************");
for (int i = 0; i < positions->Length; i++) {
Console::WriteLine(positions[i]->ItemNumber->StringRepresentation);
Console::WriteLine(positions[i]->ShortText);
Console::WriteLine(positions[i]->TotalPrice);
Console::WriteLine(L"********************");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment