Exemplo n.º 1
0
        /// <summary>
        /// Returns the sub-condition names for the event condition.
        /// </summary>
        public void GetSubConditionNames(string conditionName, out string[] subConditionNames)
        {
            subConditionNames = null;
            string methodName = "IOPCEventServer.QuerySubConditionNames";

            int    count = 0;
            IntPtr pSubConditionNames = IntPtr.Zero;

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);

                server.QuerySubConditionNames(
                    conditionName,
                    out count,
                    out pSubConditionNames);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            subConditionNames = ComUtils.GetUnicodeStrings(ref pSubConditionNames, count, true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the event categories.
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="descriptions">The descriptions.</param>
        public void GetEventCategories(int eventType, out int[] categories, out string[] descriptions)
        {
            string methodName = "IOPCEventServer.QueryEventCategories";

            int    count         = 0;
            IntPtr pCategories   = IntPtr.Zero;
            IntPtr pDescriptions = IntPtr.Zero;

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);

                server.QueryEventCategories(
                    eventType,
                    out count,
                    out pCategories,
                    out pDescriptions);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            categories   = ComUtils.GetInt32s(ref pCategories, count, true);
            descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the property item ids.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="properties">The properties to update.</param>
        private void GetPropertyItemIds(string itemId, DaProperty[] properties)
        {
            string methodName = "IOPCItemProperties.LookupItemIDs";

            int count = properties.Length;

            // get list of ids to request.
            int[] propertyIds = new int[count];

            for (int ii = 0; ii < propertyIds.Length; ii++)
            {
                propertyIds[ii] = properties[ii].PropertyId;
            }

            // request the item ids.
            IntPtr pItemIds = IntPtr.Zero;
            IntPtr pErrors  = IntPtr.Zero;

            try
            {
                IOPCItemProperties server = BeginComCall <IOPCItemProperties>(methodName, true);

                server.LookupItemIDs(
                    itemId,
                    count,
                    propertyIds,
                    out pItemIds,
                    out pErrors);
            }
            catch (Exception e)
            {
                if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL, ResultIds.E_UNKNOWNITEMID, ResultIds.E_INVALIDITEMID))
                {
                    ComUtils.TraceComError(e, methodName);
                }

                return;
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            string[] itemIds = ComUtils.GetUnicodeStrings(ref pItemIds, count, true);
            int[]    errors  = ComUtils.GetInt32s(ref pErrors, count, true);

            // update the objects.
            for (int ii = 0; ii < count; ii++)
            {
                if (errors[ii] >= 0)
                {
                    properties[ii].ItemId = itemIds[ii];
                }
                else
                {
                    properties[ii].ItemId = null;
                }
            }
        }
