A object which maps a segment to a UA object.
Inheritance: Opc.Ua.FolderState
Example #1
0
        /// <summary>
        /// Returns the next AE area or source.
        /// </summary>
        /// <returns>A DA element. Null if nothing left to browse.</returns>
        public BaseInstanceState Next(ISystemContext context, ushort namespaceIndex)
        {
            // check if already completed.
            if (m_completed)
            {
                return(null);
            }

            // create the browser.
            if (base.Unknown == null)
            {
                base.Unknown = m_client.CreateBrowser();

                if (base.Unknown == null)
                {
                    return(null);
                }

                if (!String.IsNullOrEmpty(m_itemId))
                {
                    if (!ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DIRECT, m_itemId))
                    {
                        return(null);
                    }
                }
            }

            // create the enumerator if not already created.
            if (m_enumerator == null)
            {
                m_enumerator = CreateEnumerator(true);
                m_branches   = true;

                // a null indicates an error.
                if (m_enumerator == null)
                {
                    m_completed = true;
                    return(null);
                }
            }

            // need a loop in case errors occur fetching element metadata.
            BaseInstanceState node = null;

            do
            {
                // fetch the next name.
                string name = m_enumerator.Next();

                // a null indicates the end of list.
                if (name == null)
                {
                    if (m_branches)
                    {
                        m_enumerator.Dispose();
                        m_enumerator = CreateEnumerator(false);
                        m_branches   = false;

                        // a null indicates an error.
                        if (m_enumerator != null)
                        {
                            continue;
                        }
                    }

                    m_completed = true;
                    return(null);
                }

                // create the node.
                if (m_branches)
                {
                    string itemId = GetBranchPosition(m_itemId, name);
                    node = new HdaBranchState(itemId, name, namespaceIndex);
                }
                else
                {
                    string itemId = GetItemId(name);
                    node = new HdaItemState(itemId, name, namespaceIndex);
                }

                break;
            }while (node == null);

            // return node.
            return(node);
        }
        /// <summary>
        /// Does any initialization required before the address space can be used.
        /// </summary>
        /// <remarks>
        /// The externalReferences is an out parameter that allows the node manager to link to nodes
        /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and
        /// should have a reference to the root folder node(s) exposed by this node manager.  
        /// </remarks>
        public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)
        {
            lock (Lock)
            {
                // check if the type model needs to be loaded.
                if (NamespaceIndexes.Length > 1)
                {
                    LoadPredefinedNodes(SystemContext, externalReferences);
                }

                // create the root node.
                string serverName = m_configuration.ServerName;

                if (String.IsNullOrEmpty(serverName))
                {
                    serverName = "ComHdaServer";
                }

                HdaBranchState root = new HdaBranchState(String.Empty, serverName, NamespaceIndex);
                root.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder);

                // link root to objects folder.
                IList<IReference> references = null;

                if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references))
                {
                    externalReferences[ObjectIds.ObjectsFolder] = references = new List<IReference>();
                }

                references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, root.NodeId));

                // create the status node.
                ComServerStatusState status = new ComServerStatusState(root);
                status.ReferenceTypeId = ReferenceTypeIds.Organizes;

                // get the type namepace for the browse name.
                int typeNamepaceIndex = Server.NamespaceUris.GetIndex(Namespaces.ComInterop);

                if (typeNamepaceIndex < 0)
                {
                    typeNamepaceIndex = NamespaceIndex;
                }

                status.Create(
                    SystemContext,
                    HdaModelUtils.ConstructIdForInternalNode("ServerStatus", NamespaceIndex),
                    new QualifiedName("ServerStatus", (ushort)typeNamepaceIndex),
                    null,
                    true);

                root.AddChild(status);

                // store root folder in the pre-defined nodes.
                AddPredefinedNode(SystemContext, root);

                // create the server capabilities object.
                HistoryServerCapabilitiesState capabilities = m_capabilities = new HistoryServerCapabilitiesState(null);

                CreateNode(
                    SystemContext,
                    root.NodeId,
                    ReferenceTypeIds.Organizes,
                    new QualifiedName(Opc.Ua.BrowseNames.HistoryServerCapabilities),
                    capabilities);

                capabilities.AccessHistoryDataCapability.Value = true;
                capabilities.AccessHistoryEventsCapability.Value = false;
                capabilities.MaxReturnDataValues.Value = 0;
                capabilities.MaxReturnEventValues.Value = 0;
                capabilities.ReplaceDataCapability.Value = false;
                capabilities.UpdateDataCapability.Value = false;
                capabilities.InsertEventCapability.Value = false;
                capabilities.ReplaceEventCapability.Value = false;
                capabilities.UpdateEventCapability.Value = false;
                capabilities.InsertAnnotationCapability.Value = false;
                capabilities.InsertDataCapability.Value = false;
                capabilities.DeleteRawCapability.Value = false;
                capabilities.DeleteAtTimeCapability.Value = false;

                AddPredefinedNode(SystemContext, capabilities);

                // create the default aggregate configuration object.
                AggregateConfigurationState aggregateConfiguration = new AggregateConfigurationState(null);
                aggregateConfiguration.ReferenceTypeId = ReferenceTypeIds.Organizes;

                aggregateConfiguration.Create(
                    SystemContext,
                    HdaModelUtils.ConstructIdForInternalNode(Opc.Ua.BrowseNames.AggregateConfiguration, NamespaceIndex),
                    Opc.Ua.BrowseNames.AggregateConfiguration,
                    null,
                    true);

                aggregateConfiguration.TreatUncertainAsBad.Value = m_configuration.TreatUncertainAsBad;
                aggregateConfiguration.PercentDataBad.Value = m_configuration.PercentDataBad;
                aggregateConfiguration.PercentDataGood.Value = m_configuration.PercentDataGood;
                aggregateConfiguration.UseSlopedExtrapolation.Value = m_configuration.SteppedSlopedExtrapolation;

                AddPredefinedNode(SystemContext, aggregateConfiguration);
                                
                // create the COM server.
                m_system.Initialize(SystemContext, m_configuration, status, Lock, OnServerReconnected);
                StartMetadataUpdates(DoMetadataUpdate, null, 5000, m_configuration.MaxReconnectWait);
            }
        }
        /// <summary>
        /// Returns the next AE area or source.
        /// </summary>
        /// <returns>A DA element. Null if nothing left to browse.</returns>
        public BaseInstanceState Next(ISystemContext context, ushort namespaceIndex)
        {
            // check if already completed.
            if (m_completed)
            {
                return null;
            }

            // create the browser.
            if (base.Unknown == null)
            {
                base.Unknown = m_client.CreateBrowser();

                if (base.Unknown == null)
                {
                    return null;
                }

                if (!String.IsNullOrEmpty(m_itemId))
                {
                    if (!ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DIRECT, m_itemId))
                    {
                        return null;
                    }
                }
            }

            // create the enumerator if not already created.
            if (m_enumerator == null)
            {
                m_enumerator = CreateEnumerator(true);
                m_branches = true;

                // a null indicates an error.
                if (m_enumerator == null)
                {
                    m_completed = true;
                    return null;
                }
            }

            // need a loop in case errors occur fetching element metadata.
            BaseInstanceState node = null;

            do
            {
                // fetch the next name.
                string name = m_enumerator.Next();

                // a null indicates the end of list.
                if (name == null)
                {
                    if (m_branches)
                    {
                        m_enumerator.Dispose();
                        m_enumerator = CreateEnumerator(false);
                        m_branches = false;

                        // a null indicates an error.
                        if (m_enumerator != null)
                        {
                            continue;
                        }
                    }

                    m_completed = true;
                    return null;
                }

                // create the node.
                if (m_branches)
                {
                    string itemId = GetBranchPosition(m_itemId, name);
                    node = new HdaBranchState(itemId, name, namespaceIndex);

                }
                else
                {
                    string itemId = GetItemId(name);
                    node = new HdaItemState(itemId, name, namespaceIndex);
                }

                break;
            }
            while (node == null);

            // return node.
            return node;
        }