public static List <ObjectExtensionInfoEfCoreMappingOptions> GetEfCoreDbContextMappings(
            [NotNull] this ObjectExtensionInfo objectExtensionInfo)
        {
            Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));

            return(!objectExtensionInfo.Configuration.TryGetValue(EfCoreDbContextConfigurationName, out var options) ?
                   new List <ObjectExtensionInfoEfCoreMappingOptions>() : options.As <List <ObjectExtensionInfoEfCoreMappingOptions> >());
        }
Exemple #2
0
        public ObjectExtensionInfoEfCoreMappingOptions(
            [NotNull] ObjectExtensionInfo objectExtension,
            [NotNull] Action <ModelBuilder> modelBuildAction)
        {
            ObjectExtension  = Check.NotNull(objectExtension, nameof(objectExtension));
            ModelBuildAction = Check.NotNull(modelBuildAction, nameof(modelBuildAction));

            ModelBuildAction = modelBuildAction;
        }
Exemple #3
0
        public ObjectExtensionInfoEfCoreMappingOptions(
            [NotNull] ObjectExtensionInfo objectExtension,
            [NotNull] Action <EntityTypeBuilder> entityTypeBuildAction)
        {
            ObjectExtension       = Check.NotNull(objectExtension, nameof(objectExtension));
            EntityTypeBuildAction = Check.NotNull(entityTypeBuildAction, nameof(entityTypeBuildAction));

            EntityTypeBuildAction = entityTypeBuildAction;
        }
Exemple #4
0
 public static ObjectExtensionInfo MapEfCoreProperty <TProperty>(
     [NotNull] this ObjectExtensionInfo objectExtensionInfo,
     [NotNull] string propertyName,
     [CanBeNull] Action <PropertyBuilder> propertyBuildAction)
 {
     return(objectExtensionInfo.MapEfCoreProperty(
                typeof(TProperty),
                propertyName,
                propertyBuildAction
                ));
 }
        public ObjectExtensionPropertyInfo(
            [NotNull] ObjectExtensionInfo objectExtension,
            [NotNull] Type type,
            [NotNull] string name)
        {
            ObjectExtension = Check.NotNull(objectExtension, nameof(objectExtension));
            Type            = Check.NotNull(type, nameof(type));
            Name            = Check.NotNull(name, nameof(name));

            Configuration = new Dictionary <object, object>();
        }
 public ObjectExtensionValidationContext(
     [NotNull] ObjectExtensionInfo objectExtensionInfo,
     [NotNull] IHasExtraProperties validatingObject,
     [NotNull] List <ValidationResult> validationErrors,
     [NotNull] ValidationContext validationContext)
 {
     ObjectExtensionInfo = Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));
     ValidatingObject    = Check.NotNull(validatingObject, nameof(validatingObject));
     ValidationErrors    = Check.NotNull(validationErrors, nameof(validationErrors));
     ValidationContext   = Check.NotNull(validationContext, nameof(validationContext));
 }
Exemple #7
0
        public ObjectExtensionPropertyInfo(
            [NotNull] ObjectExtensionInfo objectExtension,
            [NotNull] Type type,
            [NotNull] string name)
        {
            ObjectExtension = Check.NotNull(objectExtension, nameof(objectExtension));
            Type            = Check.NotNull(type, nameof(type));
            Name            = Check.NotNull(name, nameof(name));

            Configuration        = new Dictionary <object, object>();
            ValidationAttributes = new List <ValidationAttribute>();
            Validators           = new List <Action <ObjectExtensionPropertyValidationContext> >();
        }
Exemple #8
0
        public ObjectExtensionPropertyInfo(
            [NotNull] ObjectExtensionInfo objectExtension,
            [NotNull] Type type,
            [NotNull] string name)
        {
            ObjectExtension = Check.NotNull(objectExtension, nameof(objectExtension));
            Type            = Check.NotNull(type, nameof(type));
            Name            = Check.NotNull(name, nameof(name));

            Configuration = new Dictionary <object, object>();
            Attributes    = new List <Attribute>();
            Validators    = new List <Action <ObjectExtensionPropertyValidationContext> >();

            Attributes.AddRange(ExtensionPropertyHelper.GetDefaultAttributes(Type));
            DefaultValue = TypeHelper.GetDefaultValue(Type);
        }