Exemplo n.º 4
0
        public void QueryAvailableProperties(string itemId)
        {
            var pdwCount       = 0;
            var ppPropertyIds  = IntPtr.Zero;
            var ppDescriptions = IntPtr.Zero;
            var ppvtDataTypes  = IntPtr.Zero;

            _server.QueryAvailableProperties(itemId, out pdwCount, out ppPropertyIds, out ppDescriptions, out ppvtDataTypes);
            if (pdwCount > 0)
            {
                var ids   = ComUtils.GetInt32s(ref ppPropertyIds, pdwCount, true);
                var descs = ComUtils.GetUnicodeStrings(ref ppDescriptions, pdwCount, true);
                var types = ComUtils.GetInt16s(ref ppvtDataTypes, pdwCount, true);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the filter currently in use for event subscriptions.
        /// </summary>
        /// <param name="pdwEventType">Bit map specifying which event types are of allowed through the filter</param>
        /// <param name="pdwNumCategories">Length of the event category array returned.</param>
        /// <param name="ppdwEventCategories">Array of event categories for the filter.</param>
        /// <param name="pdwLowSeverity">Lowest severity allowed through filter.</param>
        /// <param name="pdwHighSeverity">Highest severity allowed through filter.</param>
        /// <param name="pdwNumAreas">Length of the area list array returned.</param>
        /// <param name="ppszAreaList">List of process areas for the filter.</param>
        /// <param name="pdwNumSources">Length of the event source list returned.</param>
        /// <param name="ppszSourceList">List of sources for the filter.</param>
        public void GetFilter(out int pdwEventType, out int pdwNumCategories, out IntPtr ppdwEventCategories, out int pdwLowSeverity, out int pdwHighSeverity, out int pdwNumAreas, out IntPtr ppszAreaList, out int pdwNumSources, out IntPtr ppszSourceList)
        {
            pdwEventType        = 0;
            pdwNumCategories    = 0;
            ppdwEventCategories = IntPtr.Zero;
            pdwLowSeverity      = 0;
            pdwHighSeverity     = 0;
            pdwNumAreas         = 0;
            ppszAreaList        = IntPtr.Zero;
            pdwNumSources       = 0;
            ppszSourceList      = IntPtr.Zero;

            try
            {
                pdwEventType    = m_dwEventType;
                pdwLowSeverity  = m_dwLowSeverity;
                pdwHighSeverity = m_dwHighSeverity;
                if (m_EventCategoryVector.Count != 0)
                {
                    int[] EventCategoryIDs = m_EventCategoryVector.ToArray();
                    pdwNumCategories    = m_EventCategoryVector.Count;
                    ppdwEventCategories = ComUtils.GetInt32s(EventCategoryIDs);
                }
                if (m_AreaVector.Count != 0)
                {
                    string[] Areas = m_AreaVector.ToArray();
                    pdwNumAreas  = m_AreaVector.Count;
                    ppszAreaList = ComUtils.GetUnicodeStrings(Areas);
                }
                if (m_SourceVector.Count != 0)
                {
                    string[] Sources = m_SourceVector.ToArray();
                    pdwNumSources  = m_SourceVector.Count;
                    ppszSourceList = ComUtils.GetUnicodeStrings(Sources);
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error in GetFilter");
                throw ComUtils.CreateComException(e);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the event attributes.
        /// </summary>
        /// <param name="categoryId">The category id.</param>
        /// <param name="attributeIds">The attribute ids.</param>
        /// <param name="descriptions">The descriptions.</param>
        /// <param name="datatypes">The datatypes.</param>
        public bool GetEventAttributes(
            int categoryId,
            out int[] attributeIds,
            out string[] descriptions,
            out short[] datatypes)
        {
            string methodName = "IOPCEventServer.QueryEventAttributes";

            int    count         = 0;
            IntPtr pAttributeIds = IntPtr.Zero;
            IntPtr pDescriptions = IntPtr.Zero;
            IntPtr pDataTypes    = IntPtr.Zero;

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);

                server.QueryEventAttributes(
                    categoryId,
                    out count,
                    out pAttributeIds,
                    out pDescriptions,
                    out pDataTypes);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            attributeIds = ComUtils.GetInt32s(ref pAttributeIds, count, true);
            descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true);
            datatypes    = ComUtils.GetInt16s(ref pDataTypes, count, true);

            // remove the AREAS attribute which is never exposed.
            for (int ii = 0; ii < count; ii++)
            {
                if (String.Compare(descriptions[ii], "AREAS", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    int[]    attributeIds2 = new int[count - 1];
                    string[] descriptions2 = new string[count - 1];
                    short[]  datatypes2    = new short[count - 1];

                    if (ii > 0)
                    {
                        Array.Copy(attributeIds, attributeIds2, ii);
                        Array.Copy(descriptions, descriptions2, ii);
                        Array.Copy(datatypes, datatypes2, ii);
                    }

                    if (ii < count - 1)
                    {
                        Array.Copy(attributeIds, ii + 1, attributeIds2, ii, count - ii - 1);
                        Array.Copy(descriptions, ii + 1, descriptions2, ii, count - ii - 1);
                        Array.Copy(datatypes, ii + 1, datatypes2, ii, count - ii - 1);
                    }

                    attributeIds = attributeIds2;
                    descriptions = descriptions2;
                    datatypes    = datatypes2;
                    break;
                }
            }

            return(count > 0);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Read the available non-built in properties from the server.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="updateCache">if set to <c>true</c> the cache is updated.</param>
        /// <returns>The array of properties.</returns>
        public DaProperty[] ReadAvailableProperties(string itemId, bool updateCache)
        {
            string methodName = "IOPCItemProperties.QueryAvailableProperties";

            // query for available properties.
            int count = 0;

            IntPtr pPropertyIds  = IntPtr.Zero;
            IntPtr pDescriptions = IntPtr.Zero;
            IntPtr pDataTypes    = IntPtr.Zero;

            try
            {
                IOPCItemProperties server = BeginComCall <IOPCItemProperties>(methodName, true);

                server.QueryAvailableProperties(
                    itemId,
                    out count,
                    out pPropertyIds,
                    out pDescriptions,
                    out pDataTypes);
            }
            catch (Exception e)
            {
                if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL, ResultIds.E_UNKNOWNITEMID, ResultIds.E_INVALIDITEMID))
                {
                    ComUtils.TraceComError(e, methodName);
                }

                return(null);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            int[]    propertyIds  = ComUtils.GetInt32s(ref pPropertyIds, count, true);
            string[] descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true);
            short[]  datatype     = ComUtils.GetInt16s(ref pDataTypes, count, true);

            List <DaProperty> properties = new List <DaProperty>();

            for (int ii = 0; ii < count; ii++)
            {
                // do not return any of the built in properties.
                if (propertyIds[ii] <= PropertyIds.TimeZone)
                {
                    continue;
                }

                DaProperty property = new DaProperty();

                property.PropertyId = propertyIds[ii];
                property.Name       = descriptions[ii];
                property.DataType   = datatype[ii];

                properties.Add(property);
            }

            // fetch the item ids.
            if (properties.Count > 0)
            {
                DaProperty[] array = properties.ToArray();

                GetPropertyItemIds(itemId, array);

                // update the cache.
                if (updateCache)
                {
                    lock (m_cache)
                    {
                        DaElement element = null;

                        if (m_cache.TryGetValue(itemId, out element))
                        {
                            element.Properties = array;
                        }
                    }
                }

                return(array);
            }

            return(null);
        }