Beispiel #1
0
        internal void   UpdatePropTypeFlags(int propId, PropTypeFlags flags)
        {
            PropTypeItem propType = (PropTypeItem)_propTypeCache [propId];

            propType.SetFlags(flags);

            IResource res = _storage.FindUniqueResource("PropType", "ID", propId);

            if (res != null)
            {
                res.SetProp("Flags", (int)flags);

                UpdatePropTypeRecord(propType.Name, res);
            }
            else
            {
                MyPalStorage.Storage.OnIndexCorruptionDetected("Could not find PropType resource with ID " + propId);
            }
        }
Beispiel #2
0
        /**
         * When a PropType resource is changed, updates the DB data for it.
         */

        internal void UpdatePropType(Resource res)
        {
            string propName = res.GetStringProp("Name");

            if (propName == null)
            {
                MyPalStorage.Storage.OnIndexCorruptionDetected("UpdatePropType: Name property missing on PropType resource");
                return;
            }

            int propId = this [propName].Id;

            UpdatePropTypeRecord(propName, res);

            PropTypeItem propTypeItem = FindPropTypeItem(propId);

            Debug.Assert(propTypeItem.Name == propName);
            propTypeItem.SetFlags((PropTypeFlags)res.GetIntProp("Flags"));
        }
Beispiel #3
0
        /**
         * Adds a record for the specified prop type to the DB.
         */

        internal int RegisterPropTypeInternal(string name, PropDataType propType, PropTypeFlags flags,
                                              bool forceType, out bool newPropType)
        {
            _storage.CheckOwnerThread();
            IRecord rec = _propTypeTable.GetRecordByEqual(1, name);

            if (rec != null)
            {
                if (!_propTypeNameCache.ContainsKey(name))
                {
                    throw new BadIndexesException("Property type " + name + " found in PropTypes table but missing in name cache");
                }

                bool recordChanged = false;
                if (rec.GetIntValue(2) != (int)propType)
                {
                    if (forceType)
                    {
                        rec.SetValue(2, IntInternalizer.Intern((int)propType));
                        ((PropTypeItem)this[name]).SetDataType(propType);
                        recordChanged = true;
                    }
                    else
                    {
                        throw new StorageException("Inconsistent registration for property type " + name +
                                                   ": old type " + (PropDataType)rec.GetIntValue(2) + ", new type " + propType);
                    }
                }
                int           propId   = rec.GetIntValue(0);
                PropTypeFlags newFlags = flags | this [propId].Flags;
                if (rec.GetIntValue(3) != (int)newFlags)
                {
                    rec.SetValue(3, (int)newFlags);
                    recordChanged = true;
                }
                if (recordChanged)
                {
                    rec.Commit();
                }

                newPropType = false;
                PropTypeItem propTypeItem = (PropTypeItem)_propTypeCache [propId];
                propTypeItem.SetFlags(newFlags);
                return(propId);
            }

            if ((flags & (PropTypeFlags.DirectedLink | PropTypeFlags.CountUnread)) != 0 &&
                propType != PropDataType.Link)
            {
                throw new StorageException("DirectedLink and CountUnread flags can be used only on Link properties");
            }

            int ID;

            lock ( _propTypeTable )
            {
                IRecord propertyType = _propTypeTable.NewRecord();
                propertyType.SetValue(1, name);
                propertyType.SetValue(2, IntInternalizer.Intern((int)propType));
                propertyType.SetValue(3, (int)flags);
                _storage.SafeCommitRecord(propertyType, "PropTypeCollection.RegisterPropTypeInternal");
                ID = propertyType.GetID();
                if (ID > 65536)
                {
                    MyPalStorage.Storage.OnIndexCorruptionDetected("Invalid next ID in property type table");
                }
            }

            AddPropTypeToCache(ID, name, propType, flags);

            newPropType = true;
            return(ID);
        }