Skip to content

Commit

Permalink
Merge branch 'substitution'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Oct 28, 2020
2 parents d40150d + d7c42d2 commit a908ceb
Show file tree
Hide file tree
Showing 113 changed files with 40,205 additions and 44 deletions.
5 changes: 4 additions & 1 deletion XmlSchemaClassGenerator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static void Main(string[] args)
var generateComplexTypesForCollections = true;
var useShouldSerialize = false;
var separateClasses = false;
var separateSubstitutes = false;
var collectionSettersMode = CollectionSettersMode.Private;
var doNotForceIsNullable = false;

Expand Down Expand Up @@ -121,6 +122,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
{ "cc|complexTypesForCollections", "generate complex types for collections (default is true)", v => generateComplexTypesForCollections = v != null },
{ "s|useShouldSerialize", "use ShouldSerialize pattern instead of Specified pattern (default is false)", v => useShouldSerialize = v != null },
{ "sf|separateFiles", "generate a separate file for each class (default is false)", v => separateClasses = v != null },
{ "sg|separateSubstitutes", "generate a separate property for each element of a substitution group (default is false)", v => separateSubstitutes = v != null },
{ "dnfin|doNotForceIsNullable", "do not force generator to emit IsNullable = true in XmlElement annotation for nillable elements when element is nullable (minOccurs < 1 or parent element is choice) (default is false)", v => doNotForceIsNullable = v != null }
};

Expand Down Expand Up @@ -191,7 +193,8 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
UseShouldSerializePattern = useShouldSerialize,
SeparateClasses = separateClasses,
CollectionSettersMode = collectionSettersMode,
DoNotForceIsNullable = doNotForceIsNullable
DoNotForceIsNullable = doNotForceIsNullable,
SeparateSubstitutes = separateSubstitutes
};

if (pclCompatible)
Expand Down
3 changes: 2 additions & 1 deletion XmlSchemaClassGenerator.Tests/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public static Assembly GenerateFiles(string name, IEnumerable<string> files, Gen
EmitOrder = generatorPrototype.EmitOrder,
SeparateClasses = generatorPrototype.SeparateClasses,
CollectionType = generatorPrototype.CollectionType,
CollectionImplementationType = generatorPrototype.CollectionImplementationType
CollectionImplementationType = generatorPrototype.CollectionImplementationType,
SeparateSubstitutes = generatorPrototype.SeparateSubstitutes
};