Exemple #9
0
        private static void AddPropertyValidationErrors(
            IHasExtraProperties extensibleObject,
            List <ValidationResult> validationErrors,
            ValidationContext objectValidationContext,
            ObjectExtensionInfo objectExtensionInfo)
        {
            var properties = objectExtensionInfo.GetProperties();

            if (!properties.Any())
            {
                return;
            }

            foreach (var property in properties)
            {
                AddPropertyValidationErrors(extensibleObject, validationErrors, objectValidationContext, property);
            }
        }
Exemple #10
0
        public static ObjectExtensionInfo MapEfCoreProperty(
            [NotNull] this ObjectExtensionInfo objectExtensionInfo,
            [NotNull] Type propertyType,
            [NotNull] string propertyName,
            [CanBeNull] Action <EntityTypeBuilder, PropertyBuilder> entityTypeAndPropertyBuildAction)
        {
            Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));

            return(objectExtensionInfo.AddOrUpdateProperty(
                       propertyType,
                       propertyName,
                       options =>
            {
                options.MapEfCore(
                    entityTypeAndPropertyBuildAction
                    );
            }
                       ));
        }
        public static ObjectExtensionInfo MapEfCoreEntity(
            [NotNull] this ObjectExtensionInfo objectExtensionInfo,
            [NotNull] Action <EntityTypeBuilder> entityTypeBuildAction)
        {
            Check.NotNull(objectExtensionInfo, nameof(objectExtensionInfo));

            var mappingOptionList = new List <ObjectExtensionInfoEfCoreMappingOptions>
            {
                new ObjectExtensionInfoEfCoreMappingOptions(
                    objectExtensionInfo,
                    entityTypeBuildAction)
            };

            objectExtensionInfo.Configuration.AddOrUpdate(EfCoreEntityConfigurationName, mappingOptionList,
                                                          (k, v) =>
            {
                v.As <List <ObjectExtensionInfoEfCoreMappingOptions> >().Add(mappingOptionList.First());
                return(v);
            });

            return(objectExtensionInfo);
        }
Exemple #12
0
        private static void ExecuteCustomObjectValidationActions(
            IHasExtraProperties extensibleObject,
            List <ValidationResult> validationErrors,
            ValidationContext objectValidationContext,
            ObjectExtensionInfo objectExtensionInfo)
        {
            if (!objectExtensionInfo.Validators.Any())
            {
                return;
            }

            var context = new ObjectExtensionValidationContext(
                objectExtensionInfo,
                extensibleObject,
                validationErrors,
                objectValidationContext
                );

            foreach (var validator in objectExtensionInfo.Validators)
            {
                validator(context);
            }
        }
Exemple #13
0
        private static bool CanMapProperty(
            [NotNull] string propertyName,
            [CanBeNull] ObjectExtensionInfo sourceObjectExtension,
            [CanBeNull] ObjectExtensionInfo destinationObjectExtension,
            MappingPropertyDefinitionChecks?definitionChecks = null,
            string[] ignoredProperties = null)
        {
            Check.NotNull(propertyName, nameof(propertyName));

            if (ignoredProperties != null &&
                ignoredProperties.Contains(propertyName))
            {
                return(false);
            }

            if (definitionChecks != null)
            {
                if (definitionChecks.Value.HasFlag(MappingPropertyDefinitionChecks.Source))
                {
                    if (sourceObjectExtension == null)
                    {
                        return(false);
                    }

                    if (!sourceObjectExtension.HasProperty(propertyName))
                    {
                        return(false);
                    }
                }

                if (definitionChecks.Value.HasFlag(MappingPropertyDefinitionChecks.Destination))
                {
                    if (destinationObjectExtension == null)
                    {
                        return(false);
                    }

                    if (!destinationObjectExtension.HasProperty(propertyName))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else
            {
                var sourcePropertyDefinition      = sourceObjectExtension?.GetPropertyOrNull(propertyName);
                var destinationPropertyDefinition = destinationObjectExtension?.GetPropertyOrNull(propertyName);

                if (sourcePropertyDefinition != null)
                {
                    if (destinationPropertyDefinition != null)
                    {
                        return(true);
                    }

                    if (sourcePropertyDefinition.CheckPairDefinitionOnMapping == false)
                    {
                        return(true);
                    }
                }
                else if (destinationPropertyDefinition != null)
                {
                    if (destinationPropertyDefinition.CheckPairDefinitionOnMapping == false)
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }