// Token: 0x06000EC7 RID: 3783 RVA: 0x0005E028 File Offset: 0x0005C228
        private void ParseAndAddStruct(ArrayList itemArray)
        {
            OwaEventStructAttribute owaEventStructAttribute = OwaEventRegistry.FindStructInfo(this.reader.Name);

            if (owaEventStructAttribute != null)
            {
                bool   isEmptyElement = this.reader.IsEmptyElement;
                object value          = this.ParseStruct(owaEventStructAttribute);
                if (itemArray != null)
                {
                    base.AddStructToArray(this.paramInfo, itemArray, value);
                }
                else
                {
                    base.AddStructParameter(this.paramInfo, value);
                }
                if (!isEmptyElement)
                {
                    if (!this.reader.Read())
                    {
                        this.ThrowParserException("Unexpected end of request");
                    }
                    else if (this.reader.NodeType != XmlNodeType.EndElement || !string.Equals(owaEventStructAttribute.Name, this.reader.Name, StringComparison.Ordinal))
                    {
                        this.ThrowParserException("Expected end of struct");
                    }
                }
                if (!this.reader.Read())
                {
                    this.ThrowParserException("Unexpected end of request");
                    return;
                }
                if (itemArray != null)
                {
                    if (this.reader.NodeType != XmlNodeType.EndElement || !string.Equals(this.reader.Name, "item", StringComparison.OrdinalIgnoreCase))
                    {
                        this.ThrowParserException("Expected end of item");
                        return;
                    }
                }
                else if (this.reader.NodeType != XmlNodeType.EndElement || !string.Equals(this.reader.Name, this.paramInfo.Name, StringComparison.Ordinal))
                {
                    this.ThrowParserException("Expected end of param");
                    return;
                }
            }
            else
            {
                this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Type '{0}' is unknown", new object[]
                {
                    this.reader.Name
                }));
            }
        }
        // Token: 0x06000EC8 RID: 3784 RVA: 0x0005E184 File Offset: 0x0005C384
        private object ParseStruct(OwaEventStructAttribute structInfo)
        {
            uint   num = 0U;
            object obj = Activator.CreateInstance(structInfo.StructType);

            if (this.reader.MoveToFirstAttribute())
            {
                int num2 = 0;
                do
                {
                    if (num2 >= 32)
                    {
                        this.ThrowParserException("Reached maximum number of fields per struct");
                    }
                    num2++;
                    OwaEventFieldAttribute owaEventFieldAttribute = structInfo.FindFieldInfo(this.reader.Name);
                    if (owaEventFieldAttribute == null)
                    {
                        this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Field '{0}' doesn't exist", new object[]
                        {
                            this.reader.Name
                        }));
                    }
                    FieldInfo fieldInfo = owaEventFieldAttribute.FieldInfo;
                    Type      fieldType = owaEventFieldAttribute.FieldType;
                    object    value;
                    if (fieldType != typeof(string))
                    {
                        value = base.ConvertToStrongType(owaEventFieldAttribute.FieldType, this.reader.Value);
                    }
                    else
                    {
                        value = this.reader.Value;
                    }
                    fieldInfo.SetValue(obj, value);
                    if ((num & owaEventFieldAttribute.FieldMask) != 0U)
                    {
                        this.ThrowParserException(string.Format(CultureInfo.InvariantCulture, "Field '{0}' is found twice", new object[]
                        {
                            this.reader.Name
                        }));
                    }
                    num |= owaEventFieldAttribute.FieldMask;
                }while (this.reader.MoveToNextAttribute());
            }
            if ((structInfo.RequiredMask & num) != structInfo.RequiredMask)
            {
                this.ThrowParserException("A required field in the struct wasn't present");
            }
            if (num != structInfo.AllFieldsMask)
            {
                uint num3 = ~num & structInfo.AllFieldsMask;
                for (int i = 0; i < structInfo.FieldCount; i++)
                {
                    if ((num3 & 1U) != 0U)
                    {
                        OwaEventFieldAttribute owaEventFieldAttribute2 = structInfo.FieldInfoIndexTable[i];
                        owaEventFieldAttribute2.FieldInfo.SetValue(obj, owaEventFieldAttribute2.DefaultValue);
                    }
                    num3 >>= 1;
                }
            }
            return(obj);
        }
