internal static void RegisterUniqueRestriction(string resourceType, int propId) { if (resourceType == null) { throw new ArgumentNullException("resourceType"); } if (!MyPalStorage.Storage.ResourceTypes.Exist(resourceType)) { throw new ArgumentException("Invalid resource type " + resourceType, resourceType); } PropDataType dataType = MyPalStorage.Storage.PropTypes [propId].DataType; if (dataType != PropDataType.Int && dataType != PropDataType.String && dataType != PropDataType.Date) { throw new StorageException("Unique restrictions may only be registered for int, string or date properties"); } UniqueRestriction restriction = new UniqueRestriction(resourceType, propId); if (AddResourceRestriction(restriction)) { restriction.SaveToResourceStore(); } }
public override bool Equals(object obj) { UniqueRestriction rhs = obj as UniqueRestriction; if (rhs == null) { return(false); } return(_propId == rhs._propId && _resourceType == rhs._resourceType); }
public static void RegisterTypes() { _store = MyPalStorage.Storage; _store.ResourceTypes.Register(LinkRestriction.RestrictionResourceType, String.Empty, string.Empty, ResourceTypeFlags.Internal | ResourceTypeFlags.NoIndex); _store.ResourceTypes.Register(UniqueRestriction.RestrictionResourceType, String.Empty, string.Empty, ResourceTypeFlags.Internal | ResourceTypeFlags.NoIndex); _store.ResourceTypes.Register(CustomRestriction.RestrictionResourceType, String.Empty, string.Empty, ResourceTypeFlags.Internal | ResourceTypeFlags.NoIndex); _propFromResourceType = _store.PropTypes.Register("fromResourceType", PropDataType.String, PropTypeFlags.Internal); _propToResourceType = _store.PropTypes.Register("toResourceType", PropDataType.String, PropTypeFlags.Internal); _propLinkType = _store.PropTypes.Register("LinkType", PropDataType.Int, PropTypeFlags.Internal); _propUniquePropId = _store.PropTypes.Register("UniquePropId", PropDataType.Int, PropTypeFlags.Internal); _propMinCount = _store.PropTypes.Register("MinCount", PropDataType.Int, PropTypeFlags.Internal); _propMaxCount = _store.PropTypes.Register("MaxCount", PropDataType.Int, PropTypeFlags.Internal); propCustomRestrictionClass = _store.PropTypes.Register("CustomRestrictionClass", PropDataType.String, PropTypeFlags.Internal); _restrictions = new HashMap(); _customRestrictions = new HashMap(); foreach (IResource res in _store.GetAllResources(LinkRestriction.RestrictionResourceType)) { LinkRestriction lr = new LinkRestriction(res); if (lr.ResourceType != null) { AddResourceRestriction(lr); } } foreach (IResource res in _store.GetAllResources(UniqueRestriction.RestrictionResourceType)) { UniqueRestriction restriction = new UniqueRestriction(res); if (restriction.ResourceType != null) { AddResourceRestriction(restriction); } } foreach (IResource res in _store.GetAllResources(CustomRestriction.RestrictionResourceType)) { CustomRestriction restriction = new CustomRestriction(res); if (restriction.ResourceType != null) { _customRestrictions [restriction.RestrictionClass] = restriction; AddResourceRestriction(restriction); } } _active = true; }
internal static void DeleteUniqueRestriction(string resourceType, int propId) { lock ( _restrictions ) { HashSet restrictionSet = (HashSet)_restrictions [resourceType]; if (restrictionSet != null) { UniqueRestriction restriction = new UniqueRestriction(resourceType, propId); restrictionSet.Remove(restriction); // this will delete the restriction which is equal to the given one restriction.DeleteFromResourceStore(); } } }