示例#1
0
文件: Restrictions.cs 项目: mo5h/omeo
        internal static void RegisterCustomRestriction(string resourceType, int propId,
                                                       IResourceRestriction restriction)
        {
            if (resourceType == null)
            {
                throw new ArgumentNullException("resourceType");
            }
            if (!MyPalStorage.Storage.ResourceTypes.Exist(resourceType))
            {
                throw new ArgumentException("Invalid resource type " + resourceType, resourceType);
            }

            string            restrictionClass    = restriction.GetType().FullName;
            CustomRestriction existingRestriction = (CustomRestriction)_customRestrictions [restrictionClass];

            if (existingRestriction != null)
            {
                existingRestriction.SetImplementation(restriction);
            }
            else
            {
                CustomRestriction customRestriction = new CustomRestriction(resourceType, propId, restriction);
                AddResourceRestriction(customRestriction);
                customRestriction.SaveToResourceStore();
                _customRestrictions [restrictionClass] = customRestriction;
            }
        }
示例#2
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;
        }
示例#3
0
文件: Restrictions.cs 项目: mo5h/omeo
 internal static void DeleteCustomRestriction(string resourceType, int propId)
 {
     lock ( _restrictions )
     {
         HashSet restrictionSet = (HashSet)_restrictions [resourceType];
         if (restrictionSet != null)
         {
             foreach (HashSet.Entry e in restrictionSet)
             {
                 CustomRestriction restriction = e.Key as CustomRestriction;
                 if (restriction != null && restriction.PropId == propId)
                 {
                     restrictionSet.Remove(restriction);
                     _customRestrictions.Remove(restriction.RestrictionClass);
                     restriction.DeleteFromResourceStore();
                 }
             }
         }
     }
 }