Beispiel #1
0
        public void ExportBrowseNameTest()
        {
            UANodeSet _tm = TestData.CreateNodeSetModel();
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();

            _asMock.Setup(x => x.GetNamespace(0)).Returns <ushort>(x => "tempuri.org");
            UANode _nodeFactory = new UAVariable()
            {
                NodeId       = "ns=1;i=47",
                BrowseName   = "EURange",
                ParentNodeId = "ns=1;i=43",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };
            UANodeContext _node = new UANodeContext(NodeId.Parse("ns=1;i=47"), _asMock.Object);

            _node.Update(_nodeFactory, x => Assert.Fail());
            XmlQualifiedName _resolvedName = _node.ExportNodeBrowseName();

            _asMock.Verify(x => x.GetNamespace(0), Times.Once);
            Assert.IsNotNull(_resolvedName);
            Assert.AreEqual <string>("tempuri.org:EURange", _resolvedName.ToString());
        }
Beispiel #2
0
        public void ConstructorNodeIdTest()
        {
            Mock <IAddressSpaceBuildContext> _addressSpaceMock = new Mock <IAddressSpaceBuildContext>();
            UANodeContext _toTest = new UANodeContext(NodeId.Parse("ns=1;i=11"), _addressSpaceMock.Object);

            Assert.IsNotNull(_toTest.BrowseName);
            Assert.IsTrue(new QualifiedName() == _toTest.BrowseName);
            Assert.IsFalse(_toTest.InRecursionChain);
            Assert.IsFalse(_toTest.IsProperty);
            Assert.IsFalse(((IUANodeBase)_toTest).IsPropertyVariableType);
            Assert.IsFalse(_toTest.ModelingRule.HasValue);
            Assert.IsNotNull(_toTest.NodeIdContext);
            Assert.IsTrue(_toTest.NodeIdContext.ToString() == "ns=1;i=11");
            Assert.IsNull(_toTest.UANode);
            XML.UANode _node = UnitTest.Helpers.TestData.CreateUAObject();
            int        _registerReferenceCounter = 0;

            _toTest.Update(_node, x => _registerReferenceCounter++);
            Assert.AreEqual <int>(2, _registerReferenceCounter);
            Assert.IsNotNull(_toTest.BrowseName);
            Assert.AreEqual <QualifiedName>(new QualifiedName("NewUAObject", 1), _toTest.BrowseName);
            Assert.IsFalse(_toTest.InRecursionChain);
            Assert.IsFalse(_toTest.IsProperty);
            Assert.IsFalse(((IUANodeBase)_toTest).IsPropertyVariableType);
            Assert.IsFalse(_toTest.ModelingRule.HasValue);
            Assert.IsNotNull(_toTest.NodeIdContext);
            Assert.AreEqual <string>(_toTest.NodeIdContext.ToString(), "ns=1;i=11");
            Assert.IsNotNull(_toTest.UANode);
        }
Beispiel #3
0
        public void UpdateDuplicatedNodeIdTest()
        {
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            UANodeContext _newNode = new UANodeContext(NodeId.Parse("ns=1;i=11"), _asMock.Object);
            Mock <IBuildErrorsHandling> _traceMock   = new Mock <IBuildErrorsHandling>();
            List <TraceMessage>         _traceBuffer = new List <TraceMessage>();

            _traceMock.Setup(x => x.TraceEvent(It.IsAny <TraceMessage>())).Callback <TraceMessage>(x => _traceBuffer.Add(x));
            _newNode.Log = _traceMock.Object;
            UAVariable _nodeFactory = new UAVariable()
            {
                NodeId       = "ns=1;i=47",
                BrowseName   = "EURange",
                ParentNodeId = "ns=1;i=43",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };

            _newNode.Update(_nodeFactory, x => Assert.Fail());
            _newNode.Update(_nodeFactory, x => Assert.Fail());
            Assert.AreEqual <int>(1, _traceBuffer.Count);
            Assert.AreEqual <string>(_traceBuffer[0].BuildError.Identifier, BuildError.NodeIdDuplicated.Identifier);
        }
