Пример #1
0
        protected ScimTypeAttributeDefinitionBuilder(
            IScimTypeDefinition typeDefinition,
            PropertyDescriptor propertyDescriptor,
            bool multiValued)
        {
            _DeclaringTypeDefinition = typeDefinition;
            _PropertyDescriptor      = propertyDescriptor;
            _CanonicalizationRules   = new List <ICanonicalizationRule>();

            // Initialize defaults
            CaseExact   = false;
            MultiValued = multiValued;
            Mutability  = Mutability.ReadWrite;
            Required    = false;
            Returned    = Returned.Default;
            Uniqueness  = Uniqueness.None;

            var descriptionAttr = propertyDescriptor
                                  .Attributes
                                  .Cast <Attribute>()
                                  .SingleOrDefault(attr => attr is DescriptionAttribute) as DescriptionAttribute;

            if (descriptionAttr != null)
            {
                Description = descriptionAttr.Description.RemoveMultipleSpaces();
            }
        }
Пример #2
0
 public ScimTypeComplexAttributeDefinitionBuilder(
     IScimTypeDefinition typeDefinition,
     PropertyDescriptor propertyDescriptor,
     bool multiValued = false)
     : base(typeDefinition, propertyDescriptor, multiValued)
 {
 }
 public ScimResourceTypeExtension(
     string schema,
     bool required,
     IScimTypeDefinition extensionDefinition, 
     Type extensionType, 
     Type extensionValidatorType)
 {
     Schema = schema;
     Required = required;
     ExtensionType = extensionType;
     ExtensionValidatorType = extensionValidatorType;
     ExtensionDefinition = extensionDefinition;
 }
Пример #4
0
 public ScimResourceTypeExtension(
     string schema,
     bool required,
     IScimTypeDefinition extensionDefinition,
     Type extensionType,
     Type extensionValidatorType)
 {
     Schema                 = schema;
     Required               = required;
     ExtensionType          = extensionType;
     ExtensionValidatorType = extensionValidatorType;
     ExtensionDefinition    = extensionDefinition;
 }
Пример #5
0
        internal void AddTypeDefiniton(IScimTypeDefinition scimTypeDefinition)
        {
            if (_TypeDefinitionCache.ContainsKey(scimTypeDefinition.DefinitionType))
            {
                return;
            }

            if (!_TypeDefinitionCache.TryAdd(scimTypeDefinition.DefinitionType, scimTypeDefinition))
            {
                throw new Exception(
                          string.Format(
                              "ScimServerConfiguration was unable to add a type definition for type '{0}'.",
                              scimTypeDefinition.DefinitionType.Name));
            }
        }
        public void Canonicalize(object instance, IScimTypeDefinition typeDefinition)
        {
            foreach (var attribute in typeDefinition.AttributeDefinitions)
            {
                var attributeMemberInfo = attribute.Key;
                var attributeDefinition = attribute.Value;

                var canonicalizationRules = attributeDefinition.GetCanonicalizationRules();
                if (canonicalizationRules == null || !canonicalizationRules.Any()) continue;

                var attributeValue = attributeMemberInfo.GetValue(instance);
                if (attributeValue == null || attributeValue == attributeMemberInfo.PropertyType.GetDefaultValue()) continue;

                object state = null;
                if (attributeMemberInfo.PropertyType.IsTerminalObject())
                {
                    foreach (var canonicalizationRule in canonicalizationRules)
                    {
                        canonicalizationRule.Execute(instance, ref state);
                    }

                    continue;
                }

                if (!attributeDefinition.MultiValued)
                {
                    // attribute is complex
                    foreach (var canonicalizationRule in canonicalizationRules)
                    {
                        canonicalizationRule.Execute(instance, ref state);
                    }

                    // canonicalize the complex object instance as it may have sub-attributes 
                    // with defined canonicalization rules
                    Canonicalize(attributeMemberInfo.GetValue(instance), attributeDefinition.DeclaringTypeDefinition);

                    continue;
                }
                
                // attribute is multi-valued (enumerable)
                var stateCache = new Dictionary<ICanonicalizationRule, object>();
                var enumerable = (IEnumerable)attributeValue;
                var enumerator = enumerable.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current == null) continue;

                    foreach (var canonicalizationRule in canonicalizationRules)
                    {
                        if (!stateCache.ContainsKey(canonicalizationRule))
                            stateCache[canonicalizationRule] = null;

                        var rState = stateCache[canonicalizationRule];
                        var currentElement = enumerator.Current;
                        canonicalizationRule.Execute(currentElement, ref rState);
                        stateCache[canonicalizationRule] = rState;
                    }

                    // recursively canonicalize each enumeration value as they may have sub-attributes with canonicalization rules
                    Canonicalize(enumerator.Current, attributeDefinition.DeclaringTypeDefinition);
                }
            }
        }
Пример #7
0
        public void Canonicalize(object instance, IScimTypeDefinition typeDefinition)
        {
            foreach (var attribute in typeDefinition.AttributeDefinitions)
            {
                var attributeMemberInfo = attribute.Key;
                var attributeDefinition = attribute.Value;

                var canonicalizationRules = attributeDefinition.GetCanonicalizationRules();
                if (canonicalizationRules == null || !canonicalizationRules.Any())
                {
                    continue;
                }

                var attributeValue = attributeMemberInfo.GetValue(instance);
                if (attributeValue == null || attributeValue == attributeMemberInfo.PropertyType.GetDefaultValue())
                {
                    continue;
                }

                object state = null;
                if (attributeMemberInfo.PropertyType.IsTerminalObject())
                {
                    foreach (var canonicalizationRule in canonicalizationRules)
                    {
                        canonicalizationRule.Execute(instance, ref state);
                    }

                    continue;
                }

                if (!attributeDefinition.MultiValued)
                {
                    // attribute is complex
                    foreach (var canonicalizationRule in canonicalizationRules)
                    {
                        canonicalizationRule.Execute(instance, ref state);
                    }

                    // canonicalize the complex object instance as it may have sub-attributes
                    // with defined canonicalization rules
                    Canonicalize(attributeMemberInfo.GetValue(instance), attributeDefinition.DeclaringTypeDefinition);

                    continue;
                }

                // attribute is multi-valued (enumerable)
                var stateCache = new Dictionary <ICanonicalizationRule, object>();
                var enumerable = (IEnumerable)attributeValue;
                var enumerator = enumerable.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current == null)
                    {
                        continue;
                    }

                    foreach (var canonicalizationRule in canonicalizationRules)
                    {
                        if (!stateCache.ContainsKey(canonicalizationRule))
                        {
                            stateCache[canonicalizationRule] = null;
                        }

                        var rState         = stateCache[canonicalizationRule];
                        var currentElement = enumerator.Current;
                        canonicalizationRule.Execute(currentElement, ref rState);
                        stateCache[canonicalizationRule] = rState;
                    }

                    // recursively canonicalize each enumeration value as they may have sub-attributes with canonicalization rules
                    Canonicalize(enumerator.Current, attributeDefinition.DeclaringTypeDefinition);
                }
            }
        }