public Schema ToSchema(FieldRegistry registry) { var fields = Empty; if (Fields != null) { fields = Fields.ToArray(fieldModel => { var parititonKey = new Partitioning(fieldModel.Partitioning); RootField field; if (fieldModel.Properties is ArrayFieldProperties arrayProperties && fieldModel.Children?.Length > 0) { var nestedFields = fieldModel.Children.ToArray(nestedFieldModel => { return(registry.CreateNestedField(nestedFieldModel.Id, nestedFieldModel.Name, nestedFieldModel.Properties, nestedFieldModel)); }); field = new ArrayField(fieldModel.Id, fieldModel.Name, parititonKey, nestedFields, arrayProperties, fieldModel); } else { field = registry.CreateRootField(fieldModel.Id, fieldModel.Name, parititonKey, fieldModel.Properties, fieldModel); } return(field); });
public Schema ToSchema(FieldRegistry registry) { var fields = Empty; if (Fields != null) { fields = new RootField[Fields.Count]; for (var i = 0; i < fields.Length; i++) { var fieldModel = Fields[i]; var parititonKey = new Partitioning(fieldModel.Partitioning); var field = registry.CreateRootField(fieldModel.Id, fieldModel.Name, parititonKey, fieldModel.Properties); if (field is ArrayField arrayField && fieldModel.Children?.Count > 0) { foreach (var nestedFieldModel in fieldModel.Children) { var nestedField = registry.CreateNestedField(nestedFieldModel.Id, nestedFieldModel.Name, nestedFieldModel.Properties); if (nestedFieldModel.IsHidden) { nestedField = nestedField.Hide(); } if (nestedFieldModel.IsDisabled) { nestedField = nestedField.Disable(); } arrayField = arrayField.AddField(nestedField); } field = arrayField; } if (fieldModel.IsDisabled) { field = field.Disable(); } if (fieldModel.IsLocked) { field = field.Lock(); } if (fieldModel.IsHidden) { field = field.Hide(); } fields[i] = field; } } return(new Schema(Name, fields, Properties, IsPublished)); }
protected void On(FieldAdded @event, FieldRegistry registry) { if (@event.ParentFieldId != null) { var field = registry.CreateNestedField(@event.FieldId.Id, @event.Name, @event.Properties); SchemaDef = SchemaDef.UpdateField(@event.ParentFieldId.Id, x => ((ArrayField)x).AddField(field)); } else { var partitioning = Partitioning.FromString(@event.Partitioning); var field = registry.CreateRootField(@event.FieldId.Id, @event.Name, partitioning, @event.Properties); SchemaDef = SchemaDef.DeleteField(@event.FieldId.Id); SchemaDef = SchemaDef.AddField(field); } TotalFields++; }
protected void On(SchemaCreated @event, FieldRegistry registry) { Name = @event.Name; var schema = new Schema(@event.Name); if (@event.Properties != null) { schema = schema.Update(@event.Properties); } if (@event.Publish) { schema = schema.Publish(); } if (@event.Fields != null) { foreach (var eventField in @event.Fields) { TotalFields++; var partitioning = Partitioning.FromString(eventField.Partitioning); var field = registry.CreateRootField(TotalFields, eventField.Name, partitioning, eventField.Properties); if (field is ArrayField arrayField && eventField.Nested?.Count > 0) { foreach (var nestedEventField in eventField.Nested) { TotalFields++; var nestedField = registry.CreateNestedField(TotalFields, nestedEventField.Name, nestedEventField.Properties); if (nestedEventField.IsHidden) { nestedField = nestedField.Hide(); } if (nestedEventField.IsDisabled) { nestedField = nestedField.Disable(); } arrayField = arrayField.AddField(nestedField); } field = arrayField; } if (eventField.IsHidden) { field = field.Hide(); } if (eventField.IsDisabled) { field = field.Disable(); } if (eventField.IsLocked) { field = field.Lock(); } schema = schema.AddField(field); } } SchemaDef = schema; AppId = @event.AppId; }