Exemplo n.º 1
0
        /**
         * Unregisters the specified property type and deletes all properties
         * of that type.
         */

        public void Delete(int id)
        {
            PropTypeItem item = FindPropTypeItem(id);

            if (item.DataType == PropDataType.Link)
            {
                _storage.DeleteLinksOfType(id);
            }
            else
            {
                _storage.DeletePropsOfType(id);
            }
            ResourceRestrictions.DeletePropRestrictions(id);

            IResultSet rs = _propTypeTable.CreateModifiableResultSet(0, id);

            try
            {
                SafeRecordEnumerator enumerator = new SafeRecordEnumerator(rs, "PropTypes.Delete");
                using ( enumerator )
                {
                    if (!enumerator.MoveNext())
                    {
                        MyPalStorage.Storage.OnIndexCorruptionDetected("PropTypeCollection.Delete: Attempt to delete non-existing property type " + id);
                    }
                    else
                    {
                        IRecord rec = enumerator.Current;
                        _storage.SafeDeleteRecord(rec, "PropTypes.Delete");
                    }
                }
            }
            finally
            {
                rs.Dispose();
            }

            IResource propTypeRes = _storage.FindUniqueResource("PropType", "ID", id);

            Debug.Assert(propTypeRes != null);
            propTypeRes.Delete();
        }
