/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns>true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false.</returns> public bool Equals(IUANodeBase other) { if (Object.ReferenceEquals(other, null)) { return(false); } return(this.BrowseName == other.BrowseName && this.ModelingRule == other.ModelingRule && this.UANode == other.UANode); }
void IUANodeBase.RemoveInheritedValues(IUANodeBase instanceDeclaration) { if (instanceDeclaration is null) { return; } this.UANode.RemoveInheritedValues(instanceDeclaration.UANode); if (this.ModelingRule == instanceDeclaration.ModelingRule) { this.ModelingRule = null; } }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns>true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false.</returns> public bool Equals(IUANodeBase other) { if (Object.ReferenceEquals(other, null)) { return(false); } if (this.BrowseName != other.BrowseName) { throw new ArgumentOutOfRangeException("The browse name of compared nodes musty be equal."); } return (this.UANode.Equals(other.UANode)); }
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); }
/// <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; } } }
private static void UpdateInstance(IInstanceFactory nodeDesign, UAInstance nodeSet, IUANodeBase nodeContext, Action <TraceMessage> traceEvent) { nodeDesign.ModelingRule = nodeContext.ModelingRule; nodeDesign.TypeDefinition = nodeContext.ExportBaseTypeBrowseName(false); //nodeSet.ParentNodeId - The NodeId of the Node that is the parent of the Node within the information model. This field is used to indicate //that a tight coupling exists between the Node and its parent (e.g. when the parent is deleted the child is deleted //as well). This information does not appear in the AddressSpace and is intended for use by design tools. }
private static void UpdateType(ITypeFactory nodeDesign, UAType nodeSet, IUANodeBase nodeContext, Action <TraceMessage> traceEvent) { nodeDesign.BaseType = nodeContext.ExportBaseTypeBrowseName(true); nodeDesign.IsAbstract = nodeSet.IsAbstract; }
private static void Update(IMethodInstanceFactory nodeDesign, UAMethod nodeSet, IUANodeBase nodeContext, UAReferenceContext parentReference, Action <TraceMessage> traceEvent) { if (nodeSet.ArgumentDescription != null) { foreach (UAMethodArgument _argument in nodeSet.ArgumentDescription) { if (_argument.Description == null) { continue; } foreach (XML.LocalizedText _description in _argument.Description) { nodeDesign.AddArgumentDescription(_argument.Name, _description.Locale, _description.Value); } } } nodeDesign.Executable = !nodeSet.Executable ? nodeSet.Executable : new Nullable <bool>(); nodeDesign.UserExecutable = !nodeSet.UserExecutable ? nodeSet.UserExecutable : new Nullable <bool>(); nodeDesign.MethodDeclarationId = nodeSet.MethodDeclarationId; nodeDesign.ReleaseStatus = nodeSet.ReleaseStatus.ConvertToReleaseStatus(); nodeDesign.AddInputArguments(x => nodeContext.GetParameters(x)); nodeDesign.AddOutputArguments(x => nodeContext.GetParameters(x)); }
private static void Update(IVariableTypeFactory nodeDesign, UAVariableType nodeSet, IUANodeBase nodeContext, Action <TraceMessage> traceEvent) { nodeDesign.ArrayDimensions = nodeSet.ArrayDimensions.ExportString(string.Empty); nodeDesign.DataType = nodeContext.ExportBrowseName(nodeSet.DataType, DataTypes.Number); nodeDesign.DefaultValue = nodeSet.Value; nodeDesign.ValueRank = nodeSet.ValueRank.GetValueRank(traceEvent); }
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(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> /// 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> /// <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"); } } }
private void UpdateType(ITypeFactory nodeDesign, UAType nodeSet, IUANodeBase nodeContext) { nodeDesign.BaseType = nodeContext.ExportBaseTypeBrowseName(true); nodeDesign.IsAbstract = nodeSet.IsAbstract; }
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))); } }
public IEnumerable <UAReferenceContext> GetMyReferences(IUANodeBase index) { List <UAReferenceContext> contexts = new List <UAReferenceContext>(); return(contexts); }