Beispiel #1
0
        //-
        #endregion

        /// <summary>
        /// Gives information about the vendor-specific attributes the server can provide as part of an event
        /// notification for an event within the current event category.
        /// </summary>
        /// <param name="attributes">A list with the vendor-specific event attributes associated with the current event category.</param>
        /// <param name="executionOptions">Specifies the modality of execution for quering the attributes associated with the current event category.</param>
        /// <returns>The result of quering the attributes associated with the current event category.</returns>
        /// <include
        ///  file='TBNC.doc.xml'
        ///  path='//class[@name="AeCategory"]/method[@name="QueryAeAttributes"]/doc/*'
        /// />
        public virtual int QueryAeAttributes(
            out AeAttribute[] attributes,
            ExecutionOptions executionOptions)
        {
            attributes = new AeAttribute[0];
            int res = (int)EnumResultCode.E_FAIL;

            if (this.Session == null)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "AeCategory.QueryAeAttributes",
                    "The Session property of the Category cannot be null! Set the property to a value before calling QueryAEAttributes!");
                return(res);
            }

            try
            {
                OTCExecutionOptions options = new OTCExecutionOptions();
                if (executionOptions != null)
                {
                    options.m_executionType    = (byte)executionOptions.ExecutionType;
                    options.m_executionContext = (uint)executionOptions.ExecutionContext;
                }
                else
                {
                    options.m_executionType    = (byte)EnumExecutionType.SYNCHRONOUS;
                    options.m_executionContext = 0;
                }

                uint   attributesCount       = 0;
                IntPtr attributeIDs          = IntPtr.Zero;
                IntPtr attributeDescriptions = IntPtr.Zero;
                IntPtr attributeDataTypes    = IntPtr.Zero;

                res = OTBFunctions.OTCQueryAEAttributes(
                    this.Session.Handle,
                    this.Id,
                    out attributesCount,
                    out attributeIDs,
                    out attributeDescriptions,
                    out attributeDataTypes,
                    ref options);

                if (ResultCode.SUCCEEDED(res))
                {
                    if (options.m_executionType == (byte)EnumExecutionType.SYNCHRONOUS)
                    {
                        attributes = new AeAttribute[attributesCount];

                        int uintSize   = Marshal.SizeOf(typeof(uint));
                        int ptrSize    = Marshal.SizeOf(typeof(IntPtr));
                        int ushortSize = Marshal.SizeOf(typeof(ushort));

                        for (int i = 0; i < attributesCount; i++)
                        {
                            uint attributeID =
                                (uint)Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(attributeIDs, i * uintSize), typeof(uint));
                            ushort attributeDataType =
                                (ushort)Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(attributeDataTypes, i * ushortSize), typeof(ushort));
                            IntPtr attributeDescription =
                                (IntPtr)Marshal.PtrToStructure(OTBFunctions.GetIntPtrOffset(attributeDescriptions, i * ptrSize), typeof(IntPtr));
                            attributes[i] = new AeAttribute(
                                attributeID,
                                Marshal.PtrToStringUni(attributeDescription),
                                ValueQT.GetSysType(attributeDataType));

                            OTBFunctions.OTFreeMemory(attributeDescription);
                        }                         //	end for

                        OTBFunctions.OTFreeMemory(attributeIDs);
                        OTBFunctions.OTFreeMemory(attributeDescriptions);
                        OTBFunctions.OTFreeMemory(attributeDataTypes);
                    }                     //	end if
                }
                else
                {
                    Application.Instance.Trace(
                        EnumTraceLevel.ERR,
                        EnumTraceGroup.CLIENT,
                        "AeCategory.QueryAeAttributes",
                        "Quering AeAttributes failed! Result: " + res);
                }
            }
            catch (Exception exc)
            {
                Application.Instance.Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.CLIENT,
                    "AeCategory.QueryAeAttributes",
                    exc.ToString());
            }
            return(res);
        }