Beispiel #1
0
        private List <DarwinValidation.ValidationError> DoImport(DatabaseDTO database)
        {
            var entityIds    = new Dictionary <string, Guid>();
            var attributeIds = new Dictionary <string, Guid>();

            var services   = new SqlServerServices();
            var dataSource = new ObjectDataSource();
            var entities   = new List <EntityDTO>();
            int lastTable  = 0;

            var errors    = new List <DarwinValidation.ValidationError>();
            var validator = new Validator();

            do
            {
                entities = services.ImportObjects(database, ref lastTable);
                dataSource.SaveObject(database);
                foreach (var entity in entities)
                {
                    var validationError = validator.Validate(entity);
                    if (validationError != null)
                    {
                        errors.Add(validationError);
                    }

                    dataSource.SaveObject(entity, bypassValidation: true);
                    entityIds.Add(entity.EntitySchemaPrefixedName, entity.ID);
                    foreach (var attribute in entity.Attributes)
                    {
                        attributeIds.Add(entity.EntitySchemaPrefixedName + "." + attribute.AttributeName, attribute.ID);
                    }
                }
            } while (entities.Count > 0);

            List <RelationDTO> relations = new List <RelationDTO>();

            lastTable = 0;
            do
            {
                relations = services.ImportRelations(database, entityIds, attributeIds, ref lastTable);
                foreach (var relation in relations)
                {
                    dataSource.SaveObject(relation);
                }
            } while (relations.Count > 0);

            return(errors);
        }