Beispiel #1
0
        internal static void RegisterLinkRestriction(string fromResourceType,
                                                     int linkType,
                                                     string toResourceType,
                                                     int minCount,
                                                     int maxCount)
        {
            if (!_active)
            {
                return;
            }

            if (fromResourceType == null)
            {
                throw new ArgumentNullException("fromResourceType");
            }
            if (!MyPalStorage.Storage.ResourceTypes.Exist(fromResourceType))
            {
                throw new ArgumentException("Invalid resource type " + fromResourceType, fromResourceType);
            }
            if (MyPalStorage.Storage.GetPropDataType(linkType) != PropDataType.Link)
            {
                throw new Exception("Link restrictions may only be registered for link properties");
            }

            LinkRestriction lr = new LinkRestriction(
                fromResourceType, toResourceType, linkType, minCount, maxCount);

            if (AddResourceRestriction(lr))
            {
                lr.SaveToResourceStore();
            }
        }
Beispiel #2
0
        public static string GetLinkResourceTypeRestriction(string fromResourceType, int linkType)
        {
            LinkRestriction restriction = FindLinkRestriction(fromResourceType, linkType);

            if (restriction != null)
            {
                return(restriction.ToResourceType);
            }
            return(null);
        }
Beispiel #3
0
        public static int GetMaxLinkCountRestriction(string fromResourceType, int linkType)
        {
            LinkRestriction restriction = FindLinkRestriction(fromResourceType, linkType);

            if (restriction != null)
            {
                return(restriction.MaxCount);
            }
            return(Int32.MaxValue);
        }
Beispiel #4
0
        public static int GetMinLinkCountRestriction(string fromResourceType, int linkType)
        {
            LinkRestriction restriction = FindLinkRestriction(fromResourceType, linkType);

            if (restriction != null)
            {
                return(restriction.MinCount);
            }
            return(0);
        }
Beispiel #5
0
        public override bool Equals(object obj)
        {
            if (!(obj is LinkRestriction))
            {
                return(false);
            }
            LinkRestriction lr = (LinkRestriction)obj;

            return(_resourceType == lr._resourceType && _propId == lr._propId);
        }
Beispiel #6
0
        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;
        }
Beispiel #7
0
 private static LinkRestriction FindLinkRestriction(string fromResourceType, int linkType)
 {
     lock ( _restrictions )
     {
         HashSet restrictionsSet = (HashSet)_restrictions[fromResourceType];
         if (restrictionsSet != null)
         {
             foreach (HashSet.Entry E in restrictionsSet)
             {
                 ResourceRestriction restriction = (ResourceRestriction)E.Key;
                 if (restriction.PropId == linkType)
                 {
                     LinkRestriction lr = restriction as LinkRestriction;
                     if (lr != null)
                     {
                         return(lr);
                     }
                 }
             }
         }
         return(null);
     }
 }