Beispiel #1
0
        public ComplexItem[] GetDataFilters(Opc.Da.Server server)
        {
            ComplexItem[] itemArray;
            if (this.m_unfilteredItemID != null)
            {
                return(null);
            }
            if (this.m_filterItem == null)
            {
                return(null);
            }
            BrowsePosition position = null;

            try
            {
                BrowseFilters filters = new BrowseFilters {
                    ElementNameFilter    = null,
                    BrowseFilter         = browseFilter.item,
                    ReturnAllProperties  = false,
                    PropertyIDs          = CPX_PROPERTIES,
                    ReturnPropertyValues = true
                };
                BrowseElement[] elementArray = server.Browse(this.m_filterItem, filters, out position);
                if ((elementArray == null) || (elementArray.Length == 0))
                {
                    return(new ComplexItem[0]);
                }
                ArrayList list = new ArrayList(elementArray.Length);
                foreach (BrowseElement element in elementArray)
                {
                    ComplexItem item = new ComplexItem();
                    if (item.Init(element))
                    {
                        list.Add(item);
                    }
                }
                itemArray = (ComplexItem[])list.ToArray(typeof(ComplexItem));
            }
            finally
            {
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
            return(itemArray);
        }
 public static string GetTypeDictionary(ItemIdentifier itemID)
 {
     if (itemID == null)
     {
         return(null);
     }
     lock (typeof(ComplexTypeCache))
     {
         string typeDictionary = (string)m_dictionaries[itemID.Key];
         if (typeDictionary == null)
         {
             ComplexItem complexItem = GetComplexItem(itemID);
             if (complexItem != null)
             {
                 typeDictionary = complexItem.GetTypeDictionary(m_server);
             }
         }
         return(typeDictionary);
     }
 }
 public static ComplexItem GetComplexItem(ItemIdentifier itemID)
 {
     if (itemID == null)
     {
         return(null);
     }
     lock (typeof(ComplexTypeCache))
     {
         ComplexItem item = new ComplexItem(itemID);
         try
         {
             item.Update(m_server);
         }
         catch
         {
             item = null;
         }
         m_items[itemID.Key] = item;
         return(item);
     }
 }
 public static string GetTypeDescription(ItemIdentifier itemID)
 {
     if (itemID == null)
     {
         return(null);
     }
     lock (typeof(ComplexTypeCache))
     {
         string      str         = null;
         ComplexItem complexItem = GetComplexItem(itemID);
         if (complexItem != null)
         {
             str = (string)m_descriptions[complexItem.TypeItemID.Key];
             if (str != null)
             {
                 return(str);
             }
             m_descriptions[complexItem.TypeItemID.Key] = str = complexItem.GetTypeDescription(m_server);
         }
         return(str);
     }
 }
Beispiel #5
0
        public ComplexItem CreateDataFilter(Opc.Da.Server server, string filterName, string filterValue)
        {
            ComplexItem item2;

            if (this.m_unfilteredItemID != null)
            {
                return(null);
            }
            if (this.m_filterItem == null)
            {
                return(null);
            }
            BrowsePosition position = null;

            try
            {
                ItemValue     value2  = new ItemValue(this.m_filterItem);
                StringWriter  w       = new StringWriter();
                XmlTextWriter writer2 = new XmlTextWriter(w);
                writer2.WriteStartElement("DataFilters");
                writer2.WriteAttributeString("Name", filterName);
                writer2.WriteString(filterValue);
                writer2.WriteEndElement();
                writer2.Close();
                value2.Value              = w.ToString();
                value2.Quality            = Quality.Bad;
                value2.QualitySpecified   = false;
                value2.Timestamp          = DateTime.MinValue;
                value2.TimestampSpecified = false;
                IdentifiedResult[] resultArray = server.Write(new ItemValue[] { value2 });
                if ((resultArray == null) || (resultArray.Length == 0))
                {
                    throw new ApplicationException("Unexpected result from server.");
                }
                if (resultArray[0].ResultID.Failed())
                {
                    throw new ApplicationException("Could not create new data filter.");
                }
                BrowseFilters filters = new BrowseFilters {
                    ElementNameFilter    = filterName,
                    BrowseFilter         = browseFilter.item,
                    ReturnAllProperties  = false,
                    PropertyIDs          = CPX_PROPERTIES,
                    ReturnPropertyValues = true
                };
                BrowseElement[] elementArray = server.Browse(this.m_filterItem, filters, out position);
                if ((elementArray == null) || (elementArray.Length == 0))
                {
                    throw new ApplicationException("Could not browse to new data filter.");
                }
                ComplexItem item = new ComplexItem();
                if (!item.Init(elementArray[0]))
                {
                    throw new ApplicationException("Could not initialize to new data filter.");
                }
                item2 = item;
            }
            finally
            {
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
            return(item2);
        }
Beispiel #6
0
        public ComplexItem[] GetTypeConversions(Opc.Da.Server server)
        {
            ComplexItem[] itemArray;
            if ((this.m_unconvertedItemID != null) || (this.m_unfilteredItemID != null))
            {
                return(null);
            }
            BrowsePosition position = null;

            try
            {
                BrowseFilters filters = new BrowseFilters {
                    ElementNameFilter    = "CPX",
                    BrowseFilter         = browseFilter.branch,
                    ReturnAllProperties  = false,
                    PropertyIDs          = null,
                    ReturnPropertyValues = false
                };
                BrowseElement[] elementArray = server.Browse(this, filters, out position);
                if ((elementArray == null) || (elementArray.Length == 0))
                {
                    return(null);
                }
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
                ItemIdentifier itemID = new ItemIdentifier(elementArray[0].ItemPath, elementArray[0].ItemName);
                filters.ElementNameFilter    = null;
                filters.BrowseFilter         = browseFilter.item;
                filters.ReturnAllProperties  = false;
                filters.PropertyIDs          = CPX_PROPERTIES;
                filters.ReturnPropertyValues = true;
                elementArray = server.Browse(itemID, filters, out position);
                if ((elementArray == null) || (elementArray.Length == 0))
                {
                    return(new ComplexItem[0]);
                }
                ArrayList list = new ArrayList(elementArray.Length);
                foreach (BrowseElement element in elementArray)
                {
                    if (element.Name != "DataFilters")
                    {
                        ComplexItem item = new ComplexItem();
                        if (item.Init(element))
                        {
                            item.GetDataFilterItem(server);
                            list.Add(item);
                        }
                    }
                }
                itemArray = (ComplexItem[])list.ToArray(typeof(ComplexItem));
            }
            finally
            {
                if (position != null)
                {
                    position.Dispose();
                    position = null;
                }
            }
            return(itemArray);
        }