Skip to content

Commit

Permalink
Add more attributes to type metadata (#425)
Browse files Browse the repository at this point in the history
* Add NodeClass and Mandatory to type metadata

* Also include reference type

* Add displayName and externalId

* Rename mandatory - isMandatory
  • Loading branch information
einarmo authored Jul 4, 2023
1 parent 56d162e commit d2f07df
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
12 changes: 6 additions & 6 deletions Extractor/Pushers/FDM/NodeTypeCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ private void BuildNodeTypes()
{
foreach (var child in type.Children.Values)
{
CollectChild(type, child, Enumerable.Empty<QualifiedName>());
CollectChild(type, child, Enumerable.Empty<(UAReference Reference, QualifiedName Name)>());
}
}
}

private string GetPath(IEnumerable<QualifiedName> path, string name)
private string GetPath(IEnumerable<(UAReference Reference, QualifiedName Name)> path, string name)
{
if (path.Any())
{
return $"{string.Join('_', path.Select(p => p.Name))}_{name}";
return $"{string.Join('_', path.Select(p => p.Name.Name))}_{name}";
}
return name;
}

private void CollectChild(FullUANodeType type, ChildNode node, IEnumerable<QualifiedName> path)
private void CollectChild(FullUANodeType type, ChildNode node, IEnumerable<(UAReference Reference, QualifiedName Name)> path)
{
var name = node.Reference.BrowseName;
var nodeType = Types[node.Node.TypeDefinition!];
Expand All @@ -173,10 +173,10 @@ private void CollectChild(FullUANodeType type, ChildNode node, IEnumerable<Quali
return;
}

var nextPath = path.Append(name);
var nextPath = path.Append((node.Reference.Reference, name));
if (node.Node is UAVariable variable)
{
type.Properties[fullName] = new DMSReferenceNode(variable, node.Reference.Reference, fullName)
type.Properties[fullName] = new DMSReferenceNode(variable, node.Reference.Reference, fullName, nextPath)
{
ModellingRule = node.Reference.ModellingRule
};
Expand Down
5 changes: 5 additions & 0 deletions Extractor/Pushers/FDM/TypeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public class PropertyNode
public int[]? ArrayDimensions { get; set; }
public int? ValueRank { get; set; }
public string? BrowseName { get; set; }
public int? NodeClass { get; set; }
public bool IsMandatory { get; set; }
public string? ReferenceType { get; set; }
public string? DisplayName { get; set; }
public string? ExternalId { get; set; }
}


Expand Down
29 changes: 19 additions & 10 deletions Extractor/Pushers/FDM/Types/NodeTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,37 @@ public TypeMetadata GetTypeMetadata()
var properties = new Dictionary<string, IEnumerable<PropertyNode>>();
foreach (var kvp in Properties)
{
var collectedNodes = new List<BaseUANode>();
var collectedNodes = new List<(BaseUANode node, bool mandatory, UAReference reference)>();
var node = (BaseUANode)kvp.Value.Node;
var pathEnum = kvp.Value.Path.Reverse().GetEnumerator();
pathEnum.MoveNext();
while (node.Id != NodeId)
{
collectedNodes.Add(node);
var pair = pathEnum.Current;
collectedNodes.Add((node, kvp.Value.ModellingRule == ModellingRule.Mandatory, pair.Reference));
pathEnum.MoveNext();
node = node.Parent;
if (node == null) throw new InvalidOperationException("Expected property to be proper child of type, followed parents to nothing");
}
properties[kvp.Key] = collectedNodes.Select(k =>
properties[kvp.Key] = collectedNodes.Select(pair =>
{
var prop = new PropertyNode
{
TypeDefinition = k.TypeDefinition?.ToString(),
BrowseName = $"{k.Attributes.BrowseName?.NamespaceIndex ?? 0}:{k.Attributes.BrowseName?.Name ?? k.Name ?? ""}",
NodeId = k.Id.ToString(),
TypeDefinition = pair.node.TypeDefinition?.ToString(),
BrowseName = $"{pair.node.Attributes.BrowseName?.NamespaceIndex ?? 0}:{pair.node.Attributes.BrowseName?.Name ?? pair.node.Name ?? ""}",
NodeId = pair.node.Id.ToString(),
NodeClass = (int)pair.node.NodeClass,
IsMandatory = pair.mandatory,
ReferenceType = pair.reference.Type.Id.ToString(),
DisplayName = pair.node.Name ?? "",
ExternalId = FDMUtils.SanitizeExternalId(pair.node.Name ?? "")
};
if (k is UAVariable kVar)
if (pair.node is UAVariable nVar)
{
prop.ValueRank = kVar.ValueRank;
prop.DataType = kVar.FullAttributes.DataType.Id.ToString();
prop.ArrayDimensions = kVar.ArrayDimensions;
prop.ValueRank = nVar.ValueRank;
prop.DataType = nVar.FullAttributes.DataType.Id.ToString();
prop.ArrayDimensions = nVar.ArrayDimensions;
}
return prop;
}).ToList();
Expand Down
4 changes: 3 additions & 1 deletion Extractor/Pushers/FDM/Types/ReferenceTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public class DMSReferenceNode : ReferenceNode
{
public UAVariable Node { get; set; }
public BasePropertyType? DMSType { get; set; }
public DMSReferenceNode(UAVariable node, UAReference reference, string externalId)
public IEnumerable<(UAReference Reference, QualifiedName Name)> Path { get; }
public DMSReferenceNode(UAVariable node, UAReference reference, string externalId, IEnumerable<(UAReference Reference, QualifiedName Name)> path)
: base(node.NodeClass, node.Attributes.BrowseName ?? new QualifiedName(node.Name ?? ""), externalId, reference)
{
Node = node;
Path = path;
}
}
public class ReferenceNode
Expand Down

0 comments on commit d2f07df

Please sign in to comment.