Provides access to the system which stores the data.
Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlockState"/> class.
        /// </summary>
        /// <param name="nodeManager">The context.</param>
        /// <param name="nodeId">The node id.</param>
        /// <param name="block">The block.</param>
        public BlockState(
            HistoricalAccessServerNodeManager nodeManager,
            NodeId nodeId,
            UnderlyingSystemBlock block) : base(null)
        {
            m_blockId     = block.Id;
            m_nodeManager = nodeManager;

            this.SymbolicName  = block.Name;
            this.NodeId        = nodeId;
            this.BrowseName    = new QualifiedName(block.Name, nodeId.NamespaceIndex);
            this.DisplayName   = new LocalizedText(block.Name);
            this.Description   = null;
            this.WriteMask     = 0;
            this.UserWriteMask = 0;
            this.EventNotifier = EventNotifiers.None;

            UnderlyingSystem system = nodeManager.SystemContext.SystemHandle as UnderlyingSystem;

            if (system != null)
            {
                IList <UnderlyingSystemTag> tags = block.GetTags();

                for (int ii = 0; ii < tags.Count; ii++)
                {
                    BaseVariableState variable = CreateVariable(nodeManager.SystemContext, tags[ii]);
                    AddChild(variable);
                    variable.OnSimpleWriteValue = OnWriteTagValue;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Used to receive notifications when the value attribute is read or written.
        /// </summary>
        public ServiceResult OnWriteTagValue(
            ISystemContext context,
            NodeState node,
            ref object value)
        {
            UnderlyingSystem system = context.SystemHandle as UnderlyingSystem;

            if (system == null)
            {
                return(StatusCodes.BadCommunicationError);
            }

            UnderlyingSystemBlock block = system.FindBlock(m_blockId);

            if (block == null)
            {
                return(StatusCodes.BadNodeIdUnknown);
            }

            uint error = block.WriteTagValue(node.SymbolicName, value);

            if (error != 0)
            {
                // the simulator uses UA status codes so there is no need for a mapping table.
                return(error);
            }

            return(ServiceResult.Good);
        }
        /// <summary>
        /// Initializes the node manager.
        /// </summary>
        public HistoricalAccessServerNodeManager(IServerInternal server, ApplicationConfiguration configuration)
        :
            base(server, configuration, Namespaces.HistoricalAccess)
        {
            this.AliasRoot = "HDA";

            // get the configuration for the node manager.
            m_configuration = configuration.ParseExtension<HistoricalAccessServerConfiguration>();

            // use suitable defaults if no configuration exists.
            if (m_configuration == null)
            {
                m_configuration = new HistoricalAccessServerConfiguration();
            }

            SystemContext.SystemHandle = m_system = new UnderlyingSystem(m_configuration, NamespaceIndex);
            SystemContext.NodeIdFactory = this;
        }
Example #4
0
        /// <summary>
        /// Starts the monitoring the block.
        /// </summary>
        /// <param name="context">The context.</param>
        public void StartMonitoring(ServerSystemContext context)
        {
            if (m_monitoringCount == 0)
            {
                UnderlyingSystem system = context.SystemHandle as UnderlyingSystem;

                if (system != null)
                {
                    UnderlyingSystemBlock block = system.FindBlock(m_blockId);

                    if (block != null)
                    {
                        block.StartMonitoring(OnTagsChanged);
                    }
                }
            }

            m_monitoringCount++;
        }
Example #5
0
        /// <summary>
        /// Stop the monitoring the block.
        /// </summary>
        /// <param name="context">The context.</param>
        public bool StopMonitoring(ServerSystemContext context)
        {
            m_monitoringCount--;

            if (m_monitoringCount == 0)
            {
                UnderlyingSystem system = context.SystemHandle as UnderlyingSystem;

                if (system != null)
                {
                    UnderlyingSystemBlock block = system.FindBlock(m_blockId);

                    if (block != null)
                    {
                        block.StopMonitoring();
                    }
                }
            }

            return(m_monitoringCount != 0);
        }
Example #6
0
        /// <summary>
        /// Populates the browser with references that meet the criteria.
        /// </summary>
        /// <param name="context">The context for the system being accessed.</param>
        /// <param name="browser">The browser to populate.</param>
        protected override void PopulateBrowser(ISystemContext context, NodeBrowser browser)
        {
            base.PopulateBrowser(context, browser);

            // check if the parent segments need to be returned.
            if (browser.IsRequired(ReferenceTypeIds.Organizes, true))
            {
                UnderlyingSystem system = context.SystemHandle as UnderlyingSystem;

                if (system == null)
                {
                    return;
                }

                // add reference for each segment.
                IList <UnderlyingSystemSegment> segments = system.FindSegmentsForBlock(m_blockId);

                for (int ii = 0; ii < segments.Count; ii++)
                {
                    browser.Add(ReferenceTypeIds.Organizes, true, ModelUtils.ConstructIdForSegment(segments[ii].Id, this.NodeId.NamespaceIndex));
                }
            }
        }
Example #7
0
        /// <summary>
        /// Populates the browser with references that meet the criteria.
        /// </summary>
        /// <param name="context">The context for the system being accessed.</param>
        /// <param name="browser">The browser to populate.</param>
        protected override void PopulateBrowser(ISystemContext context, NodeBrowser browser)
        {
            base.PopulateBrowser(context, browser);

            // check if the parent segments need to be returned.
            if (browser.IsRequired(ReferenceTypeIds.Organizes, true))
            {
                UnderlyingSystem system = context.SystemHandle as UnderlyingSystem;

                if (system == null)
                {
                    return;
                }

                // add reference for parent segment.
                UnderlyingSystemSegment segment = system.FindParentForSegment(m_segmentPath);

                if (segment != null)
                {
                    browser.Add(ReferenceTypeIds.Organizes, true, ModelUtils.ConstructIdForSegment(segment.Id, this.NodeId.NamespaceIndex));
                }
            }
        }
Example #8
0
        /// <summary>
        /// Returns the next reference.
        /// </summary>
        /// <returns>The next reference that meets the browse criteria.</returns>
        public override IReference Next()
        {
            UnderlyingSystem system = (UnderlyingSystem)this.SystemContext.SystemHandle;

            lock (DataLock)
            {
                IReference reference = null;

                // enumerate pre-defined references.
                // always call first to ensure any pushed-back references are returned first.
                reference = base.Next();

                if (reference != null)
                {
                    return(reference);
                }

                if (m_stage == Stage.Begin)
                {
                    m_segments = system.FindSegments(m_source.SegmentPath);
                    m_stage    = Stage.Segments;
                    m_position = 0;
                }

                // don't start browsing huge number of references when only internal references are requested.
                if (InternalOnly)
                {
                    return(null);
                }

                // enumerate segments.
                if (m_stage == Stage.Segments)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, false))
                    {
                        reference = NextChild();

                        if (reference != null)
                        {
                            return(reference);
                        }
                    }

                    m_blocks   = system.FindBlocks(m_source.SegmentPath);
                    m_stage    = Stage.Blocks;
                    m_position = 0;
                }

                // enumerate blocks.
                if (m_stage == Stage.Blocks)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, false))
                    {
                        reference = NextChild();

                        if (reference != null)
                        {
                            return(reference);
                        }

                        m_stage    = Stage.Done;
                        m_position = 0;
                    }
                }

                // all done.
                return(null);
            }
        }