Beispiel #4
0
        public void RemoveInheritedValuesTest()
        {
            UAVariable _derivedNode = new UAVariable()
            {
                NodeId      = "ns=1;i=47", BrowseName = "EURange", ParentNodeId = "ns=1;i=43", DataType = "i=884",
                DisplayName = new XML.LocalizedText[] { new XML.LocalizedText()
                                                        {
                                                            Value = "EURange"
                                                        } }
            };
            UANode _baseNode = new UAVariable()
            {
                NodeId      = "i=17568", BrowseName = "EURange", ParentNodeId = "i=15318", DataType = "i=884",
                DisplayName = new XML.LocalizedText[] { new XML.LocalizedText()
                                                        {
                                                            Value = "EURange"
                                                        } }
            };
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            IUANodeContext _derivedNodeContext       = new UANodeContext(NodeId.Parse("ns=1;i=47"), _asMock.Object);

            _derivedNodeContext.Update(_derivedNode, x => Assert.Fail());
            UANodeContext _baseNodeContext = new UANodeContext(NodeId.Parse("i=17568"), _asMock.Object);

            _baseNodeContext.Update(_baseNode, x => Assert.Fail());
            _derivedNodeContext.RemoveInheritedValues(_baseNodeContext);
            Assert.AreEqual <string>("EURange", _derivedNode.BrowseName);
            Assert.IsNull(_derivedNode.DataType);
            Assert.IsNull(_derivedNode.Description);
        }
Beispiel #5
0
        private void GetBaseTypes(UANodeContext rootNode, List <UANodeContext> inheritanceChain)
        {
            if (rootNode == null)
            {
                throw new ArgumentNullException("rootNode");
            }
            if (rootNode.InRecursionChain)
            {
                throw new ArgumentOutOfRangeException("Circular reference");
            }
            rootNode.InRecursionChain = true;
            IEnumerable <UANodeContext> _derived = m_References.Values.Where <UAReferenceContext>(x => (x.TypeNode.NodeIdContext == ReferenceTypeIds.HasSubtype) && (x.TargetNode == rootNode)).
                                                   Select <UAReferenceContext, UANodeContext>(x => x.SourceNode);

            inheritanceChain.AddRange(_derived);
            if (_derived.Count <UANodeContext>() > 1)
            {
                throw new ArgumentOutOfRangeException("To many subtypes");
            }
            else if (_derived.Count <UANodeContext>() == 1)
            {
                GetBaseTypes(_derived.First <UANodeContext>(), inheritanceChain);
            }
            rootNode.InRecursionChain = false;
        }
