Skip to content

Commit

Permalink
Fix code generation when not an UA URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
randy-armstrong committed Jan 19, 2024
1 parent 7faaaa8 commit a366dea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
35 changes: 31 additions & 4 deletions Opc.Ua.ModelCompiler/Design.v105/DemoModel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
xmlns:di="http://opcfoundation.org/UA/DI/"
xmlns:opc="http://opcfoundation.org/UA/ModelDesign.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.opcfoundation.org/DemoModel/"
TargetNamespace="http://www.opcfoundation.org/DemoModel/"
TargetXmlNamespace="http://www.opcfoundation.org/DemoModel/"
xmlns="tag:opc-foundation.org,2024-01:DemoModel"
TargetNamespace="tag:opc-foundation.org,2024-01:DemoModel"
TargetXmlNamespace="tag:opc-foundation.org,2024-01:DemoModel"
TargetVersion="1.05.03"
TargetPublicationDate="2023-12-15T00:00:00Z">

<opc:Namespaces>
<opc:Namespace Name="DemoModel" Prefix="DemoModel" XmlNamespace="http://www.opcfoundation.org/DemoModel/Types.xsd" XmlPrefix="DemoModel">http://www.opcfoundation.org/DemoModel/</opc:Namespace>
<opc:Namespace Name="DemoModel" Prefix="DemoModel" XmlNamespace="tag:opc-foundation.org,2024-01:DemoModelTypes.xsd" XmlPrefix="DemoModel">tag:opc-foundation.org,2024-01:DemoModel</opc:Namespace>
<opc:Namespace Name="OpcUa" Prefix="Opc.Ua" Version="1.05.02" PublicationDate="2022-06-28T00:00:00Z" InternalPrefix="Opc.Ua.Server" XmlNamespace="http://opcfoundation.org/UA/2008/02/Types.xsd" XmlPrefix="OpcUa">http://opcfoundation.org/UA/</opc:Namespace>
<opc:Namespace Name="DI" Prefix="Opc.Ua.Di" InternalPrefix="Opc.Ua.Di.Server" XmlPrefix="OpcUaDi">http://opcfoundation.org/UA/DI/</opc:Namespace>
</opc:Namespaces>
Expand Down Expand Up @@ -53,7 +53,21 @@
<opc:TargetId>ua:Server_ServerCapabilities_RoleSet</opc:TargetId>
</opc:Reference>
</opc:References>
<opc:Extensions>
<opc:Extension>
<some:Thing xmlns:some="http://tempuri.com/something">Wicked</some:Thing>
</opc:Extension>
</opc:Extensions>
</opc:Object>

<opc:DataType SymbolicName="EnumUnderscoreTest" BaseType="ua:Enumeration" ForceEnumValues="true">
<opc:Fields>
<opc:Field Name="x_x" Identifier="1"/>
<opc:Field Name="_x" Identifier="2"/>
<opc:Field Name="x_" Identifier="3"/>
<opc:Field Name="_" Identifier="4"/>
</opc:Fields>
</opc:DataType>

<opc:VariableType SymbolicName="RestrictedVariableType" BaseType="ua:BaseDataVariableType" DataType="ua:String" >
<opc:Children>
Expand All @@ -77,6 +91,14 @@
<opc:DefaultAccessRestrictions>SessionWithSigningAndApplyToBrowseRequired</opc:DefaultAccessRestrictions>
</opc:Method>
</opc:Children>
<opc:Extensions>
<opc:Extension>
<some:Thing xmlns:some="http://tempuri.com/something">This way</some:Thing>
</opc:Extension>
<opc:Extension>
<some:World xmlns:some="http://tempuri.com/something">comes</some:World>
</opc:Extension>
</opc:Extensions>
</opc:ObjectType>

<opc:Object SymbolicName="TestObject" TypeDefinition="RestrictedObjectType">
Expand Down Expand Up @@ -109,6 +131,11 @@
</opc:DataType>

<opc:DataType SymbolicName="Vector" BaseType="ua:Structure">
<opc:Extensions>
<opc:Extension>
<some:Thing xmlns:some="http://tempuri.com/something">This way</some:Thing>
</opc:Extension>
</opc:Extensions>
<opc:Fields>
<opc:Field Name="X" DataType="ua:Double" />
<opc:Field Name="Y" DataType="ua:Double" />
Expand Down
5 changes: 3 additions & 2 deletions Opc.Ua.ModelCompiler/NodeSetToModelDesign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private static void CollectModels(ModelTableEntry model, List<ModelTableEntry> m
private static Namespace CreateNamespace(ModelTableEntry model)
{
Namespace ns = null;

if (model.ModelUri.StartsWith(Namespaces.OpcUa))
{
ns = new Namespace()
Expand All @@ -190,7 +191,7 @@ private static Namespace CreateNamespace(ModelTableEntry model)
Version = model.Version
};
ns.XmlPrefix = ns.Prefix = "Opc.Ua." + ns.Name;
ns.Name = ns.Name.Replace(".", "");
ns.Name = ns.Name.Replace(".", "").Replace("-", "").Replace(",", "").Replace(":", "");
}
else
{
Expand All @@ -203,7 +204,7 @@ private static Namespace CreateNamespace(ModelTableEntry model)
Version = model.Version
};
ns.XmlPrefix = ns.Prefix = ns.Name;
ns.Name = ns.Name.Replace(".", "");
ns.Name = ns.Name.Replace(".", "").Replace("-", "").Replace(",", "").Replace(":", "");
}

if (ns.Value == Namespaces.OpcUa)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void WriteTemplate_Constants(string namespacePrefix, string className, L

case Language.TypeScript:
{
fileName = String.Format(@"{0}\{1}-{2}.ts", OutputDirectory, namespacePrefix.ToLower().Replace(".", ""), className.ToLower());
fileName = String.Format(@"{0}\{1}-{2}.ts", OutputDirectory, namespacePrefix.ToLower().Replace(".", "").Replace("-", "").Replace(",", "").Replace(":", ""), className.ToLower());
m_templateSuffix = ".ts";
break;
}
Expand Down

0 comments on commit a366dea

Please sign in to comment.