Exemple #1
0
        /// <summary>
        /// Registers one or more <see cref="IPermissionDescriptor"/> instances.
        /// </summary>
        /// <param name="permissionDescriptors">The permission descriptors.</param>
        public void RegisterPermissionDescriptor(params IPermissionDescriptor[] permissionDescriptors)
        {
            foreach (var permissionDescriptor in permissionDescriptors)
            {
                Logger.Debug(string.Format("Registering Permission Descriptor: {0}", permissionDescriptor.GetType().FullName));
                foreach (var resource in permissionDescriptor.Resources)
                {
                    Logger.Debug(string.Format("Registering Resource: {0}", resource));
                    var resourceName = resource.Name;

                    var resourceAdded = _resourceList.FirstOrDefault(r => r.Name == resourceName);
                    if (resourceAdded != null)
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      "Cannot add Resource ({0}) for Permission ({1}) because Resource ({0}) has already been added for Permission ({2}).",
                                      resource.Name,
                                      resource.Permission.Name,
                                      resourceAdded.Permission.Name));
                    }

                    _resourceList.Add(resource);
                }
            }
        }
        public PagedList(
            int pageIndex,
            int pageSize,
            int knownPagesAvailable,
            int totalItemsCount,
            IEnumerable <T> items,
            string rel,
            string curie,
            SortDirection sortDirection,
            string sortProperty)
            : base(items.ToList())
        {
            PageIndex           = pageIndex;
            PageSize            = pageSize;
            KnownPagesAvailable = knownPagesAvailable;
            TotalItemsCount     = totalItemsCount;

            var relationship = rel.Contains(':') ? rel : $"{curie}:{rel}";
            var item         = ResourceList.FirstOrDefault();

            if (item != null)
            {
                item.Rel = relationship;
            }
            Rel           = relationship;
            Curie         = curie;
            SortDirection = sortDirection;
            SortProperty  = sortProperty;
        }