/// <remarks/>
 public void Clone(out OpcRcw.Comn.IEnumString ppenum)
 {
     lock (m_lock)
     {
         try
         {
             ppenum = new EnumString(m_strings);
         }
         catch (Exception e)
         {
             throw ComUtils.CreateComException(e);
         }
     }
 }
        /// <summary>
        /// Creates an enumerator for the elements contained with the current branch.
        /// </summary>
        private EnumString GetEnumerator(bool isBranch)
        {
            try
            {
                OPCHDA_BROWSETYPE browseType = (isBranch)?OPCHDA_BROWSETYPE.OPCHDA_BRANCH:OPCHDA_BROWSETYPE.OPCHDA_LEAF;

                OpcRcw.Comn.IEnumString pEnumerator = null;
                m_browser.GetEnum(browseType, out pEnumerator);

                return(new EnumString(pEnumerator));
            }
            catch (Exception e)
            {
                throw Technosoftware.DaAeHdaClient.Utilities.Interop.CreateException("IOPCHDA_Browser.GetEnum", e);
            }
        }
Example #3
0
        public void Clone(out OpcRcw.Comn.IEnumString ppenum)
        {
            EnumString str;

            Monitor.Enter(str = this);
            try
            {
                ppenum = new EnumString(this.m_strings);
            }
            catch (Exception exception)
            {
                throw Server.CreateException(exception);
            }
            finally
            {
                Monitor.Exit(str);
            }
        }
Example #4
0
        /// <summary>
        /// Return an IEnumString for a list of Areas as determined by the passed parameters.
        /// </summary>
        /// <param name="dwBrowseFilterType">
        /// OPC_AREA - returns only areas.
        /// OPC_SOURCE - returns only sources.</param>
        /// <param name="szFilterCriteria">A server specific filter string. A pointer to a NULL string indicates no filtering.</param>
        /// <param name="ppIEnumString">Where to save the returned interface pointer. NULL if the HRESULT is other than S_OK or S_FALSE.</param>
        public void BrowseOPCAreas(
            OPCAEBROWSETYPE dwBrowseFilterType,
            string szFilterCriteria,
            out OpcRcw.Comn.IEnumString ppIEnumString)
        {
            ppIEnumString = null;
            if (dwBrowseFilterType != OPCAEBROWSETYPE.OPC_AREA && dwBrowseFilterType != OPCAEBROWSETYPE.OPC_SOURCE)
            {
                throw ComUtils.CreateComException("BrowseOPCAreas", ResultIds.E_INVALIDARG);
            }
            try
            {
                lock (m_lock)
                {
                    // find the current node.
                    INode parent = null;

                    // ensure browse stack has been initialized.
                    if (m_browseStack.Count == 0)
                    {
                        parent = m_session.NodeCache.Find(Objects.Server);
                        m_browseStack.Push(parent);
                    }

                    parent = m_browseStack.Peek();

                    if (parent == null)
                    {
                        throw ComUtils.CreateComException("BrowseOPCAreas", ResultIds.E_FAIL);
                    }

                    List <string> names = new List <string>();
                    IList <INode> children;

                    ////// find children.
                    children = m_session.NodeCache.Find(parent.NodeId, ReferenceTypes.HasEventSource, false, true);    // This would also include
                                                                                                                       // the HasNotifier reference which is
                                                                                                                       // a subtype of HasEventSource

                    foreach (INode child in children)
                    {
                        // ignore external nodes.
                        if (child.NodeId.IsAbsolute)
                        {
                            continue;
                        }

                        // ignore non-objects/variables.
                        if ((child.NodeClass & (NodeClass.Object | NodeClass.Variable)) == 0)
                        {
                            continue;
                        }

                        // ignore duplicate browse names.
                        if (names.Contains(child.BrowseName.ToString()))
                        {
                            continue;
                        }

                        // For a node to be an area, it has to have the 'HasNotifier' reference and must
                        // allow event notification (the EventNotifier attribute is set to SubscribeToEvents)
                        // For a node to be a source, it should be the target of the HasEventSource reference
                        if (IsValidNode((NodeId)child.NodeId, child.BrowseName.ToString(), dwBrowseFilterType))
                        {
                            if (String.IsNullOrEmpty(szFilterCriteria))
                            {
                                names.Add(child.BrowseName.ToString());
                            }
                            else
                            {
                                // apply filters
                                if (ComUtils.Match(child.BrowseName.ToString(), szFilterCriteria, true))
                                {
                                    names.Add(child.BrowseName.ToString());
                                }
                            }
                        }
                    }

                    // create enumerator.
                    ppIEnumString = (OpcRcw.Comn.IEnumString) new EnumString(names);
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error in BrowseOPCAreas");
                throw ComUtils.CreateComException(e);
            }
        }