private static AssetRef createAssetRef(UANode node) { //AssetRef // -> Key (multiple) AssetRef ass = new AssetRef(); var keys = addSemanticID(node); foreach (Key key in keys) { ass.Keys.Add(key); } return(ass); }
private static List <Key> addSemanticID(UANode sem) { //SemanticId // -> Key (multiple) // -> idType // -> Local // -> Type // -> Value List <Key> keys = new List <Key>(); foreach (Reference _ref in sem.References) { if (_ref.ReferenceType != "HasTypeDefinition" && getTypeDefinition(findNode(_ref.Value)) == "1:AASKeyType") { UAVariable key = (UAVariable)findNode(_ref.Value); Key _key = new Key(); foreach (Reference _InnerRef in key.References) { if (_InnerRef.ReferenceType != "HasTypeDefinition") { UAVariable value = (UAVariable)findNode(_InnerRef.Value); switch (value.BrowseName) { case "1:IdType": _key.idType = value.Value.InnerText; break; case "1:Local": _key.local = bool.Parse(value.Value.InnerText); break; case "1:Type": _key.type = value.Value.InnerText; break; case "1:Value": _key.value = value.Value.InnerText; break; } } } keys.Add(_key); } } return(keys); }
/// <summary> /// Updates this instance in case the wrapped <see cref="UANode" /> is recognized in the model. /// </summary> /// <param name="node">The node <see cref="UANode" /> containing definition to be added to the model.</param> /// <param name="addReference">Used to add new reference to the common collection of references.</param> /// <exception cref="ArgumentException">node - Argument must not be null</exception> public void Update(UANode node, Action <UAReferenceContext> addReference) { if (node == null) { throw new ArgumentException(nameof(node), $"Argument must not be null at {nameof(Update)} "); } if (this.UANode != null) { Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdDuplicated, string.Format("The {0} is already defined and is removed from further processing.", node.NodeId.ToString()))); return; } UANode = node; this.BrowseName = node.BrowseName.Parse(Log.TraceEvent); if (QualifiedName.IsNull(this.BrowseName)) { NodeId _id = NodeId.Parse(UANode.NodeId); this.BrowseName = new QualifiedName($"EmptyBrowseName_{_id.IdentifierPart}", _id.NamespaceIndex); Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, $"New identifier {this.BrowseName} is generated to proceed.")); } if (node.References == null) { return; } foreach (Reference _reference in node.References) { UAReferenceContext _newReference = new UAReferenceContext(_reference, this.m_AddressSpaceContext, this); switch (_newReference.ReferenceKind) { case ReferenceKindEnum.Custom: case ReferenceKindEnum.HasComponent: case ReferenceKindEnum.HasProperty: break; case ReferenceKindEnum.HasModellingRule: ModelingRule = _newReference.GetModelingRule(); break; case ReferenceKindEnum.HasSubtype: //TODO Part 3 7.10 HasSubtype - add test cases #35 m_BaseTypeNode = _newReference.SourceNode; break; case ReferenceKindEnum.HasTypeDefinition: //Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39 m_BaseTypeNode = _newReference.TargetNode; break; } addReference(_newReference); } }
private static HasDataSpecification CreateHasDataSpecification(UANode spec) { //HasDataSpecification (spec) // -> Reference (mupltiple) HasDataSpecification data = new HasDataSpecification(); foreach (Reference _ref in spec.References) { if (_ref.ReferenceType != "HasTypeDefinition") { data.reference.Add(createReference(findNode(_ref.Value))); } } return(data); }
private static SubmodelElementCollection setCollection(UANode node) { //Collection // -> SubmodelElement (multiple) SubmodelElementCollection coll = new SubmodelElementCollection(); foreach (Reference _ref in node.References) { if (_ref.ReferenceType == "HasComponent") { coll.value.Add(createSubmodelElement(findNode(_ref.Value))); } } return(coll); }
//Create Views private static Views createViews(UANode node) { // Views views = new AdminShellV20.Views(); foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { views.views.Add(createView(findNode(_ref.Value))); } } return(views); }
private static Identification GetIdentification(UANode submodel) { //AASIdentifiable // -> AASIdentifierType // -> Id // -> IdType //get AASIdentifiable node UANode iden = null; foreach (Reference _ref in submodel.References) { if (_ref.ReferenceType == "HasInterface") { iden = findNode(_ref.Value); } } Identification identification = new Identification(); foreach (Reference _ref in iden.References) { if (_ref.ReferenceType != "HasTypeDefinition") { if (getTypeDefinition(findNode(_ref.Value)) == "1:AASIdentifierType") { var val = (UAVariable)findNode(_ref.Value); foreach (Reference _refref in val.References) { if (_refref.ReferenceType == "HasProperty") { UAVariable node = (UAVariable)findNode(_refref.Value); if (node.BrowseName == "1:Id") { identification.id = node.Value.InnerText; } if (node.BrowseName == "1:IdType") { identification.idType = node.Value.InnerText; } } } } } } return(identification); }
/// <summary> /// Updates this instance in case the wrapped <see cref="UANode"/> is recognized in the model. /// </summary> /// <param name="node">The node <see cref="UANode"/> containing definition to be added to the model.</param> void IUANodeContext.Update(UANode node) { if (node == null) { return; } UANode = node; QualifiedName _broseName = node.BrowseName.Parse(BuildErrorsHandling.Log.TraceEvent); Debug.Assert(BrowseName != null); if (QualifiedName.IsNull(_broseName)) { NodeId _id = NodeId.Parse(UANode.NodeId); _broseName = new QualifiedName(string.Format("EmptyBrowseName{0}", _id.IdentifierPart), _id.NamespaceIndex); BuildErrorsHandling.Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, string.Format("New identifier {0} is generated to proceed.", _broseName))); } BrowseName = UAModelContext.ImportQualifiedName(_broseName); }
/// <summary> /// Updates this instance in case the wrapped <see cref="UANode"/> is recognized in the model. /// </summary> /// <param name="node">The node <see cref="UANode"/> containing definition to be added to the model.</param> /// <param name="traceEvent">A delegate <see cref="Action{TraceMessage}"/> encapsulates an action to report any errors and trace processing progress.</param> internal void Update(UANode node, Action <TraceMessage> traceEvent) { if (node == null) { return; } m_UAnode = node; QualifiedName _broseName = node.BrowseName.Parse(traceEvent); Debug.Assert(m_BrowseName != null); if (QualifiedName.IsNull(_broseName)) { NodeId _id = NodeId.Parse(UANode.NodeId); _broseName = new QualifiedName(string.Format("EmptyBrowseName{0}", _id.IdentifierPart), _id.NamespaceIndex); traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, String.Format("New identifier {0} is generated to proceed.", _broseName))); } m_BrowseName = m_ModelContext.ImportQualifiedName(_broseName); }
internal override void RemoveInheritedValues(UANode baseNode) { base.RemoveInheritedValues(baseNode); UAVariable _other = baseNode as UAVariable; if (baseNode is null) { throw new System.ArgumentNullException($"{nameof(baseNode)}", $"The parameter of the {nameof(RemoveInheritedValues)} must not be null"); } if (this.DataType == _other.DataType) { this.DataType = null; } if (this.ArrayDimensions == _other.ArrayDimensions) { this.ArrayDimensions = string.Empty; } }
//Create Submodel Elements private static AdminShellV20.SubmodelElementWrapper createSubmodelElement(UANode node) { //Parent (node) // -> SemanticId // -> Category (Property) // -> Qualifier // -> Kind (Property) // -> DataNode (Same name as Type) AdminShellV20.SubmodelElementWrapper wrapper = new AdminShellV20.SubmodelElementWrapper(); wrapper.submodelElement = new SubmodelElement(); List <Key> keys = new List <Key>(); QualifierCollection quals = new QualifierCollection(); foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { var val = findNode(_ref.Value); string type = getTypeDefinition(val); if (type == "1:AASSemanticIdType") { keys = addSemanticID((UAVariable)val); } else if (getTypeDefinition(val) == "1:AASQualifierType") { quals.Add(getQualifier(val)); } else { setElementData(findNode(_ref.Value), wrapper); } } } wrapper.submodelElement.idShort = makePretty(node.BrowseName); wrapper.submodelElement.semanticId = SemanticId.CreateFromKeys(keys); wrapper.submodelElement.kind = getKind(node); wrapper.submodelElement.category = getCategory(node); wrapper.submodelElement.qualifiers = quals; return(wrapper); }
/// <summary> /// Indicates whether the the inherited parent object is also equal to another object. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// <c>true</c> if the current object is equal to the <paramref name="other">other</paramref>; otherwise,, <c>false</c> otherwise.</returns> protected override bool ParentEquals(UANode other) { UAVariable _other = other as UAVariable; if (_other == null) { return(false); } return (base.ParentEquals(_other) && //TODO compare Value, Translation this.DataType == _other.DataType && this.ValueRank == _other.ValueRank && this.ArrayDimensions == _other.ArrayDimensions && this.AccessLevel == _other.AccessLevel && this.UserAccessLevel == _other.UserAccessLevel && this.MinimumSamplingInterval == _other.MinimumSamplingInterval && this.Historizing == _other.Historizing); }
private static ReferenceElement setReferenceElement(UANode node) { //ReferenceElement // -> Value ReferenceElement refEle = new ReferenceElement(); foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { UAVariable var = (UAVariable)findNode(_ref.Value); string val = var.Value.InnerText; //convert String into Reference refEle.value = createReference(val); } } return(refEle); }
private static View createView(UANode node) { //View (node) // -> ContainedElementRef // -> Key (multiple) View view = new View(); view.idShort = makePretty(node.BrowseName); foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { view.AddContainedElement(addSemanticID(findNode(_ref.Value))); } } return(view); }
private static AdminShellV20.ModelingKind getKind(UANode node) { //Parent (node) // -> Kind (Property) ModelingKind kind = new ModelingKind(); foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { UANode val = findNode(_ref.Value); if (getTypeDefinition(val) == "1:AASModelingKindDataType") { UAVariable var = (UAVariable)val; kind.kind = var.Value.InnerText; } } } return(kind); }
//Create Parameters private static string getCategory(UANode node) { //Parent (node) // -> Category (Property, String) string cat = null; foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { UANode val = findNode(_ref.Value); if (val.BrowseName == "1:Category") { UAVariable var = (UAVariable)val; cat = var.Value.InnerText; } } } return(cat); }
private void ImportUANode(UANode node, UAModelContext modelContext, Action <TraceMessage> traceEvent) { try { if (node == null) { m_TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeCannotBeNull, "At Importing UANode.")); } NodeId nodeId = modelContext.ImportNodeId(node.NodeId, false, m_TraceEvent); UANodeContext _newNode = null; string nodeIdKey = nodeId.ToString(); if (!m_NodesDictionary.TryGetValue(nodeIdKey, out _newNode)) { _newNode = new UANodeContext(this, modelContext, nodeId); _newNode.Update(node, traceEvent); m_NodesDictionary.Add(nodeIdKey, _newNode); } else { if (_newNode.UANode != null) { m_TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdDuplicated, String.Format("The {0} is already defined.", node.NodeId.ToString()))); } _newNode.Update(node, traceEvent); } foreach (Reference _rf in node.References) { UAReferenceContext _rs = UAReferenceContext.NewReferenceStub(_rf, this, modelContext, _newNode, m_TraceEvent); if (!m_References.ContainsKey(_rs.Key)) { m_References.Add(_rs.Key, _rs); } } } catch (Exception _ex) { string _msg = String.Format("ImportUANode {1} is interrupted by exception {0}", _ex.Message, node.NodeId); m_TraceEvent(TraceMessage.DiagnosticTraceMessage(_msg)); } }
private static void setIdentifiable(Asset asset, UANode node) { //AASIdentifiable (node) // -> AASAdministrativeInformationType (var) // -> AASIdentifieryType (var) foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { UANode var = findNode(_ref.Value); if (getTypeDefinition(var) == "1:AASAdministrativeInformationType") { asset.administration = createAdmninistration(var); } if (getTypeDefinition(var) == "1:AASIdentifierType") { asset.identification = createIdentification(var); } } } }
private static Qualifier getQualifier(UANode node) { //Qualifier // -> QualifierType (Property) // -> QualifierValue (Property) // -> Key (multiple) Qualifier qual = new Qualifier(); List <Key> keys = new List <Key>(); //create Keys keys = addSemanticID(node); foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { if (_ref.ReferenceType == "HasComponent") { } else { UAVariable var = (UAVariable)findNode(_ref.Value); if (var.BrowseName == "1:QualifierType") { qual.type = var.Value.InnerText; } if (var.BrowseName == "1:QualifierValue") { qual.value = var.Value.InnerText; } } } } qual.semanticId = SemanticId.CreateFromKeys(keys); return(qual); }
private static ListOfLangStr getDescription(UANode node) { //Parent (node) // -> AASLangStrSet (val) (multiple) // -> Language (var) // -> String (var) ListOfLangStr str = new ListOfLangStr(); foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { UANode val = findNode(_ref.Value); LangStr v = new LangStr(); foreach (Reference _refref in val.References) { if (_refref.ReferenceType != "HasTypeDefinition") { UAVariable var = (UAVariable)findNode(_refref.Value); if (var.BrowseName == "1:Language") { v.lang = var.Value.InnerText; } if (var.BrowseName == "1:String") { v.str = var.Value.InnerText; } } } str.Add(v); } } return(str); }
private static void setIECSpec(UANode node, ConceptDescription desc) { //DataSpecificationIEC61360 // -> many, many parameters foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { foreach (Reference _refref in findNode(_ref.Value).References) { if (_refref.ReferenceType != "HasTypeDefinition") { if (_refref.ReferenceType == "HasProperty") { UAVariable var = (UAVariable)findNode(_refref.Value); if (var.BrowseName == "1:DataType") { desc.embeddedDataSpecification .dataSpecificationContent .dataSpecificationIEC61360 .dataType = var.Value.InnerText; } if (var.BrowseName == "1:Symbol") { desc.embeddedDataSpecification .dataSpecificationContent .dataSpecificationIEC61360 .symbol = var.Value.InnerText; } if (var.BrowseName == "1:Unit") { desc.embeddedDataSpecification .dataSpecificationContent .dataSpecificationIEC61360 .unit = var.Value.InnerText; } if (var.BrowseName == "1:ValueFormat") { desc.embeddedDataSpecification .dataSpecificationContent .dataSpecificationIEC61360 .valueFormat = var.Value.InnerText; } if (var.BrowseName == "1:IdShort ") { desc.idShort = var.Value.InnerText; } if (var.BrowseName == "1:Category ") { desc.category = var.Value.InnerText; } } else if (_refref.ReferenceType == "HasComponent") { UANode obj = findNode(_refref.Value); if (obj.BrowseName == "1:Definition") { desc.embeddedDataSpecification .dataSpecificationContent .dataSpecificationIEC61360 .definition .langString = getDescription(obj); } if (obj.BrowseName == "1:PreferredName") { desc.embeddedDataSpecification .dataSpecificationContent .dataSpecificationIEC61360 .preferredName .langString = getDescription(obj); } } } } } } desc.SetAdminstration("2.0", "1"); desc.SetIdentification( "URI", "http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/2/0"); }
private static ConceptDescription createConceptDescription(UANode node, string name) { //ConceptDescription // -> AASIdentifiable // -> Identification // -> Administration // -> DataSpecification // -> DataSpecificationIEC61360 ConceptDescription desc = new ConceptDescription(); Administration admin = new Administration(); Identification iden = new Identification(); var esc = EmbeddedDataSpecification.CreateIEC61360WithContent(); esc.dataSpecificationContent.dataSpecificationIEC61360.shortName = new LangStringSetIEC61360("EN?", makePretty(name)); desc.embeddedDataSpecification = new HasDataSpecification(); desc.embeddedDataSpecification.Add(esc); foreach (Reference _ref in node.References) { if (_ref.ReferenceType != "HasTypeDefinition") { UANode val = findNode(_ref.Value); if (getTypeDefinition(val) == "1:IAASIdentifiableType") { foreach (Reference _refref in val.References) { if (_refref.ReferenceType != "HasTypeDefinition") { UANode var = findNode(_refref.Value); if (getTypeDefinition(var) == "1:AASIdentifierType") { iden = createIdentification(var); } if (getTypeDefinition(var) == "1:AASAdministrativeInformationType") { admin = createAdmninistration(var); } } } } if (getTypeDefinition(val) == "1:AASDataSpecificationType") { foreach (Reference _refref in val.References) { if (_refref.ReferenceType == "HasComponent") { setIECSpec(findNode(_ref.Value), desc); } } } } } desc.identification = iden; desc.administration = admin; return(desc); }