Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
using AgGateway.ADAPT.ApplicationDataModel.ADM;
using AgGateway.ADAPT.ShippedItemInstancePlugin;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
Expand Down Expand Up @@ -36,6 +39,7 @@ public async Task<IActionResult> Run(
bool nativeOut = false;
bool isoOut = false;
bool admOut = false;
bool adaptStandardOut = false;
if (req.Headers.TryGetValue("content-type", out Microsoft.Extensions.Primitives.StringValues contentHeaders))
{
//Determine output type from header
Expand All @@ -47,6 +51,10 @@ public async Task<IActionResult> Run(
{
admOut = true;
}
else if (contentHeaders.Contains("application/vnd.aggateway.adapt.standard+zip"))
{
adaptStandardOut = true;
}
else
{
nativeOut = true;
Expand All @@ -58,11 +66,23 @@ public async Task<IActionResult> Run(
input = input.Replace("\r\n", string.Empty).Replace("\t", string.Empty).Replace(" ", string.Empty); //Remove whitespace in the request as desired

//Override the default location of the ADAPT resource files to accomodate placement within Azure function

// ADAPT resource locations
AgGateway.ADAPT.Representation.UnitSystem.UnitSystemManager.UnitSystemDataLocation = System.IO.Path.Combine(executionContext.FunctionDirectory, "../Resources", "UnitSystem.xml");
AgGateway.ADAPT.Representation.RepresentationSystem.RepresentationManager.RepresentationSystemDataLocation = System.IO.Path.Combine(executionContext.FunctionDirectory, "../Resources", "RepresentationSystem.xml");

// ISO Plugin resource locations
AgGateway.ADAPT.ISOv4Plugin.Representation.DdiLoader.DDIDataFile = System.IO.Path.Combine(executionContext.FunctionDirectory, "../Resources", "ddiExport.txt");
AgGateway.ADAPT.ISOv4Plugin.Representation.IsoUnitOfMeasureList.ISOUOMDataFile = System.IO.Path.Combine(executionContext.FunctionDirectory, "../Resources", "IsoUnitOfMeasure.xml");

// StandardPlugin resource locations
//
// There are the two files in CommonExporters.cs, internal class CommonExporters; perhaps all resource file locations should be set here
// other files are in /resources folder
//
// AgGateway.ADAPT.StandardPlugin.TypeMappingsFileLocation = System.IO.Path.Combine(executionContext.FunctionDirectory, "../", "framework-to-standard-type-mappings.json");
// AgGateway.ADAPT.StandardPlugin.StandardDataTypesFileLocatiom = System.IO.Path.Combine(executionContext.FunctionDirectory, "../", "adapt-data-type-definitions.json");

//Write the input to a file so that the ShippedItemInstance plugin can read it
string folder = System.IO.Path.GetTempPath();
string tempPath = Path.Combine(folder, "input.json");
Expand Down Expand Up @@ -105,7 +125,11 @@ public async Task<IActionResult> Run(
AgGateway.ADAPT.ADMPlugin.Plugin admPlugin = new AgGateway.ADAPT.ADMPlugin.Plugin();
admPlugin.Export(inputData, outputPath);
}

else if (adaptStandardOut)
{
AgGateway.ADAPT.StandardPlugin.Plugin adaptStandardPlugin = new AgGateway.ADAPT.StandardPlugin.Plugin();
adaptStandardPlugin.Export(inputData, outputPath);
}
System.IO.Compression.ZipFile.CreateFromDirectory(outputPath, outputZip);
return new FileContentResult(File.ReadAllBytes(outputZip), "application/octet-stream");
}
Expand Down
12 changes: 7 additions & 5 deletions ShippedItemInstanceConverter.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AgGatewayADAPTFramework" Version="2.7.0" />
<PackageReference Include="AgGatewayADMPlugin" Version="2.3.3" />
<PackageReference Include="AgGatewayISOPlugin" Version="4.0.0" />
<PackageReference Include="AgGatewayShippedItemInstancePlugin" Version="1.1.0" />
<PackageReference Include="AgGateway.ADAPT.StandardPlugin" Version="0.9.7" />
<PackageReference Include="AgGatewayADAPTFramework" Version="3.1.0" />
<PackageReference Include="AgGatewayADMPlugin" Version="3.0.1" />
<PackageReference Include="AgGatewayISOPlugin" Version="5.6.1" />
<PackageReference Include="AgGatewayShippedItemInstancePlugin" Version="4.1.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.7.2-preview" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
Loading