예제 #1
0
파일: Restrictions.cs 프로젝트: mo5h/omeo
        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();
            }
        }
예제 #2
0
파일: Restrictions.cs 프로젝트: mo5h/omeo
        public static string GetLinkResourceTypeRestriction(string fromResourceType, int linkType)
        {
            LinkRestriction restriction = FindLinkRestriction(fromResourceType, linkType);

            if (restriction != null)
            {
                return(restriction.ToResourceType);
            }
            return(null);
        }
예제 #3
0
파일: Restrictions.cs 프로젝트: mo5h/omeo
        public static int GetMaxLinkCountRestriction(string fromResourceType, int linkType)
        {
            LinkRestriction restriction = FindLinkRestriction(fromResourceType, linkType);

            if (restriction != null)
            {
                return(restriction.MaxCount);
            }
            return(Int32.MaxValue);
        }
예제 #4
0
파일: Restrictions.cs 프로젝트: mo5h/omeo
        public static int GetMinLinkCountRestriction(string fromResourceType, int linkType)
        {
            LinkRestriction restriction = FindLinkRestriction(fromResourceType, linkType);

            if (restriction != null)
            {
                return(restriction.MinCount);
            }
            return(0);
        }
예제 #5
0
파일: Restrictions.cs 프로젝트: mo5h/omeo
        public override bool Equals(object obj)
        {
            if (!(obj is LinkRestriction))
            {
                return(false);
            }
            LinkRestriction lr = (LinkRestriction)obj;

            return(_resourceType == lr._resourceType && _propId == lr._propId);
        }
예제 #6
0
파일: Restrictions.cs 프로젝트: mo5h/omeo
        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;
        }
예제 #7
0
파일: Restrictions.cs 프로젝트: mo5h/omeo
 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);
     }
 }