public static void Decorate(XmlNode root) { if (Enum.GetNames(typeof(UADataType)).Contains(root.Name)) { UADataType dataType = (UADataType)Enum.Parse(typeof(UADataType), root.Name, true); XmlElement element = root as XmlElement; switch (dataType) { case UADataType.UAString: case UADataType.UAInt: case UADataType.UADouble: element.SetAttribute(DecoratorTags.OutputDecorator, ComponentRenderType.BodyText.ToString()); break; case UADataType.UAIntMatrix: case UADataType.UAStringMatrix: case UADataType.UADoubleMatrix: element.SetAttribute(DecoratorTags.OutputDecorator, ComponentRenderType.Grid.ToString()); break; } } foreach (XmlNode nd in root.ChildNodes) { Decorate(nd); } }
private static void Update(IDataTypeFactory nodeDesign, UADataType nodeSet, IUAModelContext modelContext, Action <TraceMessage> traceEvent) { nodeSet.Definition.GetParameters(nodeDesign.NewDefinition(), modelContext, traceEvent); nodeDesign.DataTypePurpose = nodeSet.Purpose.ConvertToDataTypePurpose(); if (nodeSet.Purpose != XML.DataTypePurpose.Normal) { traceEvent(TraceMessage.DiagnosticTraceMessage($"DataTypePurpose value {nodeSet.Purpose } is not supported by the tool")); } }
private void Update(IDataTypeFactory nodeDesign, UADataType nodeSet) { nodeSet.Definition.GetParameters(nodeDesign.NewDefinition(), AS, Log.TraceEvent); nodeDesign.DataTypePurpose = nodeSet.Purpose.ConvertToDataTypePurpose(); if (nodeSet.Purpose != XML.DataTypePurpose.Normal) { Log.TraceEvent(TraceMessage.DiagnosticTraceMessage($"DataTypePurpose value {nodeSet.Purpose } is not supported by the tool")); } }
public static string GetNamespace(this UADataType dt, string[] namespaceUris) { if (dt.BrowseName != null && QualifiedName.TryParse(dt.BrowseName, out var bname) && bname.NamespaceIndex < namespaceUris.Length) { return(namespaceUris[bname.NamespaceIndex]); } return(null); }
public static string GetTypeName(this UADataType dt) { if (dt.SymbolicName != null) { return(dt.SymbolicName); } else if (dt.BrowseName != null && QualifiedName.TryParse(dt.BrowseName, out var bname)) { return(bname.Name.ToNetIdentifier()); } else { return(null); } }
private string getElementTypeName(UADataType dataType) { return dataType.ToString(); }
private static void Update(IDataTypeFactory nodeDesign, UADataType nodeSet, UAModelContext modelContext, Action <TraceMessage> traceEvent) { nodeSet.Definition.GetParameters(nodeDesign.NewDefinition(), modelContext, traceEvent); }
// OPC UA defines variables, views and objects, as well as associated variabletypes, datatypes, referencetypes and objecttypes // In addition, OPC UA defines methods and properties public static void Generate(UANodeSet nodeSet) { // clear previously generated DTDL _map.Clear(); _interfaceList.Clear(); _contentsList.Clear(); _nodeList.Clear(); _nodesetNamespaceURI = nodeSet.NamespaceUris[0]; CreateSchemaMap(); // create DTDL interfaces and their contents foreach (UANode uaNode in nodeSet.Items) { UAVariable variable = uaNode as UAVariable; if (variable != null) { if (uaNode.BrowseName.ToString() == "InputArguments") { continue; } // check if this node is part of the model bool isPartOfModel = false; foreach (Reference reference in variable.References) { if (reference.ReferenceType == "HasModellingRule") { isPartOfModel = true; break; } } if (isPartOfModel) { // ignore this node continue; } DtdlContents dtdlTelemetry = new DtdlContents { Type = "Telemetry", Name = Regex.Replace(uaNode.BrowseName.ToString().Trim(), "[^A-Za-z]+", ""), Schema = GetDtdlDataType(variable.DataType) }; Tuple <DtdlContents, string> newTuple = new Tuple <DtdlContents, string>(dtdlTelemetry, variable.ParentNodeId); if (!_contentsList.Contains(newTuple)) { _contentsList.Add(newTuple); } Tuple <string, string, string> newNodeTuple; if (variable.BrowseName.Length > 0) { newNodeTuple = new Tuple <string, string, string>(variable.BrowseName, GetDtdlDataType(variable.DataType.ToString()), variable.ParentNodeId ?? ""); } else { newNodeTuple = new Tuple <string, string, string>(variable.NodeId.ToString(), GetDtdlDataType(variable.DataType.ToString()), variable.ParentNodeId ?? ""); } string key = nodeSet.NamespaceUris[0] + "#" + variable.NodeId.ToString().Substring(variable.NodeId.ToString().IndexOf(';') + 1); if (!_nodeList.ContainsKey(key)) { _nodeList.Add(key, newNodeTuple); } continue; } UAMethod method = uaNode as UAMethod; if (method != null) { // check if this node is part of the model bool isPartOfModel = false; foreach (Reference reference in method.References) { if (reference.ReferenceType == "HasModellingRule") { isPartOfModel = true; break; } } if (isPartOfModel) { // ignore this node continue; } DtdlContents dtdlCommand = new DtdlContents { Type = "Command", Name = Regex.Replace(uaNode.BrowseName.ToString().Trim(), "[^A-Za-z]+", "") }; Tuple <DtdlContents, string> newTuple = new Tuple <DtdlContents, string>(dtdlCommand, method.ParentNodeId); if (!_contentsList.Contains(newTuple)) { _contentsList.Add(newTuple); } Tuple <string, string, string> newNodeTuple; if (method.BrowseName.Length > 0) { newNodeTuple = new Tuple <string, string, string>(method.BrowseName, "command", method.ParentNodeId ?? ""); } else { newNodeTuple = new Tuple <string, string, string>(method.NodeId.ToString(), "command", method.ParentNodeId ?? ""); } string key = nodeSet.NamespaceUris[0] + "#" + method.NodeId.ToString().Substring(method.NodeId.ToString().IndexOf(';') + 1); if (!_nodeList.ContainsKey(key)) { _nodeList.Add(key, newNodeTuple); } continue; } UAObject uaObject = uaNode as UAObject; if (uaObject != null) { // check if this node is part of the model bool isPartOfModel = false; foreach (Reference reference in uaObject.References) { if (reference.ReferenceType == "HasModellingRule") { isPartOfModel = true; break; } } if (isPartOfModel) { // ignore this node continue; } DtdlInterface dtdlInterface = new DtdlInterface { Id = "dtmi:" + Regex.Replace(uaNode.BrowseName.ToString().Trim(), "[^A-Za-z]+", "") + ";1", Type = "Interface", DisplayName = Regex.Replace(uaNode.BrowseName.ToString().Trim(), "[^A-Za-z]+", ""), Contents = new List <DtdlContents>() }; Tuple <DtdlInterface, string, string> newTuple = new Tuple <DtdlInterface, string, string>(dtdlInterface, uaObject.NodeId, uaObject.ParentNodeId); if (!_interfaceList.Contains(newTuple)) { _interfaceList.Add(newTuple); } Tuple <string, string, string> newNodeTuple; if (uaObject.BrowseName.Length > 0) { newNodeTuple = new Tuple <string, string, string>(uaObject.BrowseName, "object", uaObject.ParentNodeId ?? ""); } else { newNodeTuple = new Tuple <string, string, string>(uaObject.NodeId.ToString(), "object", uaObject.ParentNodeId ?? ""); } string key = nodeSet.NamespaceUris[0] + "#" + uaObject.NodeId.ToString().Substring(uaObject.NodeId.ToString().IndexOf(';') + 1); if (!_nodeList.ContainsKey(key)) { _nodeList.Add(key, newNodeTuple); } continue; } UAView view = uaNode as UAView; if (view != null) { // we don't map views since DTDL has no such concept continue; } UAVariableType variableType = uaNode as UAVariableType; if (variableType != null) { // we don't map UA variable types, only instances. DTDL only has a limited set of built-in types. continue; } UADataType dataType = uaNode as UADataType; if (dataType != null) { // we don't map UA data types, only instances. DTDL only has a limited set of built-in types. continue; } UAReferenceType referenceType = uaNode as UAReferenceType; if (referenceType != null) { // we don't map UA reference types, only instances. DTDL only has a limited set of built-in types. continue; } UAObjectType objectType = uaNode as UAObjectType; if (objectType != null) { // we don't map UA object (custom) types, only instances. DTDL only has a limited set of built-in types. continue; } throw new ArgumentException("Unknown UA node detected!"); } AddComponentsToInterfaces(); AddRelationshipsBetweenInterfaces(); // generate JSON files foreach (Tuple <DtdlInterface, string, string> dtdlInterfaceTuple in _interfaceList) { string generatedDTDL = JsonConvert.SerializeObject(dtdlInterfaceTuple.Item1, Formatting.Indented); string dtdlPath = Path.Combine(Directory.GetCurrentDirectory(), "JSON", Path.GetFileNameWithoutExtension(dtdlInterfaceTuple.Item1.DisplayName) + ".dtdl.json"); System.IO.File.WriteAllText(dtdlPath, generatedDTDL); } }
public NodeId GetParentId(UADataType dt) => dt.References .Where(r => r.ReferenceType == "HasSubtype") .Select(r => ParseNodeId(r.Value)) .FirstOrDefault();