예제 #1
0
        public List <EnumValueInfo> GetAccessTypesFromAssembly(Assembly assembly, MetadataCache cache)
        {
            ArgumentUtility.CheckNotNull("assembly", assembly);
            ArgumentUtility.CheckNotNull("cache", cache);

            List <EnumValueInfo> accessTypes = new List <EnumValueInfo> ();

            foreach (var type in AssemblyTypeCache.GetTypes(assembly))
            {
                if (type.IsEnum && Attribute.IsDefined(type, typeof(AccessTypeAttribute), false))
                {
                    Dictionary <Enum, EnumValueInfo> values = _enumerationReflector.GetValues(type, cache);
                    foreach (KeyValuePair <Enum, EnumValueInfo> entry in values)
                    {
                        if (!cache.ContainsAccessType(entry.Key))
                        {
                            cache.AddAccessType(entry.Key, entry.Value);
                        }
                        accessTypes.Add(entry.Value);
                    }
                }
            }

            return(accessTypes);
        }
예제 #2
0
        public SecurableClassInfo GetMetadata(Type type, MetadataCache cache)
        {
            ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("type", type, typeof(ISecurableObject));
            if (type.IsValueType)
            {
                throw new ArgumentException("Value types are not supported.", "type");
            }
            ArgumentUtility.CheckNotNull("cache", cache);

            SecurableClassInfo info = cache.GetSecurableClassInfo(type);

            if (info == null)
            {
                info      = new SecurableClassInfo();
                info.Name = TypeUtility.GetPartialAssemblyQualifiedName(type);
                PermanentGuidAttribute guidAttribute = (PermanentGuidAttribute)Attribute.GetCustomAttribute(type, typeof(PermanentGuidAttribute), true);
                if (guidAttribute != null)
                {
                    info.ID = guidAttribute.Value.ToString();
                }
                info.Properties.AddRange(GetProperties(type, cache));
                info.AccessTypes.AddRange(_accessTypeReflector.GetAccessTypesFromType(type, cache));

                cache.AddSecurableClassInfo(type, info);

                if (typeof(ISecurableObject).IsAssignableFrom(type.BaseType))
                {
                    info.BaseClass = GetMetadata(type.BaseType, cache);
                    info.BaseClass.DerivedClasses.Add(info);
                }
            }

            return(info);
        }
        public void ConvertAndSave(MetadataCache cache, string filename)
        {
            ArgumentUtility.CheckNotNull("cache", cache);
            ArgumentUtility.CheckNotNullOrEmpty("filename", filename);

            XmlDocument xmlDocument = Convert(cache);

            xmlDocument.Save(filename);
        }
        private LocalizedName[] GetLocalizedNames(MetadataCache cache, CultureInfo culture)
        {
            List <LocalizedName> localizedNames = new List <LocalizedName> ();

            AddNames(localizedNames, cache.GetSecurableClassInfos(), CreateLocalizedNameFromClassInfo);
            AddNames(localizedNames, cache.GetAbstractRoles(), CreateLocalizedNameFromEnumValueInfo);
            AddNames(localizedNames, cache.GetAccessTypes(), CreateLocalizedNameFromEnumValueInfo);
            AddStateNames(localizedNames, cache.GetStatePropertyInfos());

            return(localizedNames.ToArray());
        }
        public void ConvertAndSave(MetadataCache cache, string filename)
        {
            if (_metadataConverter != null)
            {
                _metadataConverter.ConvertAndSave(cache, filename);
            }

            foreach (CultureInfo culture in _cultures)
            {
                _localizationConverter.ConvertAndSave(GetLocalizedNames(cache, culture), culture, filename);
            }
        }
        public void Save(string filename)
        {
            MetadataCache     metadata  = new MetadataCache();
            AssemblyReflector reflector = new AssemblyReflector();

            foreach (Assembly assembly in _assemblies)
            {
                reflector.GetMetadata(assembly, metadata);
            }

            _converter.ConvertAndSave(metadata, filename);
        }
        public XmlDocument Convert(MetadataCache cache)
        {
            ArgumentUtility.CheckNotNull("cache", cache);

            XmlDocument    document    = new XmlDocument();
            XmlDeclaration declaration = document.CreateXmlDeclaration("1.0", string.Empty, string.Empty);

            document.AppendChild(declaration);

            XmlElement rootElement = document.CreateElement("securityMetadata", _metadataSchema.SchemaUri);

            AppendCollection(document, rootElement, "classes", cache.GetSecurableClassInfos(), CreateClassNode);
            AppendCollection(document, rootElement, "stateProperties", cache.GetStatePropertyInfos(), CreateStatePropertyNode);
            AppendCollection(document, rootElement, "accessTypes", cache.GetAccessTypes(), CreateAccessTypeNode);
            AppendCollection(document, rootElement, "abstractRoles", cache.GetAbstractRoles(), CreateAbstractRoleNode);

            document.AppendChild(rootElement);
            return(document);
        }
