Esempio n. 1
0
 protected void ResolveNameTargetHelper <T>(T owner, Func <T, TMappingKey, List <TMappingValue> > findByKey, ModelErrors errors)
     where T : class
 {
     if (owner is null)
     {
         return;
     }
     if (((object)this._Target == null) && ((object)this._TargetName != null))
     {
         var lstFound = findByKey(owner, this._TargetName);
         if (lstFound.Count == 1)
         {
             this._Target     = lstFound[0];
             this._TargetName = null;
         }
         else if (lstFound.Count == 0)
         {
             errors.AddErrorOrThrow($"Target {this._TargetName} not found", this.Name?.ToString(), ResolveNameNotFoundException.Factory);
         }
         else
         {
             errors.AddErrorOrThrow($"Target {this._TargetName} found #{lstFound.Count} times.", this.Name?.ToString(), ResolveNameNotUniqueException.Factory);
         }
     }
 }
Esempio n. 2
0
        public void BuildEntities(
            MappingModelSchema mappingModelSchema,
            ModelErrors errors
            )
        {
            ModelSchema modelSchemaSource = mappingModelSchema.Source;
            ModelSchema modelSchemaTarget = mappingModelSchema.Target;

            var lstEntityMappings = mappingModelSchema.EntityMappings.Where(_ => _.Enabled).ToList();

            foreach (var entityMapping in lstEntityMappings)
            {
                if (entityMapping.Target is null)
                {
                    var    targetName  = entityMapping.TargetName;
                    string extenalName = targetName;
                    string typeName    = null;
#warning SOON thinkof what's in the mapping.
                    if (this.NamingServiceTarget.EntitiesHaveFakeComplexTypes)
                    {
                        typeName = targetName;
                    }
                    modelSchemaTarget.CreateEntity(targetName, extenalName, typeName);
                }
            }

            foreach (var entitySource in modelSchemaSource.Entities)
            {
                if (this._KnownEntityMappingSourceName.Contains(entitySource.Name))
                {
                    continue;
                }

                (string targetName, string extenalName, string typeName, string typeExternalName) = this.NamingServiceTarget.SuggestEntityName(entitySource.Name);

                if (typeName is null && this.NamingServiceTarget.EntitiesHaveFakeComplexTypes)
                {
                    typeName = targetName;
                }

                var entityMapping = mappingModelSchema.CreateEntityMapping(
                    null,
                    entitySource.Name,
                    targetName,
                    this.EnabledForCreatedMappings || this.EnabledForCreatedMappingModelEntity,
                    true,
                    this.GetComment()
                    );
                if (entityMapping.Enabled)
                {
                    if (entityMapping.Target is null)
                    {
                        modelSchemaTarget.CreateEntity(entityMapping.TargetName, extenalName, typeName);
                    }
                }
                if (this._KnownComplexTypeMappingSourceName.Contains(entitySource.EntityTypeName))
                {
                    // if there is a rule ... ok
                }
                else
                {
                    var complexTypeSource = entitySource.EntityType;
                    if (complexTypeSource is null)
                    {
#warning SOON error??
                        errors.AddErrorOrThrow($"EntityType {entitySource.EntityTypeName} does not exists.", entitySource.Name);
                    }
                    else
                    {
                        var complexTypeMapping = mappingModelSchema.CreateComplexTypeMapping(
                            null,
                            complexTypeSource.Name,
                            typeName,
                            this.EnabledForCreatedMappings || this.EnabledForCreatedMappingModelComplexType,
                            true,
                            this.GetComment()
                            );
                        this._KnownComplexTypeMappingSourceName.Add(complexTypeSource.Name);
                        if (complexTypeMapping.Enabled && !string.IsNullOrEmpty(complexTypeMapping.TargetName))
                        {
                            if (complexTypeMapping.Target is null)
                            {
                                modelSchemaTarget.CreateComplexType(complexTypeMapping.TargetName ?? typeName, typeExternalName);
                            }
                            if ((!(complexTypeMapping.Source is null)) &&
                                (!(complexTypeMapping.Target is null))
                                )
                            {
                                this.BuildComplexTypeProperties(complexTypeMapping, errors);
                                this.BuildComplexTypeIndexes(complexTypeMapping, errors);
                            }
                            else
                            {
                                if (complexTypeMapping.Source is null)
                                {
                                    errors.AddErrorOrThrow($"complexTypeMapping.Source {complexTypeMapping.SourceName} is null", $"complexTypeMapping.Name: {complexTypeMapping.Name}");
                                }
                                if (complexTypeMapping.Target is null)
                                {
                                    errors.AddErrorOrThrow($"complexTypeMapping.Target {complexTypeMapping.TargetName} is null", $"complexTypeMapping.Name: {complexTypeMapping.Name}");
                                }
                            }
                        }
                    }
                }
            }