Example #9
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            UnderlyingSystem system = (UnderlyingSystem)this.SystemContext.SystemHandle;

            NodeId targetId = null;

            // check if a specific browse name is requested.
            if (!QualifiedName.IsNull(base.BrowseName))
            {
                // check if match found previously.
                if (m_position == Int32.MaxValue)
                {
                    return(null);
                }

                // browse name must be qualified by the correct namespace.
                if (m_source.BrowseName.NamespaceIndex != base.BrowseName.NamespaceIndex)
                {
                    return(null);
                }

                // look for matching segment.
                if (m_stage == Stage.Segments && m_segments != null)
                {
                    for (int ii = 0; ii < m_segments.Count; ii++)
                    {
                        if (base.BrowseName.Name == m_segments[ii].Name)
                        {
                            targetId = ModelUtils.ConstructIdForSegment(m_segments[ii].Id, m_source.NodeId.NamespaceIndex);
                            break;
                        }
                    }
                }

                // look for matching block.
                if (m_stage == Stage.Blocks && m_blocks != null)
                {
                    for (int ii = 0; ii < m_blocks.Count; ii++)
                    {
                        UnderlyingSystemBlock block = system.FindBlock(m_blocks[ii]);

                        if (block != null && base.BrowseName.Name == block.Name)
                        {
                            targetId = ModelUtils.ConstructIdForBlock(m_blocks[ii], m_source.NodeId.NamespaceIndex);
                            break;
                        }
                    }
                }

                m_position = Int32.MaxValue;
            }

            // return the child at the next position.
            else
            {
                // look for next segment.
                if (m_stage == Stage.Segments && m_segments != null)
                {
                    if (m_position >= m_segments.Count)
                    {
                        return(null);
                    }

                    targetId = ModelUtils.ConstructIdForSegment(m_segments[m_position++].Id, m_source.NodeId.NamespaceIndex);
                }

                // look for next block.
                else if (m_stage == Stage.Blocks && m_blocks != null)
                {
                    if (m_position >= m_blocks.Count)
                    {
                        return(null);
                    }

                    targetId = ModelUtils.ConstructIdForBlock(m_blocks[m_position++], m_source.NodeId.NamespaceIndex);
                }
            }

            // create reference.
            if (targetId != null)
            {
                return(new NodeStateReference(ReferenceTypeIds.Organizes, false, targetId));
            }

            return(null);
        }
        /// <summary>
        /// Returns the next reference.
        /// </summary>
        /// <returns>The next reference that meets the browse criteria.</returns>
        public override IReference Next()
        {
            UnderlyingSystem system = (UnderlyingSystem)this.SystemContext.SystemHandle;

            lock (DataLock)
            {
                IReference reference = null;

                // enumerate pre-defined references.
                // always call first to ensure any pushed-back references are returned first.
                reference = base.Next();

                if (reference != null)
                {
                    return(reference);
                }

                if (m_stage == Stage.Begin)
                {
                    m_folders  = m_source.ArchiveFolder.GetChildFolders();
                    m_stage    = Stage.Folders;
                    m_position = 0;
                }

                // don't start browsing huge number of references when only internal references are requested.
                if (InternalOnly)
                {
                    return(null);
                }

                // enumerate folders.
                if (m_stage == Stage.Folders)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, false))
                    {
                        reference = NextChild();

                        if (reference != null)
                        {
                            return(reference);
                        }
                    }

                    m_items    = m_source.ArchiveFolder.GetItems();
                    m_stage    = Stage.Items;
                    m_position = 0;
                }

                // enumerate items.
                if (m_stage == Stage.Items)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, false))
                    {
                        reference = NextChild();

                        if (reference != null)
                        {
                            return(reference);
                        }

                        m_stage    = Stage.Parents;
                        m_position = 0;
                    }
                }

                // enumerate parents.
                if (m_stage == Stage.Parents)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, true))
                    {
                        reference = NextChild();

                        if (reference != null)
                        {
                            return(reference);
                        }

                        m_stage    = Stage.Done;
                        m_position = 0;
                    }
                }

                // all done.
                return(null);
            }
        }
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            UnderlyingSystem system = (UnderlyingSystem)this.SystemContext.SystemHandle;

            NodeId targetId = null;

            // check if a specific browse name is requested.
            if (!QualifiedName.IsNull(base.BrowseName))
            {
                // check if match found previously.
                if (m_position == Int32.MaxValue)
                {
                    return(null);
                }

                // browse name must be qualified by the correct namespace.
                if (m_source.BrowseName.NamespaceIndex != base.BrowseName.NamespaceIndex)
                {
                    return(null);
                }

                // look for matching folder.
                if (m_stage == Stage.Folders && m_folders != null)
                {
                    for (int ii = 0; ii < m_folders.Length; ii++)
                    {
                        if (base.BrowseName.Name == m_folders[ii].Name)
                        {
                            targetId = ArchiveFolderState.ConstructId(m_folders[ii].UniquePath, m_source.NodeId.NamespaceIndex);
                            break;
                        }
                    }
                }

                // look for matching item.
                else if (m_stage == Stage.Items && m_items != null)
                {
                    for (int ii = 0; ii < m_items.Length; ii++)
                    {
                        if (base.BrowseName.Name == m_items[ii].Name)
                        {
                            targetId = ArchiveItemState.ConstructId(m_items[ii].UniquePath, m_source.NodeId.NamespaceIndex);
                            break;
                        }
                    }
                }

                // look for matching parent.
                else if (m_stage == Stage.Parents)
                {
                    ArchiveFolder parent = m_source.ArchiveFolder.GetParentFolder();

                    if (base.BrowseName.Name == parent.Name)
                    {
                        targetId = ArchiveFolderState.ConstructId(parent.UniquePath, m_source.NodeId.NamespaceIndex);
                    }
                }

                m_position = Int32.MaxValue;
            }

            // return the child at the next position.
            else
            {
                // look for next folder.
                if (m_stage == Stage.Folders && m_folders != null)
                {
                    if (m_position >= m_folders.Length)
                    {
                        return(null);
                    }

                    targetId = ArchiveFolderState.ConstructId(m_folders[m_position++].UniquePath, m_source.NodeId.NamespaceIndex);
                }

                // look for next item.
                else if (m_stage == Stage.Items && m_items != null)
                {
                    if (m_position >= m_items.Length)
                    {
                        return(null);
                    }

                    targetId = ArchiveItemState.ConstructId(m_items[m_position++].UniquePath, m_source.NodeId.NamespaceIndex);
                }

                // look for matching parent.
                else if (m_stage == Stage.Parents)
                {
                    ArchiveFolder parent = m_source.ArchiveFolder.GetParentFolder();

                    if (parent != null)
                    {
                        targetId = ArchiveFolderState.ConstructId(parent.UniquePath, m_source.NodeId.NamespaceIndex);
                    }
                }
            }

            // create reference.
            if (targetId != null)
            {
                return(new NodeStateReference(ReferenceTypeIds.Organizes, false, targetId));
            }

            return(null);
        }