Esempio n. 1
0
        /// <summary>
        /// Adds an link with an item id to the address space.
        /// </summary>
        public bool AddItemAndLink(string browsePath, string itemID, IDevice device)
        {
            lock (this)
            {
                // validate browse path.
                if (browsePath == null || browsePath.Length == 0)
                {
                    return(false);
                }

                // check if item does not exists.
                if (!m_items.Contains(itemID))
                {
                    return(false);
                }

                // create the browse element.
                BrowseElement element = m_addressSpace.Insert(browsePath, itemID);

                if (element == null)
                {
                    return(false);
                }

                // create new item and index by item id.
                m_items[element.ItemID] = new CacheItem(itemID, device);
                return(true);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Removes an link (but not the item) from the address space only if it has no children.
        /// </summary>
        public bool RemoveEmptyLink(string browsePath)
        {
            lock (this)
            {
                // validate browse path.
                if (browsePath == null || browsePath.Length == 0)
                {
                    return(false);
                }

                // create the browse element.
                BrowseElement element = m_addressSpace.Find(browsePath);

                if (element != null)
                {
                    if (element.Count == 0)
                    {
                        element.Remove();
                        return(true);
                    }
                }

                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Removes an link and an item with the same id to the address space.
        /// </summary>
        public bool RemoveItemAndLink(string browsePath)
        {
            lock (this)
            {
                // validate browse path.
                if (browsePath == null || browsePath.Length == 0)
                {
                    return(false);
                }

                // find the browse element.
                BrowseElement element = m_addressSpace.Find(browsePath);

                if (element != null)
                {
                    // remove item.
                    m_items.Remove(element.ItemID);

                    // remove element.
                    element.Remove();
                }

                return(true);
            }
        }
        /// <summary>
        /// Inserts a child with a specific item id into the correct place in the hierarchy.
        /// </summary>
        public BrowseElement Insert(string browsePath, string itemID)
        {
            BrowseElement child = Insert(browsePath);

            if (child != null)
            {
                child.m_itemID = itemID;
            }

            return(child);
        }
        /// <summary>
        /// Removes the child with the specified name from the element.
        /// </summary>
        public bool Remove(string name)
        {
            if (m_children != null)
            {
                for (int ii = 0; ii < m_children.Count; ii++)
                {
                    BrowseElement child = (BrowseElement)m_children[ii];

                    if (child.Name == name)
                    {
                        m_children.RemoveAt(ii);
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// Adds an link without an item to the address space.
        /// </summary>
        public bool AddLink(string browsePath)
        {
            lock (this)
            {
                // validate browse path.
                if (browsePath == null || browsePath.Length == 0)
                {
                    return(false);
                }

                // create the browse element.
                BrowseElement element = m_addressSpace.Insert(browsePath);

                if (element == null)
                {
                    return(false);
                }

                return(true);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Returns the set of elements in the address space that meet the specified criteria.
        /// </summary>
        public Opc.Da.BrowseElement[] Browse(
            ItemIdentifier itemID,
            BrowseFilters filters,
            ref Opc.Da.BrowsePosition position)
        {
            lock (this)
            {
                if (m_disposed)
                {
                    throw new ObjectDisposedException("Opc.Da.Cache");
                }

                BrowseElement element = m_addressSpace;

                // find desired element.
                string browsePath = (itemID != null)?itemID.ItemName:null;

                if (browsePath != null && browsePath.Length > 0)
                {
                    element = m_addressSpace.Find(browsePath);

                    if (element == null)
                    {
                        // check if browsing a property item.
                        PropertyID property = Property.VALUE;

                        string rootID = LookupProperty(browsePath, out property);

                        if (rootID != null)
                        {
                            element = m_addressSpace.Find(rootID);
                        }

                        if (element == null)
                        {
                            throw new ResultIDException(ResultID.Da.E_UNKNOWN_ITEM_NAME);
                        }

                        // property items never contain children.
                        return(new Opc.Da.BrowseElement[0]);
                    }
                }

                // check if no elements exist.
                if (element.Count == 0)
                {
                    return(new Opc.Da.BrowseElement[0]);
                }

                // determine start position.
                int start = 0;

                if (position != null)
                {
                    start = ((BrowsePosition)position).Index;
                    position.Dispose();
                    position = null;
                }

                // process child nodes.
                ArrayList results = new ArrayList();

                for (int ii = start; ii < element.Count; ii++)
                {
                    BrowseElement child = element.Child(ii);

                    // exclude elements without children.
                    if (filters.BrowseFilter == browseFilter.branch && child.Count == 0)
                    {
                        continue;
                    }

                    // check if an element is an item.
                    CacheItem item = (CacheItem)m_items[child.ItemID];

                    // exclude elements which are not items.
                    if (filters.BrowseFilter == browseFilter.item && item == null)
                    {
                        continue;
                    }

                    // apply name filter (using the SQL LIKE operator).
                    if (filters.ElementNameFilter != null && filters.ElementNameFilter.Length > 0)
                    {
                        if (!Opc.Convert.Match(child.Name, filters.ElementNameFilter, true))
                        {
                            continue;
                        }
                    }

                    // add element to list of results.
                    Opc.Da.BrowseElement result = new Opc.Da.BrowseElement();

                    result.Name        = child.Name;
                    result.ItemName    = child.ItemID;
                    result.ItemPath    = null;
                    result.IsItem      = item != null;
                    result.HasChildren = child.Count > 0;
                    result.Properties  = null;

                    // add properties to results.
                    if (filters.ReturnAllProperties || filters.PropertyIDs != null)
                    {
                        result.Properties = GetProperties(item, (filters.ReturnAllProperties)?null:filters.PropertyIDs, filters.ReturnPropertyValues);
                    }

                    results.Add(result);

                    // check if max elements exceeded.
                    if (filters.MaxElementsReturned > 0 && results.Count >= filters.MaxElementsReturned)
                    {
                        if (ii + 1 < element.Count)
                        {
                            position = new BrowsePosition(itemID, filters);
                            ((BrowsePosition)position).Index = ii + 1;
                        }

                        break;
                    }
                }


                // return results.
                return((Opc.Da.BrowseElement[])results.ToArray(typeof(Opc.Da.BrowseElement)));
            }
        }
 /// <summary>
 /// Initializes the element with its parent and item id.
 /// </summary>
 public BrowseElement(BrowseElement parent, string name, string itemID)
 {
     m_parent = parent;
     m_name   = name;
     m_itemID = itemID;
 }
 /// <summary>
 /// Initializes the element with its parent.
 /// </summary>
 public BrowseElement(BrowseElement parent, string name)
 {
     m_parent = parent;
     m_name   = name;
 }
        /// <summary>
        /// Inserts a child into the correct place in the hierarchy.
        /// </summary>
        public BrowseElement Insert(string browsePath)
        {
            if (browsePath == null) throw new ArgumentNullException("browsePath");

            // extract the first path element from the browse path.
            string name    = browsePath;
            string subpath = "";

            do
            {
                int index = name.IndexOf(Separator);

                if (index == -1)
                {
                    break;
                }

                subpath = name.Substring(index + Separator.Length);
                name    = name.Substring(0, index);

                // name may be empty if multiple separators defined.
                if (name.Length > 0)
                {
                    break;
                }

                name = subpath;
            }
            while (subpath.Length > 0);

            // check for valid path.
            if (name.Length == 0)
            {
                return null;
            }

            // find out if child element already exists.
            if (m_children != null)
            {
                foreach (BrowseElement child in m_children)
                {
                    if (child.Name == name)
                    {
                        // insert new element in child.
                        if (subpath.Length > 0)
                        {
                            return child.Insert(subpath);
                        }

                        // return existing child.
                        return child;
                    }
                }
            }

            // create a new child element.
            BrowseElement element = new BrowseElement(this, name);

            // add new child to end of list.
            if (m_children == null)
            {
                m_children = new ArrayList();
            }

            // add any children to the new element.
            if (subpath.Length == 0)
            {
                m_children.Add(element);
                return element;
            }

            // add any sub elements.
            BrowseElement parent = element;

            element = parent.Insert(subpath);

            if (element != null)
            {
                m_children.Add(parent);
            }

            return element;
        }
 /// <summary>
 /// Initializes the element with its parent and item id.
 /// </summary>
 public BrowseElement(BrowseElement parent, string name, string itemID)
 {
     m_parent = parent;
     m_name   = name;
     m_itemID = itemID;
 }
 /// <summary>
 /// Initializes the element with its parent.
 /// </summary>
 public BrowseElement(BrowseElement parent, string name)
 {
     m_parent = parent;
     m_name   = name;
 }
        /// <summary>
        /// Inserts a child into the correct place in the hierarchy.
        /// </summary>
        public BrowseElement Insert(string browsePath)
        {
            if (browsePath == null)
            {
                throw new ArgumentNullException("browsePath");
            }

            // extract the first path element from the browse path.
            string name    = browsePath;
            string subpath = "";

            do
            {
                int index = name.IndexOf(Separator);

                if (index == -1)
                {
                    break;
                }

                subpath = name.Substring(index + Separator.Length);
                name    = name.Substring(0, index);

                // name may be empty if multiple separators defined.
                if (name.Length > 0)
                {
                    break;
                }

                name = subpath;
            }while (subpath.Length > 0);

            // check for valid path.
            if (name.Length == 0)
            {
                return(null);
            }

            // find out if child element already exists.
            if (m_children != null)
            {
                foreach (BrowseElement child in m_children)
                {
                    if (child.Name == name)
                    {
                        // insert new element in child.
                        if (subpath.Length > 0)
                        {
                            return(child.Insert(subpath));
                        }

                        // return existing child.
                        return(child);
                    }
                }
            }

            // create a new child element.
            BrowseElement element = new BrowseElement(this, name);

            // add new child to end of list.
            if (m_children == null)
            {
                m_children = new ArrayList();
            }

            // add any children to the new element.
            if (subpath.Length == 0)
            {
                m_children.Add(element);
                return(element);
            }

            // add any sub elements.
            BrowseElement parent = element;

            element = parent.Insert(subpath);

            if (element != null)
            {
                m_children.Add(parent);
            }

            return(element);
        }