Exemplo n.º 1
0
        private void Load()
        {
            if (Invalid)
            {
                IsInitialized = false;
            }

            if (!IsInitialized)
            {
                Collection = new System.Collections.Generic.List <OlapAttributeTableField>(0);
                System.Collections.ArrayList fields = NativeOlapApi.AttributeTableFields(_attributeTable.Dimension.Server.Store.ClientSlot, _attributeTable.Dimension.Server.ServerHandle, this._attributeTable.Dimension.Name, _attributeTable.Id, _attributeTable.Dimension.Server.LastErrorInternal);
                if (fields != null)
                {
                    for (int i = 0; i < fields.Count; i++)
                    {
                        OlapAttributeTableFieldDefinition fieldDef = (OlapAttributeTableFieldDefinition)fields[i];
                        OlapAttributeTableFieldType       type;
                        switch (fieldDef.Type)
                        {
                        case 'C':
                            type = OlapAttributeTableFieldType.OlapAttributeTableFieldTypeCharacter;
                            break;

                        case 'N':
                            type = OlapAttributeTableFieldType.OlapAttributeTableFieldTypeNumeric;
                            break;

                        case 'D':
                            type = OlapAttributeTableFieldType.OlapAttributeTableFieldTypeDate;
                            break;

                        case 'L':
                            type = OlapAttributeTableFieldType.OlapAttributeTableFieldTypeLogical;
                            break;

                        default:
                            throw new OlapException("Found unknown attribute field type: " + fieldDef.Type);
                        }
                        Collection.Add(new OlapAttributeTableField(_attributeTable, fieldDef.FieldName, fieldDef.Id, fieldDef.FieldWidth, fieldDef.Decimals, type));
                    }
                }
                else
                {
                    if (_attributeTable.Dimension.Server.LastErrorInternal.Value != 0)
                    {
                        throw new OlapException("Receiving the attribute table field collection failed!", _attributeTable.Dimension.Server.LastErrorInternal.Value);
                    }
                }
                Invalid       = false;
                IsInitialized = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the specified attribute field value for the element.
        /// </summary>
        /// <param name="table">The attribute table that has the field.</param>
        /// <param name="field">The field for which to get the value.</param>
        /// <returns>An object that holds the value. Returns null, if the value was not found.</returns>
        // [System::Runtime::CompilerServices::IndexerNameAttribute("Attribute")]
        public object this[OlapAttributeTable table, OlapAttributeTableField field]
        {
            get
            {
                string key            = string.Empty;
                bool   cacheAttribute = false;
                int    tableId        = table.Id;

                if (_dimension.CacheAttributes)
                {
                    key            = string.Concat(_name, KeySeparator, field.Name);
                    cacheAttribute = true;
                    bool found = false;

                    switch (tableId)
                    {
                    case 1:
                        found = _dimension.Attribute1Cache.ContainsKey(key);
                        if (found)
                        {
                            return(_dimension.Attribute1Cache[key]);
                        }
                        break;

                    case 2:
                        found = _dimension.Attribute2Cache.ContainsKey(key);
                        if (found)
                        {
                            return(_dimension.Attribute2Cache[key]);
                        }
                        break;

                    case 3:
                        found = _dimension.Attribute3Cache.ContainsKey(key);
                        if (found)
                        {
                            return(_dimension.Attribute3Cache[key]);
                        }
                        break;

                    default:
                        throw new OlapException("Invalid attribute table requested");
                    }
                }

                OlapAttributeTableFieldDefinition def = new OlapAttributeTableFieldDefinition();
                def.Type       = (char)field.Type;
                def.Decimals   = field.Decimals;
                def.FieldWidth = field.Width;
                object result = NativeOlapApi.AttributeGetValue(_dimension.Server.Store.ClientSlot, _dimension.Server.ServerHandle, _dimension.Name, tableId, field.Name, _name, def, _dimension.Server.LastErrorInternal);

                if (cacheAttribute)
                {
                    switch (tableId)
                    {
                    case 1:
                        _dimension.Attribute1Cache.Add(key, result);
                        break;

                    case 2:
                        _dimension.Attribute2Cache.Add(key, result);
                        break;

                    case 3:
                        _dimension.Attribute3Cache.Add(key, result);
                        break;
                    }
                }

                return(result);
            }

            set
            {
                OlapAttributeTableFieldDefinition def = new OlapAttributeTableFieldDefinition();
                def.Type       = (char)field.Type;
                def.Decimals   = field.Decimals;
                def.FieldWidth = field.Width;
                NativeOlapApi.AttributeSetValue(_dimension.Server.Store.ClientSlot, _dimension.Server.ServerHandle, _dimension.Name, table.Id, field.Name, _name, def, value, _dimension.Server.LastErrorInternal);
            }
        }