Example #3
0
        public static void RegisterStruct(Type structType)
        {
            ExTraceGlobals.OehCallTracer.TraceDebug(0L, "OwaEventRegistry.RegisterStruct");
            if (structType == null)
            {
                throw new ArgumentNullException("structType");
            }
            object[] customAttributes = structType.GetCustomAttributes(typeof(OwaEventStructAttribute), false);
            if (customAttributes == null || customAttributes.Length == 0)
            {
                throw new OwaNotSupportedException("Struct type is missing the OwaEventStructAttribute attribute");
            }
            OwaEventStructAttribute owaEventStructAttribute = (OwaEventStructAttribute)customAttributes[0];

            owaEventStructAttribute.StructType = structType;
            ExTraceGlobals.OehDataTracer.TraceDebug <Type>(0L, "Struct type: '{0}'", structType);
            Type type = null;

            customAttributes = structType.GetCustomAttributes(typeof(OwaEventObjectIdAttribute), false);
            if (customAttributes != null && customAttributes.Length > 0)
            {
                type = ((OwaEventObjectIdAttribute)customAttributes[0]).ObjectIdType;
            }
            FieldInfo[] fields = structType.GetFields(BindingFlags.Instance | BindingFlags.Public);
            int         num    = 0;
            uint        num2   = 0U;

            foreach (FieldInfo fieldInfo in fields)
            {
                customAttributes = fieldInfo.GetCustomAttributes(typeof(OwaEventFieldAttribute), false);
                if (customAttributes != null && customAttributes.Length > 0)
                {
                    OwaEventFieldAttribute owaEventFieldAttribute = (OwaEventFieldAttribute)customAttributes[0];
                    owaEventFieldAttribute.FieldInfo = fieldInfo;
                    owaEventFieldAttribute.FieldType = fieldInfo.FieldType;
                    if (type != null && owaEventFieldAttribute.FieldType == typeof(ObjectId))
                    {
                        owaEventFieldAttribute.FieldType = type;
                    }
                    if (!OwaEventRegistry.IsAllowedFieldType(owaEventFieldAttribute.FieldType))
                    {
                        throw new OwaNotSupportedException("Field type is not supported.");
                    }
                    owaEventFieldAttribute.FieldMask       = 1U << num;
                    owaEventStructAttribute.AllFieldsMask |= owaEventFieldAttribute.FieldMask;
                    if (!owaEventFieldAttribute.IsOptional)
                    {
                        num2 |= owaEventFieldAttribute.FieldMask;
                    }
                    else if (fieldInfo.FieldType == typeof(ExDateTime))
                    {
                        owaEventFieldAttribute.DefaultValue = ExDateTime.MinValue;
                    }
                    if (num >= 32)
                    {
                        throw new OwaNotSupportedException("Struct declares more fields than allowed");
                    }
                    owaEventStructAttribute.AddFieldInfo(owaEventFieldAttribute, num);
                    num++;
                    ExTraceGlobals.OehDataTracer.TraceDebug <string, Type>(0L, "Struct field found, name: '{0}', type: '{1}'", owaEventStructAttribute.Name, owaEventFieldAttribute.FieldType);
                }
            }
            if (num == 0)
            {
                throw new OwaNotSupportedException("Struct must have at least one field");
            }
            owaEventStructAttribute.FieldCount   = num;
            owaEventStructAttribute.RequiredMask = num2;
            OwaEventRegistry.structTable.Add(owaEventStructAttribute.Name, owaEventStructAttribute);
            OwaEventRegistry.structTypeTable.Add(owaEventStructAttribute.StructType, owaEventStructAttribute);
        }