예제 #8
0
        public List <EnumValueInfo> GetAccessTypesFromType(Type type, MetadataCache cache)
        {
            ArgumentUtility.CheckNotNull("type", type);
            ArgumentUtility.CheckNotNull("cache", cache);

            Dictionary <Enum, EnumValueInfo> accessTypes = _enumerationReflector.GetValues(typeof(GeneralAccessTypes), cache);

            foreach (KeyValuePair <Enum, EnumValueInfo> entry in accessTypes)
            {
                if (!cache.ContainsAccessType(entry.Key))
                {
                    cache.AddAccessType(entry.Key, entry.Value);
                }
            }

            AddAccessTypes(type, accessTypes, cache);

            return(new List <EnumValueInfo> (accessTypes.Values));
        }
예제 #9
0
        protected virtual List <StatePropertyInfo> GetProperties(Type type, MetadataCache cache)
        {
            ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("type", type, typeof(ISecurableObject));
            ArgumentUtility.CheckNotNull("cache", cache);

            MemberInfo[] propertyInfos = type.FindMembers(
                MemberTypes.Property,
                BindingFlags.Instance | BindingFlags.Public,
                FindStatePropertiesFilter,
                null);

            List <StatePropertyInfo> statePropertyInfos = new List <StatePropertyInfo> ();

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                statePropertyInfos.Add(_statePropertyReflector.GetMetadata(propertyInfo, cache));
            }

            return(statePropertyInfos);
        }
예제 #10
0
        // methods and properties

        public Dictionary <Enum, EnumValueInfo> GetValues(Type type, MetadataCache cache)
        {
            ArgumentUtility.CheckNotNull("type", type);
            if (!type.IsEnum)
            {
                throw new ArgumentException(string.Format("The type '{0}' is not an enumerated type.", type.FullName), "type");
            }
            ArgumentUtility.CheckNotNull("cache", cache);

            IList values = Enum.GetValues(type);

            Dictionary <Enum, EnumValueInfo> enumValueInfos = new Dictionary <Enum, EnumValueInfo> ();

            for (int i = 0; i < values.Count; i++)
            {
                Enum value = (Enum)values[i];
                enumValueInfos.Add(value, GetValue(value, cache));
            }

            return(enumValueInfos);
        }
        public void GetMetadata(Assembly assembly, MetadataCache cache)
        {
            ArgumentUtility.CheckNotNull("assembly", assembly);
            ArgumentUtility.CheckNotNull("cache", cache);

            Assembly securityAssembly = GetType().Assembly;

            _accessTypeReflector.GetAccessTypesFromAssembly(securityAssembly, cache);
            _accessTypeReflector.GetAccessTypesFromAssembly(assembly, cache);

            _abstractRoleReflector.GetAbstractRoles(securityAssembly, cache);
            _abstractRoleReflector.GetAbstractRoles(assembly, cache);

            foreach (Type type in AssemblyTypeCache.GetTypes(assembly))
            {
                if (typeof(ISecurableObject).IsAssignableFrom(type))
                {
                    _classReflector.GetMetadata(type, cache);
                }
            }
        }