Beispiel #6
0
        public void EqualsUAVariableTestMethod()
        {
            UAVariable _derivedNode = new UAVariable()
            {
                NodeId       = "ns=1;i=47",
                BrowseName   = "EURange",
                ParentNodeId = "ns=1;i=43",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };
            UANode _baseNode = new UAVariable()
            {
                NodeId       = "i=17568",
                BrowseName   = "EURange",
                ParentNodeId = "i=15318",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            IUANodeContext _derivedNodeContext       = new UANodeContext(NodeId.Parse("ns=1;i=47"), _asMock.Object);

            _derivedNodeContext.Update(_derivedNode, x => Assert.Fail());
            UANodeContext _baseNodeContext = new UANodeContext(NodeId.Parse("i=17568"), _asMock.Object);

            _baseNodeContext.Update(_baseNode, x => Assert.Fail());
            Assert.IsTrue(_derivedNode.Equals(_baseNode));
            Assert.IsTrue(_derivedNodeContext.Equals(_baseNodeContext));
        }
Beispiel #7
0
        public void EqualsTest()
        {
            AddressSpaceBuildContext _as     = new AddressSpaceBuildContext();
            UANodeContext            _first  = _as.InstanceToTest;
            UANodeContext            _second = _as.InstanceToTest;

            Assert.IsTrue(_first.Equals(_second));
        }
Beispiel #8
0
        public void CalculateNodeReferencesValidatorIsNullTest()
        {
            Mock <IAddressSpaceBuildContext> _addressSpaceMock = new Mock <IAddressSpaceBuildContext>();
            Mock <INodeFactory> _mockNodeFactory = new Mock <INodeFactory>();
            IUANodeBase         _first           = new UANodeContext(NodeId.Parse("ns=1;i=11"), _addressSpaceMock.Object);

            _first.CalculateNodeReferences(_mockNodeFactory.Object, null);
        }
Beispiel #9
0
            private UANodeContext NewNode(UANode newNode)
            {
                UANodeContext _newNode = new UANodeContext(NodeId.Parse(newNode.NodeId), this);

                _newNode.Update(newNode, x => { m_References.Add(x.Key, x); });
                Add2mNodesDictionary(_newNode);
                return(_newNode);
            }
        public void EqualsTest()
        {
            IUAModelContext _mc     = new UAModelContext();
            UANodeContext   _first  = new UANodeContext(new AddressSpaceBuildContext(), _mc, NodeId.Parse("ns=1;i=11"));
            UANodeContext   _second = new UANodeContext(new AddressSpaceBuildContext(), _mc, NodeId.Parse("ns=1;i=11"));

            Assert.IsTrue(_first.Equals(_second));
        }
Beispiel #11
0
        private void GetChildren(UANodeContext type, List <UANodeContext> instances)
        {
            IEnumerable <UANodeContext> _children = m_References.Values.Where <UAReferenceContext>(x => x.SourceNode == type).
                                                    Where <UAReferenceContext>(x => (x.ReferenceKind == ReferenceKindEnum.HasProperty || x.ReferenceKind == ReferenceKindEnum.HasComponent)).
                                                    Select <UAReferenceContext, UANodeContext>(x => x.TargetNode);

            instances.AddRange(_children);
        }
Beispiel #12
0
        public void CalculateNodeReferencesNullFactoryTest()
        {
            Mock <IAddressSpaceBuildContext> _addressSpaceMock = new Mock <IAddressSpaceBuildContext>();
            Mock <IValidator> _validatorMoc = new Mock <IValidator>();
            IUANodeBase       _first        = new UANodeContext(NodeId.Parse("ns=1;i=11"), _addressSpaceMock.Object);

            _first.CalculateNodeReferences(null, _validatorMoc.Object);
        }
Beispiel #13
0
        /// <summary>
        /// Search the address space to find the node <paramref name="nodeId" /> and returns <see cref="XmlQualifiedName" />
        /// encapsulating the <see cref="UANode.BrowseName" /> of this node if exist. Returns<c>null</c> otherwise.
        /// </summary>
        /// <param name="nodeId">The identifier of the node to find.</param>
        /// <param name="traceEvent">Encapsulates an action used to trace events.</param>
        /// <returns>An instance of <see cref="XmlQualifiedName" /> representing the <see cref="UANode.BrowseName" /> of the node indexed by <paramref name="nodeId" /></returns>
        internal XmlQualifiedName ExportBrowseName(NodeId nodeId, Action <TraceMessage> traceEvent)
        {
            UANodeContext _context = TryGetUANodeContext(nodeId, traceEvent);

            if (_context == null)
            {
                return(null);
            }
            return(_context.ExportNodeBrowseName());
        }
Beispiel #14
0
        internal void GetDerivedInstances(UANodeContext rootNode, List <UANodeContext> list)
        {
            List <UANodeContext> _col = new List <UANodeContext>();

            _col.Add(rootNode);
            GetBaseTypes(rootNode, _col);
            foreach (UANodeContext _type in _col)
            {
                GetChildren(_type, list);
            }
        }
Beispiel #15
0
        internal UANodeContext GetOrCreateNodeContext(NodeId nodeId, UAModelContext modelContext, Action <TraceMessage> traceEvent)
        {
            UANodeContext _ret;
            string        _idKey = nodeId.ToString();

            if (!m_NodesDictionary.TryGetValue(_idKey, out _ret))
            {
                _ret = new UANodeContext(this, modelContext, nodeId);
                m_NodesDictionary.Add(_idKey, _ret);
            }
            return(_ret);
        }
Beispiel #16
0
        public void GetDerivedInstances4ObjectTest()
        {
            AddressSpaceBuildContext _as           = new AddressSpaceBuildContext();
            UANodeContext            _testInstance = _as.InstanceToTest;

            Assert.IsTrue(_testInstance.UANode.GetType() == typeof(UAObject));
            Assert.AreEqual <string>("1:InstanceOfDerivedFromComplexObjectType", _testInstance.BrowseName.ToString());
            Dictionary <string, IUANodeBase> _result = _testInstance.GetDerivedInstances();

            Assert.IsNotNull(_result);
            Assert.AreEqual <int>(4, _result.Count);
        }
Beispiel #17
0
        public void CalculateNodeReferencesNullUANodeTest()
        {
            Mock <IAddressSpaceBuildContext> _addressSpaceMock = new Mock <IAddressSpaceBuildContext>();

            _addressSpaceMock.Setup(x => x.GetMyReferences(It.IsAny <IUANodeBase>())).Returns(new List <UAReferenceContext>());
            Mock <INodeFactory> _mockNodeFactory = new Mock <INodeFactory>();
            Mock <IValidator>   _validatorMoc    = new Mock <IValidator>();

            _validatorMoc.Setup(x => x.ValidateExportNode(It.IsAny <IUANodeBase>(), _mockNodeFactory.Object, It.IsAny <UAReferenceContext>()));
            IUANodeBase _node = new UANodeContext(NodeId.Parse("ns=1;i=11"), _addressSpaceMock.Object);

            _node.CalculateNodeReferences(_mockNodeFactory.Object, _validatorMoc.Object);
            _addressSpaceMock.Verify(x => x.GetMyReferences(It.IsAny <IUANodeBase>()), Times.Once);
            _validatorMoc.Verify(x => x.ValidateExportNode(It.IsAny <IUANodeBase>(), _mockNodeFactory.Object, It.IsAny <UAReferenceContext>()), Times.Never);
        }
        public void ConstructorTest()
        {
            IUAModelContext _mc     = new UAModelContext();
            UANodeContext   _toTest = new UANodeContext(new AddressSpaceBuildContext(), _mc, NodeId.Parse("ns=1;i=11"));

            Assert.IsNotNull(_toTest.BrowseName);
            Assert.IsTrue(new QualifiedName() == _toTest.BrowseName);
            Assert.IsFalse(_toTest.InRecursionChain);
            Assert.IsFalse(_toTest.IsProperty);
            Assert.IsFalse(_toTest.IsPropertyVariableType);
            Assert.IsFalse(_toTest.ModelingRule.HasValue);
            Assert.IsNotNull(_toTest.NodeIdContext);
            Assert.IsTrue(_toTest.NodeIdContext.ToString() == "ns=1;i=11");
            Assert.AreSame(_mc, _toTest.UAModelContext);
            Assert.IsNull(_toTest.UANode);
        }
Beispiel #19
0
        public void UpdateNodeIdTest()
        {
            Mock <IAddressSpaceBuildContext> _addressSpaceMock = new Mock <IAddressSpaceBuildContext>();
            UANodeContext _toTest = new UANodeContext(NodeId.Parse("ns=1;i=11"), _addressSpaceMock.Object);

            XML.UANode _node = new UAObject()
            {
                NodeId      = "ns=1;i=1",
                BrowseName  = "1:NewUAObject",
                DisplayName = new XML.LocalizedText[] { new XML.LocalizedText()
                                                        {
                                                            Value = "New UA Object"
                                                        } },
                References = new Reference[]
                {
                    new Reference()
                    {
                        ReferenceType = ReferenceTypeIds.HasTypeDefinition.ToString(), Value = ObjectTypeIds.BaseObjectType.ToString()
                    },
                    new Reference()
                    {
                        ReferenceType = ReferenceTypeIds.Organizes.ToString(), IsForward = false, Value = "i=85"
                    }
                },
                // UAInstance
                ParentNodeId = string.Empty,
                // UAObject
                EventNotifier = 0x01,
            };
            int _registerReferenceCounter = 0;

            _toTest.Update(_node, x => _registerReferenceCounter++);
            Assert.AreEqual <int>(2, _registerReferenceCounter);
            Assert.IsNotNull(_toTest.BrowseName);
            Assert.AreEqual <QualifiedName>(new QualifiedName("NewUAObject", 1), _toTest.BrowseName);
            Assert.IsFalse(_toTest.InRecursionChain);
            Assert.IsFalse(_toTest.IsProperty);
            Assert.IsFalse(((IUANodeBase)_toTest).IsPropertyVariableType);
            Assert.IsFalse(_toTest.ModelingRule.HasValue);
            Assert.IsNotNull(_toTest.NodeIdContext);
            Assert.AreEqual <string>(_toTest.NodeIdContext.ToString(), "ns=1;i=11");
            Assert.IsNotNull(_toTest.UANode);
        }
Beispiel #20
0
        public void BuildSymbolicIdTest()
        {
            Mock <IBuildErrorsHandling> _traceMock   = new Mock <IBuildErrorsHandling>();
            List <TraceMessage>         _traceBuffer = new List <TraceMessage>();

            _traceMock.Setup(x => x.TraceEvent(It.IsAny <TraceMessage>())).Callback <TraceMessage>(x => _traceBuffer.Add(x));
            NodeId _nodeId = NodeId.Parse("ns=1;i=11");
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            UANodeContext _toTest = new UANodeContext(NodeId.Parse("ns=1;i=11"), _asMock.Object);

            _toTest.Log = _traceMock.Object;
            List <string> path = new List <string>();

            _toTest.BuildSymbolicId(path);
            Assert.AreEqual <int>(1, _traceBuffer.Count);
            Assert.AreEqual <string>("P3-0403040000", _traceBuffer[0].BuildError.Identifier);
            Assert.AreEqual <string>("The target node NodeId=ns=1;i=11, current path ", _traceBuffer[0].Message);
            Assert.AreEqual <int>(0, path.Count);
        }
        internal static UAReferenceContext NewReferenceStub
            (Reference reference, AddressSpaceContext addressSpaceContext, UAModelContext modelContext, UANodeContext parentNode, Action <TraceMessage> traceEvent)
        {
            UANodeContext      targetNode = modelContext.GetOrCreateNodeContext(reference.Value, true, traceEvent);
            UAReferenceContext _stb       = new UAReferenceContext()
            {
                m_Context  = addressSpaceContext,
                ParentNode = parentNode,
                SourceNode = reference.IsForward ? parentNode : targetNode,
                ModelNode  = reference,
                TargetNode = reference.IsForward ? targetNode : parentNode,
                TypeNode   = modelContext.GetOrCreateNodeContext(reference.ReferenceType, true, traceEvent),
            };

            if (_stb.TypeNode != null && _stb.TypeNode.NodeIdContext.NamespaceIndex == 0)
            {
                _stb.ReferenceKind = _stb.GetReferenceKind(_stb.TypeNode);
            }
            return(_stb);
        }
Beispiel #22
0
        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);
        }
        //methods
        private ReferenceKindEnum GetReferenceKind(UANodeContext TypeNode)
        {
            if (TypeNode.NodeIdContext.NamespaceIndex != 0)
            {
                return(ReferenceKindEnum.Custom);
            }
            ReferenceKindEnum _ret = default(ReferenceKindEnum);

            switch (TypeNode.NodeIdContext.UintIdentifier())
            {
            case ReferenceTypes.HierarchicalReferences:
                _ret = ReferenceKindEnum.HierarchicalReferences;
                break;

            case ReferenceTypes.HasComponent:
                _ret = ReferenceKindEnum.HasComponent;
                break;

            case ReferenceTypes.HasProperty:
                _ret = ReferenceKindEnum.HasProperty;
                break;

            case ReferenceTypes.HasModellingRule:
                _ret = ReferenceKindEnum.HasModellingRule;
                break;

            case ReferenceTypes.HasTypeDefinition:
                _ret = ReferenceKindEnum.HasTypeDefinition;
                break;

            case ReferenceTypes.HasSubtype:
                _ret = ReferenceKindEnum.HasSubtype;
                break;

            default:
                _ret = ReferenceKindEnum.Custom;
                break;
            }
            return(_ret);
        }
