Example #1
0
        public static SchemaWithRefs <SchemaDto> EnrichSchemaNames(this SchemaWithRefs <SchemaDto> target, ICollection <SchemaDto> allSchemas)
        {
            void Handle(ReferencesFieldPropertiesDto properties)
            {
                var referenced = allSchemas.FirstOrDefault(x => properties.SchemaIds?.Contains(x.Id) == true);

                if (referenced != null)
                {
                    target.ReferencedSchemas[referenced.Id] = referenced.Name;
                }
            }

            foreach (var field in target.Schema.Fields.OrEmpty())
            {
                if (field.Properties is ReferencesFieldPropertiesDto reference)
                {
                    Handle(reference);
                }

                foreach (var nested in field.Nested.OrEmpty())
                {
                    if (nested.Properties is ReferencesFieldPropertiesDto nestedReference)
                    {
                        Handle(nestedReference);
                    }
                }
            }

            return(target);
        }
        public static SchemaWithRefs <T> AdjustReferences <T>(this SchemaWithRefs <T> target, ICollection <SchemaDto> allSchemas) where T : UpsertSchemaDto
        {
            void Handle(ReferencesFieldPropertiesDto properties)
            {
                if (properties.SchemaIds?.Count > 0)
                {
                    var newSchemaIds = properties.SchemaIds.ToList();

                    var i = 0;

                    foreach (var schemaId in properties.SchemaIds)
                    {
                        if (target.ReferencedSchemas.TryGetValue(schemaId, out var name))
                        {
                            var referenced = allSchemas.FirstOrDefault(x => x.Name == name);

                            if (referenced != null)
                            {
                                newSchemaIds[i] = referenced.Id;
                            }
                        }

                        i++;
                    }

                    properties.SchemaIds = newSchemaIds;
                }
            }

            if (target.Schema.Fields != null)
            {
                foreach (var field in target.Schema.Fields)
                {
                    if (field.Properties is ReferencesFieldPropertiesDto reference)
                    {
                        Handle(reference);
                    }

                    if (field.Nested != null)
                    {
                        foreach (var nested in field.Nested)
                        {
                            if (nested.Properties is ReferencesFieldPropertiesDto nestedReference)
                            {
                                Handle(nestedReference);
                            }
                        }
                    }
                }
            }

            return(target);
        }
Example #3
0
        public static SchemaWithRefs <T> AdjustReferences <T>(this SchemaWithRefs <T> target, ICollection <SchemaDto> allSchemas) where T : UpsertDto
        {
            if (target.Schema.Fields != null)
            {
                foreach (var field in target.Schema.Fields)
                {
                    if (field.Properties is ReferencesFieldPropertiesDto reference)
                    {
                        if (target.ReferencedSchemas.TryGetValue(reference.SchemaId, out var name))
                        {
                            var referenced = allSchemas.FirstOrDefault(x => x.Name == name);

                            if (referenced != null)
                            {
                                reference.SchemaId = referenced.Id;
                            }
                        }
                    }

                    if (field.Nested != null)
                    {
                        foreach (var nested in field.Nested)
                        {
                            if (nested.Properties is ReferencesFieldPropertiesDto nestedReference)
                            {
                                if (target.ReferencedSchemas.TryGetValue(nestedReference.SchemaId, out var name))
                                {
                                    var referenced = allSchemas.FirstOrDefault(x => x.Name == name);

                                    if (referenced != null)
                                    {
                                        nestedReference.SchemaId = referenced.Id;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(target);
        }
Example #4
0
        public static SchemaWithRefs <SchemaDetailsDto> EnrichSchemaNames(this SchemaWithRefs <SchemaDetailsDto> target, ICollection <SchemaDto> allSchemas)
        {
            if (target.Schema.Fields != null)
            {
                foreach (var field in target.Schema.Fields)
                {
                    if (field.Properties is ReferencesFieldPropertiesDto reference)
                    {
                        var referenced = allSchemas.FirstOrDefault(x => x.Id == reference.SchemaId);

                        if (referenced != null)
                        {
                            target.ReferencedSchemas[referenced.Id] = referenced.Name;
                        }
                    }

                    if (field.Nested != null)
                    {
                        foreach (var nested in field.Nested)
                        {
                            if (nested.Properties is ReferencesFieldPropertiesDto nestedReference)
                            {
                                var referenced = allSchemas.FirstOrDefault(x => x.Id == nestedReference.SchemaId);

                                if (referenced != null)
                                {
                                    target.ReferencedSchemas[referenced.Id] = referenced.Name;
                                }
                            }
                        }
                    }
                }
            }

            return(target);
        }