/// <summary> /// Processes the node references to calculate all relevant properties. Must be called after finishing import of all the parent models. /// </summary> /// <param name="nodeFactory">The node container.</param> /// <param name="traceEvent">A delegate <see cref="Action{TraceMessage}"/> encapsulates an action to report any errors and trace processing progress.</param> internal void CalculateNodeReferences(INodeFactory nodeFactory, Action <TraceMessage> traceEvent) { m_ModelingRule = new Nullable <ModelingRules>(); List <UAReferenceContext> _children = new List <UAReferenceContext>(); Dictionary <string, UANodeContext> _derivedChildren = null; foreach (UAReferenceContext _rfx in m_AddressSpaceContext.GetMyReferences(this)) { switch (_rfx.ReferenceKind) { case ReferenceKindEnum.Custom: XmlQualifiedName _ReferenceType = _rfx.GetReferenceTypeName(traceEvent); if (_ReferenceType == XmlQualifiedName.Empty) { BuildError _err = BuildError.DanglingReferenceTarget; traceEvent(TraceMessage.BuildErrorTraceMessage(_err, "Information")); } IReferenceFactory _or = nodeFactory.NewReference(); _or.IsInverse = !_rfx.Reference.IsForward; _or.ReferenceType = _ReferenceType; _or.TargetId = _rfx.BrowsePath(traceEvent); break; case ReferenceKindEnum.HasComponent: if (_rfx.SourceNodeContext == this) { _children.Add(_rfx); } break; case ReferenceKindEnum.HasProperty: if ((_rfx.SourceNodeContext == this) && (!(_rfx.SourceNodeContext.UANode is UADataType) || _rfx.TargetNodeContext.UANode.BrowseName.CompareTo("EnumStrings") != 0)) { _children.Add(_rfx); } break; case ReferenceKindEnum.HasModellingRule: m_ModelingRule = _rfx.GetModelingRule(); break; case ReferenceKindEnum.HasSubtype: //TODO Part 3 7.10 HasSubtype - add test cases #35 m_BaseTypeNode = _rfx.SourceNodeContext; break; case ReferenceKindEnum.HasTypeDefinition: //Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39 m_BaseTypeNode = _rfx.TargetNodeContext; _derivedChildren = _rfx.TargetNodeContext.GetDerivedChildren(); Debug.Assert(!IsProperty, "Has property "); m_IsProperty = _rfx.TargetNodeContext.IsPropertyVariableType; break; } } _children = _children.Where <UAReferenceContext>(x => _derivedChildren == null || !_derivedChildren.ContainsKey(x.TargetNodeContext.m_BrowseName.Name)).ToList <UAReferenceContext>(); foreach (UAReferenceContext _rc in _children) { Validator.ValidateExportNode(_rc.TargetNodeContext, nodeFactory, _rc, traceEvent); } }
internal static string ValidateIdentifier(this string name, Action <TraceMessage> reportError) { if (!name.IsValidLanguageIndependentIdentifier()) { reportError(TraceMessage.BuildErrorTraceMessage(BuildError.WrongSymbolicName, string.Format("SymbolicName: '{0}'.", name))); } return(name); }
internal static string ValidateIdentifier(this string name, Action <TraceMessage> reportError) { if (!System.CodeDom.Compiler.CodeGenerator.IsValidLanguageIndependentIdentifier(name)) { reportError(TraceMessage.BuildErrorTraceMessage(BuildError.WrongSymbolicName, String.Format("SymbolicName: '{0}'.", name))); } return(name); }
private static AccessRestrictions ConvertToAccessRestrictions(byte accessRestrictions, string typeName, Action <TraceMessage> traceEvent) { if (accessRestrictions > 7) { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongAccessLevel, $"The current value is {accessRestrictions} of the node type {typeName}. Assigned max value")); return(AccessRestrictions.EncryptionRequired & AccessRestrictions.SessionRequired & AccessRestrictions.SigningRequired); } return((AccessRestrictions)accessRestrictions); }
//methods /// <summary> /// Gets or sets the name of the m browse. /// </summary> /// <value>The name of the m browse.</value> private void TraceErrorUndefinedBaseType(NodeId target, bool type, Action <TraceMessage> traceEvent) { if (type) { string _msg = string.Format("BaseType of Id={0} for node {1}", target, this.BrowseName); traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.UndefinedHasSubtypeTarget, _msg)); } else { string _msg = string.Format("TypeDefinition of Id={0} for node {1}", target, this.BrowseName); traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.UndefinedHasTypeDefinition, _msg)); } }
private static FactoryType CreateNode <FactoryType, NodeSetType> ( Func <FactoryType> createNode, IUANodeBase nodeContext, Action <FactoryType, NodeSetType> updateNode, Action <FactoryType, NodeSetType, IUANodeBase, Action <TraceMessage> > updateBase, Action <TraceMessage> traceEvent ) where FactoryType : INodeFactory where NodeSetType : UANode { FactoryType _nodeFactory = createNode(); nodeContext.CalculateNodeReferences(_nodeFactory); NodeSetType _nodeSet = (NodeSetType)nodeContext.UANode; XmlQualifiedName _browseName = nodeContext.ExportNodeBrowseName(); string _symbolicName; if (string.IsNullOrEmpty(_nodeSet.SymbolicName)) { _symbolicName = _browseName.Name.ValidateIdentifier(traceEvent); //TODO IsValidLanguageIndependentIdentifier is not supported by the .NET standard #340 } else { _symbolicName = _nodeSet.SymbolicName.ValidateIdentifier(traceEvent); //TODO IsValidLanguageIndependentIdentifier is not supported by the .NET standard #340 } _nodeFactory.BrowseName = _browseName.Name.ExportString(_symbolicName); _nodeSet.Description.ExportLocalizedTextArray(_nodeFactory.AddDescription); _nodeSet.DisplayName.Truncate(512, traceEvent).ExportLocalizedTextArray(_nodeFactory.AddDisplayName); _nodeFactory.SymbolicName = new XmlQualifiedName(_symbolicName, _browseName.Namespace); Action <uint, string> _doReport = (x, y) => { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongWriteMaskValue, string.Format("The current value is {0:x} of the node type {1}.", x, y))); }; _nodeFactory.WriteAccess = _nodeSet is UAVariable?_nodeSet.WriteMask.Validate(0x200000, x => _doReport(x, _nodeSet.GetType().Name)) : _nodeSet.WriteMask.Validate(0x400000, x => _doReport(x, _nodeSet.GetType().Name)); _nodeFactory.AccessRestrictions = ConvertToAccessRestrictions(_nodeSet.AccessRestrictions, _nodeSet.GetType().Name, traceEvent); _nodeFactory.Category = _nodeSet.Category; if (_nodeSet.RolePermissions != null) { traceEvent(TraceMessage.DiagnosticTraceMessage("RolePermissions is not supported. You must fix it manually.")); } if (!string.IsNullOrEmpty(_nodeSet.Documentation)) { traceEvent(TraceMessage.DiagnosticTraceMessage("Documentation is not supported. You must fix it manually.")); } updateBase(_nodeFactory, _nodeSet, nodeContext, traceEvent); updateNode(_nodeFactory, _nodeSet); return(_nodeFactory); }
private static void Update(IVariableInstanceFactory nodeDesign, UAVariable nodeSet, IUANodeBase nodeContext, Action <TraceMessage> traceEvent) { nodeDesign.AccessLevel = nodeSet.AccessLevel.GetAccessLevel(traceEvent); nodeDesign.ArrayDimensions = nodeSet.ArrayDimensions.ExportString(string.Empty); nodeDesign.DataType = nodeContext.ExportBrowseName(nodeSet.DataType, DataTypes.Number); //TODO add test case must be DataType, must not be abstract nodeDesign.DefaultValue = nodeSet.Value; //TODO add test case must be of type defined by DataType nodeDesign.Historizing = nodeSet.Historizing.Export(false); nodeDesign.MinimumSamplingInterval = nodeSet.MinimumSamplingInterval.Export(0D); nodeDesign.ValueRank = nodeSet.ValueRank.GetValueRank(traceEvent); if (nodeSet.Translation != null) { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, "- the Translation element for the UAVariable")); } }
private static void Update(IReferenceTypeFactory nodeDesign, UAReferenceType nodeSet, Action <TraceMessage> traceEvent) { nodeSet.InverseName.ExportLocalizedTextArray(nodeDesign.AddInverseName); nodeDesign.Symmetric = nodeSet.Symmetric; if (nodeSet.Symmetric && (nodeSet.InverseName != null && nodeSet.InverseName.Where(x => !string.IsNullOrEmpty(x.Value)).Any())) { XML.LocalizedText _notEmpty = nodeSet.InverseName.Where(x => !string.IsNullOrEmpty(x.Value)).First(); traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongInverseName, string.Format("If ReferenceType {0} is symmetric the InverseName {1}:{2} shall be omitted.", nodeSet.NodeIdentifier(), _notEmpty.Locale, _notEmpty.Value))); } else if (!nodeSet.Symmetric && !nodeSet.IsAbstract && (nodeSet.InverseName == null || !nodeSet.InverseName.Where(x => !string.IsNullOrEmpty(x.Value)).Any())) { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongInverseName, string.Format("If ReferenceType {0} is not symmetric and not abstract the InverseName shall be specified.", nodeSet.NodeIdentifier()))); } }
/// <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 UANodeContext TryGetUANodeContext(NodeId nodeId, Action <TraceMessage> traceEvent) { UANodeContext _ret; if (!m_NodesDictionary.TryGetValue(nodeId.ToString(), out _ret)) { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdNotDefined, String.Format("References to node with NodeId: {0} is omitted during the import.", nodeId))); return(null); } if (_ret.UANode == null) { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdNotDefined, String.Format("NodeId: {0} is omitted during the import.", nodeId))); return(null); } return(_ret); }
private void Update(IPropertyInstanceFactory propertyInstance, UAVariable nodeSet, IUANodeBase nodeContext, UAReferenceContext parentReference) { try { Update(propertyInstance, nodeSet); propertyInstance.ReferenceType = parentReference == null ? null : parentReference.GetReferenceTypeName(); if (!nodeContext.IsProperty) { Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, $"Creating Property {nodeContext.BrowseName}- wrong reference type {parentReference.ReferenceKind.ToString()}")); } } catch (Exception _ex) { Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Property because of error {0} at: {1}.", _ex, _ex.StackTrace))); } }
private static void Update(IVariableInstanceFactory variableInstance, UAVariable nodeSet, IUANodeBase nodeContext, UAReferenceContext parentReference, Action <TraceMessage> traceEvent) { try { Update(variableInstance, nodeSet, nodeContext, traceEvent); variableInstance.ReferenceType = parentReference == null ? null : parentReference.GetReferenceTypeName(); if (nodeContext.IsProperty) { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Variable, string.Format("Creating Variable - wrong reference type {0}", parentReference.ReferenceKind.ToString()))); } } catch (Exception _ex) { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Variable because of error {0} at: {1}.", _ex, _ex.StackTrace))); } }
/// <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); }
/// <summary> /// Validates the selected nodes <paramref name="nodesCollection"/> and export it using <paramref name="exportModelFactory"/>. /// </summary> /// <param name="nodesCollection">The items <see cref="IEnumerable{IUANodeBase}" /> imported to the Address Space <see cref="IAddressSpaceContext" />.</param> /// <param name="exportModelFactory">The model export factory.</param> /// <param name="addressSpaceContext">The Address Space context.</param> /// <param name="traceEvent">The trace event method encapsulation.</param> internal static void ValidateExportModel(IEnumerable <IUANodeBase> nodesCollection, IModelFactory exportModelFactory, IAddressSpaceValidationContext addressSpaceContext, Action <TraceMessage> traceEvent) { traceEvent(TraceMessage.DiagnosticTraceMessage(string.Format("Entering Validator.ValidateExportModel - starting creation of the ModelDesign for {0} nodes.", nodesCollection.Count <IUANodeBase>()))); List <BuildError> _errors = new List <BuildError>(); //TODO should be added to the model; foreach (IModelTableEntry _ns in addressSpaceContext.ExportNamespaceTable) { string _publicationDate = _ns.PublicationDate.HasValue ? _ns.PublicationDate.Value.ToShortDateString() : DateTime.UtcNow.ToShortDateString(); string _version = _ns.Version; exportModelFactory.CreateNamespace(_ns.ModelUri, _publicationDate, _version); } string _msg = null; int _nc = 0; foreach (IUANodeBase _item in nodesCollection) { try { ValidateExportNode(_item, exportModelFactory, null, y => { if (y.TraceLevel != TraceEventType.Verbose) { _errors.Add(y.BuildError); } traceEvent(y); }); _nc++; } catch (Exception _ex) { _msg = string.Format("Error caught while processing the node {0}. The message: {1} at {2}.", _item.UANode.NodeId, _ex.Message, _ex.StackTrace); traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, _msg)); } } if (_errors.Count == 0) { _msg = string.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes.", _nc); } else { _msg = string.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes and {1} errors.", _nc, _errors.Count); } traceEvent(TraceMessage.DiagnosticTraceMessage(_msg)); }
/// <summary> /// Validates the selected nodes <paramref name="nodesCollection"/> and export it using <paramref name="exportModelFactory"/>. /// </summary> /// <param name="nodesCollection">The items <see cref="UANodeContext" /> imported to the Address Space <see cref="IAddressSpaceContext" />.</param> /// <param name="exportModelFactory">The model export factory.</param> /// <param name="addressSpaceContext">The Address Space context.</param> /// <param name="traceEvent">The trace event method encapsulation.</param> internal static void ValidateExportModel (IEnumerable <UANodeContext> nodesCollection, IModelFactory exportModelFactory, AddressSpaceContext addressSpaceContext, Action <TraceMessage> traceEvent) { traceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("Entering Validator.ValidateExportModel - starting creation of the ModelDesign for {0} nodes.", nodesCollection.Count <UANodeContext>()))); List <BuildError> _errors = new List <BuildError>(); //TODO should be added to the model; foreach (string _ns in addressSpaceContext.ExportNamespaceTable()) { exportModelFactory.CreateNamespace(_ns); } string _msg = null; int _nc = 0; foreach (UANodeContext _item in nodesCollection) { try { ValidateExportNode(_item, exportModelFactory, null, y => { if (y.TraceLevel != TraceEventType.Verbose) { _errors.Add(y.BuildError); } traceEvent(y); }); _nc++; } catch (Exception _ex) { _msg = String.Format("Error caught while processing the node {0}. The message: {1} at {2}.", _item.UANode.NodeId, _ex.Message, _ex.StackTrace); traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, _msg)); } } if (_errors.Count == 0) { _msg = String.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes.", _nc); } else { _msg = String.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes and {1} errors.", _nc, _errors.Count); } traceEvent(TraceMessage.DiagnosticTraceMessage(_msg)); }
/// <summary> /// Builds the symbolic identifier. /// </summary> /// <param name="path">The browse path.</param> /// <param name="traceEvent">A delegate <see cref="Action{TraceMessage}"/> encapsulates an action to report any errors and trace processing progress.</param> internal void BuildSymbolicId(List <string> path, Action <TraceMessage> traceEvent) { if (this.UANode == null) { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.DanglingReferenceTarget, "")); return; } IEnumerable <UAReferenceContext> _parentConnector = m_AddressSpaceContext.GetReferences2Me(this).Where <UAReferenceContext>(x => x.ChildConnector); Debug.Assert(_parentConnector.Count <UAReferenceContext>() <= 1); UAReferenceContext _connector = _parentConnector.FirstOrDefault <UAReferenceContext>(); if (_connector != null) { _connector.BuildSymbolicId(path, traceEvent); } string _BranchName = String.IsNullOrEmpty(this.UANode.SymbolicName) ? this.m_BrowseName.Name : this.UANode.SymbolicName; path.Add(_BranchName); }
/// <summary> /// Builds the symbolic identifier. /// </summary> /// <param name="path">The browse path.</param> public void BuildSymbolicId(List <string> path) { if (this.UANode == null) { Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.DanglingReferenceTarget, $"The target node NodeId={this.NodeIdContext}, current path {string.Join(", ", path)}")); return; } IEnumerable <UAReferenceContext> _parentConnector = m_AddressSpaceContext.GetReferences2Me(this).Where <UAReferenceContext>(x => x.ChildConnector); Debug.Assert(_parentConnector.Count <UAReferenceContext>() <= 1); //TODO #40; ValidateAndExportModel shall export also instances #40 UAReferenceContext _connector = _parentConnector.FirstOrDefault <UAReferenceContext>(); if (_connector != null) { _connector.BuildSymbolicId(path); } string _BranchName = string.IsNullOrEmpty(this.UANode.SymbolicName) ? this.BrowseName.Name : this.UANode.SymbolicName; path.Add(_BranchName); }
private static FactoryType CreateNode <FactoryType, NodeSetType> ( Func <FactoryType> createNode, UANodeContext nodeContext, Action <FactoryType, NodeSetType> updateNode, Action <FactoryType, NodeSetType, UANodeContext, Action <TraceMessage> > updateBase, Action <TraceMessage> traceEvent ) where FactoryType : INodeFactory where NodeSetType : UANode { FactoryType _nodeFactory = createNode(); nodeContext.CalculateNodeReferences(_nodeFactory, traceEvent); NodeSetType _nodeSet = (NodeSetType)nodeContext.UANode; XmlQualifiedName _browseName = nodeContext.ExportNodeBrowseName(); string _symbolicName; if (String.IsNullOrEmpty(_nodeSet.SymbolicName)) { _symbolicName = _browseName.Name.ValidateIdentifier(traceEvent); } else { _symbolicName = _nodeSet.SymbolicName.ValidateIdentifier(traceEvent); } _nodeFactory.BrowseName = _browseName.Name.ExportString(_symbolicName); _nodeSet.Description.ExportLocalizedTextArray(_nodeFactory.AddDescription); _nodeSet.DisplayName.Truncate(512, traceEvent).ExportLocalizedTextArray(_nodeFactory.AddDisplayName); _nodeFactory.SymbolicName = new XmlQualifiedName(_symbolicName, _browseName.Namespace); Action <UInt32, string> _doReport = (x, y) => { traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongWriteMaskValue, String.Format("The current value is {0:x} of the node type {1}.", x, y))); }; _nodeFactory.WriteAccess = _nodeSet is UAVariable?_nodeSet.WriteMask.Validate(0x200000, x => _doReport(x, _nodeSet.GetType().Name)) : _nodeSet.WriteMask.Validate(0x400000, x => _doReport(x, _nodeSet.GetType().Name)); updateBase(_nodeFactory, _nodeSet, nodeContext, traceEvent); updateNode(_nodeFactory, _nodeSet); return(_nodeFactory); }
private ushort ImportNamespaceIndex(ushort namespaceIndex) { // nothing special required for indexes < 0. if (namespaceIndex == 0) { return(namespaceIndex); } // return a new value if parameter is out of range. string _identifier = $"NameUnknown{m_NamespaceCount++}"; if (m_UANodeSetModel.NamespaceUris.Length > namespaceIndex - 1) { _identifier = m_UANodeSetModel.NamespaceUris[namespaceIndex - 1]; } else { BuildErrorsHandling.Log.TraceEvent( TraceMessage.BuildErrorTraceMessage(BuildError.UndefinedNamespaceIndex, $"ImportNamespaceIndex failed - namespace index {namespaceIndex-1} is out of the NamespaceUris index. New namespace {_identifier} is created insted.")); } return(AddressSpaceContext.GetIndexOrAppend(_identifier)); }
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)); } }
//methods private void ImportNodeSet(UANodeSet model) { if (model.ServerUris != null) { m_TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, "ServerUris is omitted during the import")); } if (model.Extensions != null) { m_TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NotSupportedFeature, "Extensions is omitted during the import")); } string _namespace = model.NamespaceUris == null?m_NamespaceTable.GetString(0) : model.NamespaceUris[0]; m_TraceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("Entering AddressSpaceContext.ImportNodeSet - starting import {0}.", _namespace))); UAModelContext _modelContext = new UAModelContext(model.Aliases, model.NamespaceUris, this); m_TraceEvent(TraceMessage.DiagnosticTraceMessage("AddressSpaceContext.ImportNodeSet - context for imported model is created and starting import nodes.")); foreach (UANode _nd in model.Items) { this.ImportUANode(_nd, _modelContext, m_TraceEvent); } m_TraceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("Finishing AddressSpaceContext.ImportNodeSet - imported {0} nodes.", model.Items.Length))); }
internal static XML.LocalizedText[] Truncate(this XML.LocalizedText[] localizedText, int maxLength, Action <TraceMessage> reportError) { if (localizedText == null || localizedText.Length == 0) { return(null); } List <XML.LocalizedText> _ret = new List <XML.LocalizedText>(); foreach (XML.LocalizedText _item in localizedText) { if (_item.Value.Length > maxLength) { reportError(TraceMessage.BuildErrorTraceMessage(BuildError.WrongDisplayNameLength, string.Format ("The localized text starting with '{0}:{1}' of length {2} is too long.", _item.Locale, _item.Value.Substring(0, 20), _item.Value.Length))); XML.LocalizedText _localizedText = new XML.LocalizedText() { Locale = _item.Locale, Value = _item.Value.Substring(0, maxLength) }; } } return(localizedText); }
/// <summary> /// Validates <paramref name="nodeContext" /> and exports it using an object of <see cref="IModelFactory" /> type. /// </summary> /// <param name="nodeContext">The node context to be validated and exported.</param> /// <param name="exportFactory">A model export factory.</param> /// <param name="parentReference">The reference to parent node.</param> /// <exception cref="ApplicationException">In {nameof(ValidateExportNode)}</exception> public void ValidateExportNode(IUANodeBase nodeContext, INodeContainer exportFactory, UAReferenceContext parentReference) { Debug.Assert(nodeContext != null, "Validator.ValidateExportNode the argument nodeContext is null."); //TODO Handle HasComponent ReferenceType errors. #42 if (Object.ReferenceEquals(nodeContext.UANode, null)) { string _msg = string.Format("The node {0} is undefined", nodeContext.NodeIdContext); BuildError _be = null; if (parentReference == null || parentReference.ReferenceKind == ReferenceKindEnum.HasProperty) { _be = BuildError.UndefinedHasPropertyTarget; } else { _be = BuildError.UndefinedHasComponentTarget; } TraceMessage _traceMessage = TraceMessage.BuildErrorTraceMessage(_be, _msg); Log.TraceEvent(_traceMessage); CreateModelDesignStub(exportFactory); } else { switch (nodeContext.UANode.NodeClassEnum) { case NodeClassEnum.UADataType: CreateNode <IDataTypeFactory, UADataType>(exportFactory.AddNodeFactory <IDataTypeFactory>, nodeContext, (x, y) => Update(x, y), UpdateType); break; case NodeClassEnum.UAMethod: CreateNode <IMethodInstanceFactory, UAMethod>(exportFactory.AddNodeFactory <IMethodInstanceFactory>, nodeContext, (x, y) => Update(x, y, parentReference), UpdateInstance); break; case NodeClassEnum.UAObject: CreateNode <IObjectInstanceFactory, UAObject>(exportFactory.AddNodeFactory <IObjectInstanceFactory>, nodeContext, (x, y) => Update(x, y), UpdateInstance); break; case NodeClassEnum.UAObjectType: CreateNode <IObjectTypeFactory, UAObjectType>(exportFactory.AddNodeFactory <IObjectTypeFactory>, nodeContext, Update, UpdateType); break; case NodeClassEnum.UAReferenceType: CreateNode <IReferenceTypeFactory, UAReferenceType>(exportFactory.AddNodeFactory <IReferenceTypeFactory>, nodeContext, (x, y) => Update(x, y), UpdateType); break; case NodeClassEnum.UAVariable: if (parentReference.ReferenceKind == ReferenceKindEnum.HasProperty) { CreateNode <IPropertyInstanceFactory, UAVariable>(exportFactory.AddNodeFactory <IPropertyInstanceFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, parentReference), UpdateInstance); } else { CreateNode <IVariableInstanceFactory, UAVariable>(exportFactory.AddNodeFactory <IVariableInstanceFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, parentReference), UpdateInstance); } break; case NodeClassEnum.UAVariableType: CreateNode <IVariableTypeFactory, UAVariableType>(exportFactory.AddNodeFactory <IVariableTypeFactory>, nodeContext, (x, y) => Update(x, y), UpdateType); break; case NodeClassEnum.UAView: CreateNode <IViewInstanceFactory, UAView>(exportFactory.AddNodeFactory <IViewInstanceFactory>, nodeContext, (x, y) => Update(x, y), UpdateInstance); break; case NodeClassEnum.Unknown: throw new ApplicationException($"In {nameof(ValidateExportNode)} unexpected NodeClass value"); } } }
/// <summary> /// Processes the node references to calculate all relevant properties. Must be called after finishing import of all the parent models. /// </summary> /// <param name="nodeFactory">The node container.</param> /// <param name="validator">The validator.</param> /// <exception cref="ArgumentNullException"><paramref name="nodeFactory"/> must not be null.</exception> void IUANodeBase.CalculateNodeReferences(INodeFactory nodeFactory, IValidator validator) { if (nodeFactory == null) { throw new ArgumentNullException(nameof(nodeFactory), $"{nodeFactory} must not be null in {nameof(IUANodeBase.CalculateNodeReferences)}"); } if (validator is null) { throw new ArgumentNullException(nameof(validator), $"{nameof(validator)} must not be null in {nameof(IUANodeBase.CalculateNodeReferences)}"); } List <UAReferenceContext> _children = new List <UAReferenceContext>(); foreach (UAReferenceContext _rfx in m_AddressSpaceContext.GetMyReferences(this)) { switch (_rfx.ReferenceKind) { case ReferenceKindEnum.Custom: XmlQualifiedName _ReferenceType = _rfx.GetReferenceTypeName(); if (_ReferenceType == XmlQualifiedName.Empty) { BuildError _err = BuildError.DanglingReferenceTarget; Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(_err, "Information")); } IReferenceFactory _or = nodeFactory.NewReference(); _or.IsInverse = !_rfx.Reference.IsForward; _or.ReferenceType = _ReferenceType; _or.TargetId = _rfx.BrowsePath(); break; case ReferenceKindEnum.HasComponent: if (_rfx.SourceNode == this) { _children.Add(_rfx); } break; case ReferenceKindEnum.HasProperty: if ((_rfx.SourceNode == this) && (_rfx.SourceNode.UANode.NodeClassEnum != NodeClassEnum.UADataType)) { _children.Add(_rfx); } break; case ReferenceKindEnum.HasModellingRule: break; case ReferenceKindEnum.HasSubtype: break; case ReferenceKindEnum.HasTypeDefinition: //Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39 IsProperty = _rfx.TargetNode.IsPropertyVariableType; break; } } Dictionary <string, IUANodeBase> _derivedChildren = m_BaseTypeNode == null ? new Dictionary <string, IUANodeBase>() : m_BaseTypeNode.GetDerivedInstances(); foreach (UAReferenceContext _rc in _children) { try { IUANodeBase _instanceDeclaration = null; if (!string.IsNullOrEmpty(_rc.TargetNode.BrowseName.Name)) { _instanceDeclaration = _derivedChildren.ContainsKey(_rc.TargetNode.BrowseName.Name) ? _derivedChildren[_rc.TargetNode.BrowseName.Name] : null; } if (_rc.TargetNode.Equals(_instanceDeclaration)) { continue; } _rc.TargetNode.RemoveInheritedValues(_instanceDeclaration); validator.ValidateExportNode(_rc.TargetNode, nodeFactory, _rc); } catch (Exception) { throw; } } }
/// <summary> /// Validates <paramref name="nodeContext"/> and exports it using an object of <see cref="IModelFactory"/> type. /// </summary> /// <param name="nodeContext">The node context to be validated and exported.</param> /// <param name="exportFactory">A model export factory.</param> /// <param name="parentReference">The reference to parent node.</param> /// <param name="traceEvent">The trace event.</param> /// <returns>An object of <see cref="INodeFactory"/>.</returns> internal static void ValidateExportNode(IUANodeBase nodeContext, INodeContainer exportFactory, UAReferenceContext parentReference, Action <TraceMessage> traceEvent) { Debug.Assert(nodeContext != null, "Validator.ValidateExportNode the argument nodeContext is null."); //TODO Handle HasComponent ReferenceType errors. #42 if (nodeContext.UANode == null) { string _msg = string.Format("The node {0} is undefined", nodeContext.NodeIdContext); BuildError _be = null; if (parentReference == null || parentReference.ReferenceKind == ReferenceKindEnum.HasProperty) { _be = BuildError.UndefinedHasPropertyTarget; } else { _be = BuildError.UndefinedHasComponentTarget; } TraceMessage _traceMessage = TraceMessage.BuildErrorTraceMessage(_be, _msg); traceEvent(_traceMessage); CreateModelDesignStub(exportFactory); } else { string nodeType = nodeContext.UANode.GetType().Name; switch (nodeType) { case "UAReferenceType": CreateNode <IReferenceTypeFactory, UAReferenceType>(exportFactory.AddNodeFactory <IReferenceTypeFactory>, nodeContext, (x, y) => Update(x, y, traceEvent), UpdateType, traceEvent); break; case "UADataType": CreateNode <IDataTypeFactory, UADataType>(exportFactory.AddNodeFactory <IDataTypeFactory>, nodeContext, (x, y) => Update(x, y, nodeContext.UAModelContext, traceEvent), UpdateType, traceEvent); break; case "UAVariableType": CreateNode <IVariableTypeFactory, UAVariableType>(exportFactory.AddNodeFactory <IVariableTypeFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, traceEvent), UpdateType, traceEvent); break; case "UAObjectType": CreateNode <IObjectTypeFactory, UAObjectType>(exportFactory.AddNodeFactory <IObjectTypeFactory>, nodeContext, Update, UpdateType, traceEvent); break; case "UAView": CreateNode <IViewInstanceFactory, UAView>(exportFactory.AddNodeFactory <IViewInstanceFactory>, nodeContext, (x, y) => Update(x, y, traceEvent), UpdateInstance, traceEvent); break; case "UAMethod": CreateNode <IMethodInstanceFactory, UAMethod>(exportFactory.AddNodeFactory <IMethodInstanceFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, parentReference, traceEvent), UpdateInstance, traceEvent); break; case "UAVariable": if (parentReference == null || parentReference.ReferenceKind == ReferenceKindEnum.HasProperty) { CreateNode <IPropertyInstanceFactory, UAVariable>(exportFactory.AddNodeFactory <IPropertyInstanceFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, parentReference, traceEvent), UpdateInstance, traceEvent); } else { CreateNode <IVariableInstanceFactory, UAVariable>(exportFactory.AddNodeFactory <IVariableInstanceFactory>, nodeContext, (x, y) => Update(x, y, nodeContext, parentReference, traceEvent), UpdateInstance, traceEvent); } break; case "UAObject": CreateNode <IObjectInstanceFactory, UAObject>(exportFactory.AddNodeFactory <IObjectInstanceFactory>, nodeContext, (x, y) => Update(x, y, traceEvent), UpdateInstance, traceEvent); break; default: Debug.Assert(false, "Wrong node type"); break; } } }