Beispiel #24
0
 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));
     }
 }
Beispiel #25
0
        public void UpdateWithDifferentNodeIdTest()
        {
            Mock <IAddressSpaceBuildContext> _asMock = new Mock <IAddressSpaceBuildContext>();
            QualifiedName  qualifiedName             = QualifiedName.Parse("EURange");
            IUANodeContext _newNode = new UANodeContext(NodeId.Parse("ns=1;i=11"), _asMock.Object);

            Assert.AreEqual <string>("ns=1;i=11", _newNode.NodeIdContext.ToString());
            UANode _nodeFactory = new UAVariable()
            {
                NodeId       = "ns=1;i=47",
                BrowseName   = "EURange",
                ParentNodeId = "ns=1;i=43",
                DataType     = "i=884",
                DisplayName  = new XML.LocalizedText[] { new XML.LocalizedText()
                                                         {
                                                             Value = "EURange"
                                                         } }
            };

            _newNode.Update(_nodeFactory, x => Assert.Fail()); // Update has different NodeId - no change is expected.
            Assert.AreEqual <string>("ns=1;i=11", _newNode.NodeIdContext.ToString());
            Assert.AreEqual <string>("ns=1;i=47", _newNode.UANode.NodeId);
        }
Beispiel #26
0
 private static void UpdateType(ITypeFactory nodeDesign, UAType nodeSet, UANodeContext nodeContext, Action <TraceMessage> traceEvent)
 {
     nodeDesign.BaseType   = nodeContext.ExportBaseTypeBrowseName(true, traceEvent);
     nodeDesign.IsAbstract = nodeSet.IsAbstract;
 }
Beispiel #27
0
 private static void UpdateInstance(IInstanceFactory nodeDesign, UAInstance nodeSet, UANodeContext nodeContext, Action <TraceMessage> traceEvent)
 {
     nodeDesign.ModelingRule   = nodeContext.ModelingRule;
     nodeDesign.TypeDefinition = nodeContext.ExportBaseTypeBrowseName(false, traceEvent);
     //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.
 }
Beispiel #28
0
        /// <summary>
        /// Validates <paramref name="nodeContext"/> and exports it using an object od <see cref="IModelFactory"/>.
        /// </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(UANodeContext 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;
                }
            }
        }
Beispiel #29
0
 internal IEnumerable <UAReferenceContext> GetReferences2Me(UANodeContext index)
 {
     return(m_References.Values.Where <UAReferenceContext>(x => x.TargetNode == index && x.ParentNode != index));
 }
Beispiel #30
0
 internal IEnumerable <UAReferenceContext> GetMyReferences(UANodeContext index)
 {
     return(m_References.Values.Where <UAReferenceContext>(x => (x.ParentNode == index)));
 }