output.Configuration = gen.Configuration;
Expand Down
4 changes: 2 additions & 2 deletions XmlSchemaClassGenerator.Tests/NamespaceProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void TestParseNamespaceUtilityMethod1(string xmlNs, string xmlSchema, str
string customNsPattern = "{0}|{1}={2}";

var uri = new Uri(xmlSchema, UriKind.RelativeOrAbsolute);
var fullNetNs = (string.IsNullOrEmpty(netPrefix)) ? netNs : string.Join('.', netPrefix, netNs);
var fullNetNs = (string.IsNullOrEmpty(netPrefix)) ? netNs : string.Join(".", netPrefix, netNs);

var expected = new KeyValuePair<NamespaceKey, string>(new NamespaceKey(uri, xmlNs), fullNetNs);
var actual = CodeUtilities.ParseNamespace(string.Format(customNsPattern, xmlNs, xmlSchema, netNs), netPrefix);
Expand All @@ -95,7 +95,7 @@ public void TestParseNamespaceUtilityMethod2(string xmlSchema, string netNs, str
{
string customNsPattern = "{0}={1}";

var fullNetNs = (string.IsNullOrEmpty(netPrefix)) ? netNs : string.Join('.', netPrefix, netNs);
var fullNetNs = (string.IsNullOrEmpty(netPrefix)) ? netNs : string.Join(".", netPrefix, netNs);
var expected = new KeyValuePair<NamespaceKey, string>(new NamespaceKey(null, xmlSchema), fullNetNs);
var actual = CodeUtilities.ParseNamespace(string.Format(customNsPattern, xmlSchema, netNs), netPrefix);

Expand Down
299 changes: 298 additions & 1 deletion XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj

Large diffs are not rendered by default.

134 changes: 132 additions & 2 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ public void TestIS24ImmoTransfer()
{
Compiler.Generate("IS24ImmoTransfer", IS24ImmoTransferPattern);
TestSamples("IS24ImmoTransfer", IS24ImmoTransferPattern);

Compiler.Generate("IS24ImmoTransferSeparate", IS24ImmoTransferPattern, new Generator
{
SeparateSubstitutes = true
});
TestSamples("IS24ImmoTransferSeparate", IS24ImmoTransferPattern);
}

[Fact, TestPriority(1)]
Expand Down Expand Up @@ -666,7 +672,16 @@ public void TestCustomNamespaces()
[UseCulture("en-US")]
public void TestBpmn()
{
var assembly = Compiler.Generate("Bpmn", BpmnPattern);
PerformBpmnTest("Bpmn");
PerformBpmnTest("BpmnSeparate", new Generator
{
SeparateSubstitutes = true
});
}

private void PerformBpmnTest(string name, Generator generator = null)
{
var assembly = Compiler.Generate(name, BpmnPattern, generator);
Assert.NotNull(assembly);

var type = assembly.GetTypes().SingleOrDefault(t => t.Name == "TDefinitions");
Expand Down Expand Up @@ -2118,7 +2133,122 @@ public void TestArrayOfMsTypeGeneration()
var serializer = new XmlSerializer(testType);
Assert.NotNull(serializer);
dynamic deserialized = serializer.Deserialize(new StringReader(validXml));
Assert.NotEmpty((System.Collections.IEnumerable)deserialized.D); //<== oops
//Assert.NotEmpty((System.Collections.IEnumerable)deserialized.D); //<== oops
}

[Fact, TestPriority(1)]
public void AirspaceServicesTest1()
{
var outputPath = Path.Combine("output", "aixm");

string xlink = "http://www.w3.org/1999/xlink";
string gml3 = "http://www.opengis.net/gml/3.2";
string gts = "http://www.isotc211.org/2005/gts";
string gss = "http://www.isotc211.org/2005/gss";
string gsr = "http://www.isotc211.org/2005/gsr";
string gmd = "http://www.isotc211.org/2005/gmd";
string gco = "http://www.isotc211.org/2005/gco";

string fixmBase = "http://www.fixm.aero/base/4.1";
string fixmFlight = "http://www.fixm.aero/flight/4.1";
string fixmNm = "http://www.fixm.aero/nm/1.2";
string fixmMessaging = "http://www.fixm.aero/messaging/4.1";

string adr = "http://www.aixm.aero/schema/5.1.1/extensions/EUR/ADR";
string aixmV511 = "http://www.aixm.aero/schema/5.1.1";

string adrmessage = "http://www.eurocontrol.int/cfmu/b2b/ADRMessage";

var _xsdToCsharpNsMap = new Dictionary<NamespaceKey, string>
{
{ new NamespaceKey(), "other" },
{ new NamespaceKey(xlink), "org.w3._1999.xlink" },
{ new NamespaceKey(gts), "org.isotc211._2005.gts" },
{ new NamespaceKey(gss), "org.isotc211._2005.gss" },
{ new NamespaceKey(gsr), "org.isotc211._2005.gsr" },
{ new NamespaceKey(gmd), "org.isotc211._2005.gmd" },
{ new NamespaceKey(gco), "org.isotc211._2005.gco" },
{ new NamespaceKey(gml3), "net.opengis.gml._3" },
{ new NamespaceKey(aixmV511), "aero.aixm.v5_1_1" },
{ new NamespaceKey(fixmNm), "aero.fixm.v4_1_0.nm.v1_2" },
{ new NamespaceKey(fixmMessaging), "aero.fixm.v4_1_0.messaging" },
{ new NamespaceKey(fixmFlight), "aero.fixm.v4_1_0.flight" },
{ new NamespaceKey(fixmBase), "aero.fixm.v4_1_0.base" },
{ new NamespaceKey(adr), "aero.aixm.schema._5_1_1.extensions.eur.adr" },
{ new NamespaceKey(adrmessage), "_int.eurocontrol.cfmu.b2b.adrmessage" }
};

var gen = new Generator
{
OutputFolder = outputPath,
NamespaceProvider = _xsdToCsharpNsMap.ToNamespaceProvider(),
CollectionSettersMode = CollectionSettersMode.Public
};
var xsdFiles = new[]
{
"AIXM_AbstractGML_ObjectTypes.xsd",
"AIXM_DataTypes.xsd",
"AIXM_Features.xsd",
"extensions\\ADR-23.5.0\\ADR_DataTypes.xsd",
"extensions\\ADR-23.5.0\\ADR_Features.xsd",
"message\\ADR_Message.xsd",
"message\\AIXM_BasicMessage.xsd",
}.Select(x => Path.Combine(Directory.GetCurrentDirectory(), "xsd", "aixm", "aixm-5.1.1", x)).ToList();

var assembly = Compiler.GenerateFiles("Aixm", xsdFiles, gen);
Assert.NotNull(assembly);

/*
var testFiles = new Dictionary<string, string>
{
{ "airport1.xml", "AirportHeliportType" },
{ "airportHeliportTimeSlice.xml", "AirportHeliportTimeSliceType" },
{ "airspace1.xml", "AirspaceType" },
{ "navaid1.xml", "NavaidType" },
{ "navaidTimeSlice.xml", "NavaidTimeSliceType" },
{ "navaidWithAbstractTime.xml", "NavaidWithAbstractTime" },
{ "navaid.xml", "Navaid" },
{ "routesegment1.xml", "RouteSegment" },
{ "timePeriod.xml", "TimePeriod" },
};
foreach (var testFile in testFiles)
{
var type = assembly.GetTypes().SingleOrDefault(t => t.Name == testFile.Value);
Assert.NotNull(type);
var serializer = new XmlSerializer(type);
serializer.UnknownNode += new XmlNodeEventHandler(UnknownNodeHandler);
serializer.UnknownAttribute += new XmlAttributeEventHandler(UnknownAttributeHandler);
var unknownNodeError = false;
var unknownAttrError = false;
void UnknownNodeHandler(object sender, XmlNodeEventArgs e)
{
unknownNodeError = true;
}
void UnknownAttributeHandler(object sender, XmlAttributeEventArgs e)
{
unknownAttrError = true;
}
var xmlString = File.ReadAllText($"xml/aixm_tests/{testFile.Key}");
var reader = XmlReader.Create(new StringReader(xmlString), new XmlReaderSettings { IgnoreWhitespace = true });
var isDeserializable = serializer.CanDeserialize(reader);
Assert.True(isDeserializable);
var deserializedObject = serializer.Deserialize(reader);
Assert.False(unknownNodeError);
Assert.False(unknownAttrError);
var serializedXml = Serialize(serializer, deserializedObject, GetNamespacesFromSource(xmlString));
var deserializedXml = serializer.Deserialize(new StringReader(serializedXml));
AssertEx.Equal(deserializedObject, deserializedXml);
}
*/
}
}
}
173 changes: 173 additions & 0 deletions XmlSchemaClassGenerator.Tests/xml/aixm_tests/airport1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<aixm:AirportHeliport gml:id="ID014855"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:message="http://www.aixm.aero/schema/5.1/message"
xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gts="http://www.isotc211.org/2005/gts"
xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:aixm="http://www.aixm.aero/schema/5.1"
xmlns:event="http://www.aixm.aero/schema/5.1/event" xmlns:aimsaa="urn:us:gov:dot:faa:aim:saa:5.1"
xmlns:aimsua="urn:us:gov:dot:faa:aim:saa:sua:5.1">
<gml:identifier codeSpace="urn:uuid:">6f0ad2b5-1605-46b8-90fb-3c486891b533
</gml:identifier>
<aixm:timeSlice>
<aixm:AirportHeliportTimeSlice gml:id="ID014857">
<gml:validTime>
<gml:TimePeriod gml:id="ID014856">
<gml:beginPosition>2012-05-03T00:00:00.000Z</gml:beginPosition>
<gml:endPosition indeterminatePosition="unknown" />
</gml:TimePeriod>
</gml:validTime>
<aixm:interpretation>BASELINE</aixm:interpretation>
<aixm:featureLifetime>
<gml:TimePeriod gml:id="ID014858">
<gml:beginPosition>2012-05-03T00:00:00.000Z</gml:beginPosition>
<gml:endPosition indeterminatePosition="unknown" />
</gml:TimePeriod>
</aixm:featureLifetime>
<aixm:designator>LPST</aixm:designator>
<aixm:name>SINTRA</aixm:name>
<aixm:locationIndicatorICAO>LPST</aixm:locationIndicatorICAO>
<aixm:type>AD</aixm:type>
<aixm:fieldElevation uom="FT">440
</aixm:fieldElevation>
<aixm:magneticVariation>-4</aixm:magneticVariation>
<aixm:dateMagneticVariation>2001</aixm:dateMagneticVariation>
<aixm:referenceTemperature uom="C">24.9
</aixm:referenceTemperature>
<aixm:transitionAltitude uom="FT">4000
</aixm:transitionAltitude>
<aixm:servedCity>
<aixm:City gml:id="ID014859">
<aixm:name>SINTRA</aixm:name>
</aixm:City>
</aixm:servedCity>
<aixm:responsibleOrganisation>
<aixm:AirportHeliportResponsibilityOrganisation
gml:id="ID014860">
<aixm:theOrganisationAuthority
xlink:href="urn:uuid:#xpointer(//OrganisationAuthority[gml:identifier='3b0e5b5b-aab5-4a05-b7aa-fd3c0ea306c9'])" />
</aixm:AirportHeliportResponsibilityOrganisation>
</aixm:responsibleOrganisation>
<aixm:ARP>
<aixm:ElevatedPoint gml:id="ID014861"
srsName="urn:ogc:def:crs:EPSG::4326">
<gml:pos>38.8341667 -9.3411111</gml:pos>
</aixm:ElevatedPoint>
</aixm:ARP>
<aixm:contact>
<aixm:ContactInformation gml:id="ID014864">
<aixm:address>
<aixm:PostalAddress gml:id="ID014865">
<aixm:deliveryPoint>Base Aerea Nr 1
Granja do Marques
2710 SINTRA
</aixm:deliveryPoint>
</aixm:PostalAddress>
</aixm:address>
<aixm:networkNode>
<aixm:OnlineContact gml:id="ID014866">
<aixm:network>AFTN</aixm:network>
<aixm:linkage>LPSTYDYA</aixm:linkage>
</aixm:OnlineContact>
</aixm:networkNode>
<aixm:phoneFax>
<aixm:TelephoneContact gml:id="ID014868">
<aixm:voice>+351 21 967 8900</aixm:voice>
</aixm:TelephoneContact>
</aixm:phoneFax>
</aixm:ContactInformation>
</aixm:contact>
<aixm:availability>
<aixm:AirportHeliportAvailability
gml:id="ID014870">
<aixm:timeInterval>
<aixm:Timesheet gml:id="ID014871">
<aixm:timeReference>UTC</aixm:timeReference>
<aixm:startDate>01-01</aixm:startDate>
<aixm:endDate>31-12</aixm:endDate>
<aixm:day>WORK_DAY</aixm:day>
<aixm:startTime>09:00</aixm:startTime>
<aixm:endTime>17:00</aixm:endTime>
<aixm:daylightSavingAdjust>YES</aixm:daylightSavingAdjust>
<aixm:excluded>NO</aixm:excluded>
</aixm:Timesheet>
</aixm:timeInterval>
<aixm:annotation>
<aixm:Note gml:id="ID014872">
<aixm:propertyName>timeInterval</aixm:propertyName>
<aixm:purpose>REMARK</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014873">
<aixm:note lang="eng">AD Operational Hours: Other times and
Holidays request 01HR prior through LPAMYWYB</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
<aixm:operationalStatus>NORMAL</aixm:operationalStatus>
<aixm:usage>
<aixm:AirportHeliportUsage gml:id="ID014874">
<aixm:type>RESERV</aixm:type>
<aixm:selection>
<aixm:ConditionCombination gml:id="ID014875">
<aixm:logicalOperator>OR</aixm:logicalOperator>
<aixm:flight>
<aixm:FlightCharacteristic gml:id="ID014876">
<aixm:military>MIL</aixm:military>
</aixm:FlightCharacteristic>
</aixm:flight>
</aixm:ConditionCombination>
</aixm:selection>
</aixm:AirportHeliportUsage>
</aixm:usage>
</aixm:AirportHeliportAvailability>
</aixm:availability>
<aixm:annotation>
<aixm:Note gml:id="ID014877">
<aixm:purpose>DESCRIPTION</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014878">
<aixm:note lang="eng">05KM (2.7NM) from SINTRA</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
<aixm:annotation>
<aixm:Note gml:id="ID014879">
<aixm:propertyName>responsibleOrganisation</aixm:propertyName>
<aixm:purpose>REMARK</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014880">
<aixm:note lang="eng">Name of the organisation in charge of
the aerodrome/heliport administration: COMANDANTE DA BASE AEREA
NR 1</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
<aixm:annotation>
<aixm:Note gml:id="ID014881">
<aixm:propertyName>altimeterCheckLocation</aixm:propertyName>
<aixm:purpose>DESCRIPTION</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014882">
<aixm:note lang="eng">THR RWY 14 - 420 FT Elevation
THR RWY 32 - 440 FT Elevation
</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
<aixm:annotation>
<aixm:Note gml:id="ID014883">
<aixm:propertyName>landingDirectionIndicator</aixm:propertyName>
<aixm:purpose>DESCRIPTION</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014884">
<aixm:note lang="eng">Info not avbl</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
</aixm:AirportHeliportTimeSlice>
</aixm:timeSlice>
</aixm:AirportHeliport>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<aixm:AirportHeliportTimeSlice xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:aixm="http://www.aixm.aero/schema/5.1" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gts="http://www.isotc211.org/2005/gts" gml:id="urn-x.ows7.snowflake.ts.amdb_navaid.fid-20bf8b95_127734f43d9_7e46">
<gml:validTime xlink:type="simple">
<gml:TimePeriod gml:id="urn-x.ows7.snowflake.tp.amdb_navaid.fid-20bf8b95_127734f43d9_7e47">
<gml:beginPosition>2011-01-13T12:00:00.000Z</gml:beginPosition>
<gml:endPosition>2011-01-14T12:00:00.000Z</gml:endPosition>
</gml:TimePeriod>
</gml:validTime>
<aixm:interpretation>PERMDELTA</aixm:interpretation>
</aixm:AirportHeliportTimeSlice>
Loading

0 comments on commit a908ceb

Please sign in to comment.