Exemplo n.º 2
0
        internal void Initialize()
        {
            // during initial bootstrap - use two-step setting of display name template
            // during later startups - use correct template from the start to avoid extra ResourceTypes writes
            string defaultDisplayNameTemplate = "";

            if (_propTypes.Exist("Name") && _propTypes.Exist("PropDisplayName"))
            {
                defaultDisplayNameTemplate = "PropDisplayName | Name";
            }

            bool propTypeNewType, resourceTypeNewType;
            int  resPropType = _resourceTypes.RegisterResourceTypeInternal("PropType", defaultDisplayNameTemplate,
                                                                           ResourceTypeFlags.Internal | ResourceTypeFlags.NoIndex, true, out propTypeNewType);
            int resResourceType = _resourceTypes.RegisterResourceTypeInternal("ResourceType", defaultDisplayNameTemplate,
                                                                              ResourceTypeFlags.Internal | ResourceTypeFlags.NoIndex, true, out resourceTypeNewType);

            bool nameNewType, idNewType, dataTypeNewType, displayNameMaskNewType, flagsNewType,
                 propDisplayNameNewType, internalNewType, noIndexNewType, resourceContainerNewType,
                 fileFormatNewType, canBeUnreadNewType;

            _propName = _propTypes.RegisterPropTypeInternal("Name", PropDataType.String, PropTypeFlags.Normal,
                                                            true, out nameNewType);
            _propId = _propTypes.RegisterPropTypeInternal("ID", PropDataType.Int, PropTypeFlags.Internal,
                                                          true, out idNewType);
            _propDataType = _propTypes.RegisterPropTypeInternal("DataType", PropDataType.Int, PropTypeFlags.Internal,
                                                                true, out dataTypeNewType);
            _propDisplayNameMask = _propTypes.RegisterPropTypeInternal("DisplayNameMask", PropDataType.String,
                                                                       PropTypeFlags.Internal, true, out displayNameMaskNewType);
            _propFlags = _propTypes.RegisterPropTypeInternal("Flags", PropDataType.Int, PropTypeFlags.Internal,
                                                             true, out flagsNewType);
            _propPropDisplayName = _propTypes.RegisterPropTypeInternal("PropDisplayName", PropDataType.String, PropTypeFlags.Internal,
                                                                       true, out propDisplayNameNewType);
            _propInternal = _propTypes.RegisterPropTypeInternal("Internal", PropDataType.Int, PropTypeFlags.Internal,
                                                                true, out internalNewType);
            _propNoIndex = _propTypes.RegisterPropTypeInternal("NoIndex", PropDataType.Int, PropTypeFlags.Internal,
                                                               true, out noIndexNewType);
            _propFileFormat = _propTypes.RegisterPropTypeInternal("FileFormat", PropDataType.Int, PropTypeFlags.Internal,
                                                                  true, out fileFormatNewType);
            _propResourceContainer = _propTypes.RegisterPropTypeInternal("ResourceContainer", PropDataType.Int, PropTypeFlags.Internal,
                                                                         true, out resourceContainerNewType);
            _propCanBeUnread = _propTypes.RegisterPropTypeInternal("CanBeUnread", PropDataType.Bool, PropTypeFlags.Internal,
                                                                   true, out canBeUnreadNewType);

            _resourceTypes.CreateOrUpdateResourceTypeResource("PropType", "PropType", defaultDisplayNameTemplate,
                                                              ResourceTypeFlags.Internal | ResourceTypeFlags.NoIndex, null, resPropType, propTypeNewType);
            _resourceTypes.CreateOrUpdateResourceTypeResource("ResourceType", "ResourceType", defaultDisplayNameTemplate,
                                                              ResourceTypeFlags.Internal | ResourceTypeFlags.NoIndex, null, resResourceType, resourceTypeNewType);

            _propTypes.CreateOrUpdatePropTypeResource("Name", PropDataType.String, PropTypeFlags.Normal,
                                                      null, _propName, nameNewType);
            _propTypes.CreateOrUpdatePropTypeResource("ID", PropDataType.Int, PropTypeFlags.Internal,
                                                      null, _propId, idNewType);
            _propTypes.CreateOrUpdatePropTypeResource("DataType", PropDataType.Int, PropTypeFlags.Internal,
                                                      null, _propDataType, dataTypeNewType);
            _propTypes.CreateOrUpdatePropTypeResource("DisplayNameMask", PropDataType.String, PropTypeFlags.Internal,
                                                      null, _propDisplayNameMask, displayNameMaskNewType);
            _propTypes.CreateOrUpdatePropTypeResource("Flags", PropDataType.Int, PropTypeFlags.Internal,
                                                      null, _propFlags, flagsNewType);
            _propTypes.CreateOrUpdatePropTypeResource("PropDisplayName", PropDataType.String, PropTypeFlags.Internal,
                                                      null, _propPropDisplayName, propDisplayNameNewType);
            _propTypes.CreateOrUpdatePropTypeResource("Internal", PropDataType.Int, PropTypeFlags.Internal,
                                                      null, _propInternal, internalNewType);
            _propTypes.CreateOrUpdatePropTypeResource("NoIndex", PropDataType.Int, PropTypeFlags.Internal,
                                                      null, _propNoIndex, noIndexNewType);
            _propTypes.CreateOrUpdatePropTypeResource("FileFormat", PropDataType.Int, PropTypeFlags.Internal,
                                                      null, _propFileFormat, fileFormatNewType);
            _propTypes.CreateOrUpdatePropTypeResource("ResourceContainer", PropDataType.Int, PropTypeFlags.Internal,
                                                      null, _propResourceContainer, resourceContainerNewType);
            _propTypes.CreateOrUpdatePropTypeResource("CanBeUnread", PropDataType.Bool, PropTypeFlags.Internal,
                                                      null, _propCanBeUnread, canBeUnreadNewType);

            _propDisplayName = _propTypes.Register("_DisplayName", PropDataType.String, PropTypeFlags.Internal);

            _propTypes.Register("Custom", PropDataType.Int, PropTypeFlags.Internal);
            _propTypes.Register("ReverseDisplayName", PropDataType.String, PropTypeFlags.Internal);
            _propTypes.Register("OwnerPluginList", PropDataType.StringList, PropTypeFlags.Internal);

            if (defaultDisplayNameTemplate == "")
            {
                _resourceTypes ["ResourceType"].ResourceDisplayNameTemplate = "PropDisplayName | Name";
                _resourceTypes ["PropType"].ResourceDisplayNameTemplate     = "PropDisplayName | Name";
            }

            ResourceRestrictions.RegisterTypes();

            MyPalStorage.Storage.RegisterUniqueRestriction("ResourceType", _propName);
            MyPalStorage.Storage.RegisterUniqueRestriction("PropType", _propName);
            MyPalStorage.Storage.RegisterUniqueRestriction("PropType", _propId);
        }