Exemplo n.º 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());
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
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);
        }