예제 #12
0
        public EnumValueInfo GetValue(Enum value, MetadataCache cache)
        {
            ArgumentUtility.CheckNotNull("value", value);
            ArgumentUtility.CheckNotNull("cache", cache);

            EnumValueInfo info = cache.GetEnumValueInfo(value);

            if (info == null)
            {
                string name = value.ToString();
                info = new EnumValueInfo(TypeUtility.GetPartialAssemblyQualifiedName(value.GetType()), name, Convert.ToInt32(value));
                FieldInfo fieldInfo = value.GetType().GetField(name, BindingFlags.Static | BindingFlags.Public);
                PermanentGuidAttribute attribute = (PermanentGuidAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(PermanentGuidAttribute), false);
                if (attribute != null)
                {
                    info.ID = attribute.Value.ToString();
                }

                cache.AddEnumValueInfo(value, info);
            }

            return(info);
        }
        public StatePropertyInfo GetMetadata(PropertyInfo property, MetadataCache cache)
        {
            ArgumentUtility.CheckNotNull("property", property);
            if (!property.PropertyType.IsEnum)
            {
                throw new ArgumentException(
                          string.Format("The type of the property '{0}' in type '{1}' is not an enumerated type.", property.Name, property.DeclaringType.FullName),
                          "property");
            }

            if (!Attribute.IsDefined(property.PropertyType, typeof(SecurityStateAttribute), false))
            {
                throw new ArgumentException(string.Format("The type of the property '{0}' in type '{1}' does not have the {2} applied.",
                                                          property.Name, property.DeclaringType.FullName, typeof(SecurityStateAttribute).FullName),
                                            "property");
            }

            ArgumentUtility.CheckNotNull("cache", cache);

            StatePropertyInfo info = cache.GetStatePropertyInfo(property);

            if (info == null)
            {
                info      = new StatePropertyInfo();
                info.Name = property.Name;
                PermanentGuidAttribute attribute = (PermanentGuidAttribute)Attribute.GetCustomAttribute(property, typeof(PermanentGuidAttribute), true);
                if (attribute != null)
                {
                    info.ID = attribute.Value.ToString();
                }
                info.Values = new List <EnumValueInfo> (_enumerationReflector.GetValues(property.PropertyType, cache).Values);

                cache.AddStatePropertyInfo(property, info);
            }
            return(info);
        }
예제 #14
0
        private void AddAccessTypesFromAttribute(IEnumerable <MethodInfo> methodInfos, Dictionary <Enum, EnumValueInfo> accessTypes, MetadataCache cache)
        {
            foreach (var methodInfo in methodInfos)
            {
                var values = _permissionReflector.GetRequiredMethodPermissions(methodInfo.DeclaringType, MethodInfoAdapter.Create(methodInfo));
                foreach (Enum value in values)
                {
                    EnumValueInfo accessType = _enumerationReflector.GetValue(value, cache);

                    if (!cache.ContainsAccessType(value))
                    {
                        cache.AddAccessType(value, accessType);
                    }

                    if (!accessTypes.ContainsKey(value))
                    {
                        accessTypes.Add(value, accessType);
                    }
                }
            }
        }
예제 #15
0
        private void AddAccessTypes(Type type, Dictionary <Enum, EnumValueInfo> accessTypes, MetadataCache cache)
        {
            var instanceMethods = GetInstanceMethods(type);
            var staticMethods   = GetStaticMethods(type);

            var methodInformations = instanceMethods.Concat(staticMethods);

            AddAccessTypesFromAttribute(methodInformations, accessTypes, cache);
        }