Last active
May 24, 2019 20:58
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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