Exemplo n.º 1
0
        public Schema Deserialize(JToken token)
        {
            var model = token.ToObject <JsonSchemaModel>(serializer);

            var fields =
                model.Fields.Select(kvp =>
            {
                var fieldModel = kvp.Value;

                var field = fieldRegistry.CreateField(kvp.Key, fieldModel.Name, fieldModel.Properties);

                if (fieldModel.IsDisabled)
                {
                    field = field.Disable();
                }

                if (fieldModel.IsHidden)
                {
                    field = field.Hide();
                }

                return(field);
            }).ToImmutableDictionary(x => x.Id, x => x);

            var schema =
                new Schema(
                    model.Name,
                    model.IsPublished, model.Properties, fields);

            return(schema);
        }
Exemplo n.º 2
0
        public Schema ToSchema(FieldRegistry fieldRegistry)
        {
            var fields = Fields?.Select(fieldModel =>
            {
                var parititonKey = new Partitioning(fieldModel.Partitioning);

                var field = fieldRegistry.CreateField(fieldModel.Id, fieldModel.Name, parititonKey, fieldModel.Properties);

                if (fieldModel.IsDisabled)
                {
                    field = field.Disable();
                }

                if (fieldModel.IsLocked)
                {
                    field = field.Lock();
                }

                if (fieldModel.IsHidden)
                {
                    field = field.Hide();
                }

                return(field);
            }).ToImmutableList() ?? ImmutableList <Field> .Empty;

            var schema = new Schema(Name, IsPublished, Properties, fields);

            return(schema);
        }
        public Schema Deserialize(JToken token)
        {
            var model = token.ToObject <JsonSchemaModel>(serializer);

            var fields =
                model.Fields.Select(fieldModel =>
            {
                var parititonKey = new Partitioning(fieldModel.Partitioning);

                var field = fieldRegistry.CreateField(fieldModel.Id, fieldModel.Name, parititonKey, fieldModel.Properties);

                if (fieldModel.IsDisabled)
                {
                    field = field.Disable();
                }

                if (fieldModel.IsHidden)
                {
                    field = field.Hide();
                }

                return(field);
            }).ToImmutableList();

            var schema =
                new Schema(
                    model.Name,
                    model.IsPublished, model.Properties, fields);

            return(schema);
        }
Exemplo n.º 4
0
        public static Schema Dispatch(SchemaCreated @event, FieldRegistry registry)
        {
            var schema = Schema.Create(@event.Name, @event.Properties);

            if (@event.Fields != null)
            {
                var fieldId = 1;

                foreach (var eventField in @event.Fields)
                {
                    var partitioning =
                        string.Equals(eventField.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                        Partitioning.Language :
                        Partitioning.Invariant;

                    var field = registry.CreateField(fieldId, eventField.Name, partitioning, eventField.Properties);

                    if (eventField.IsHidden)
                    {
                        field = field.Hide();
                    }

                    if (eventField.IsDisabled)
                    {
                        field = field.Disable();
                    }

                    schema = schema.AddOrUpdateField(field);

                    fieldId++;
                }
            }

            return(schema);
        }
Exemplo n.º 5
0
        public static Schema Dispatch(FieldAdded @event, Schema schema, FieldRegistry registry)
        {
            var partitioning =
                string.Equals(@event.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                Partitioning.Language :
                Partitioning.Invariant;

            return(schema.AddField(registry.CreateField(@event.FieldId.Id, @event.Name, partitioning, @event.Properties)));
        }
Exemplo n.º 6
0
        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 =
                        string.Equals(eventField.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                        Partitioning.Language :
                        Partitioning.Invariant;

                    var field = registry.CreateField(TotalFields, eventField.Name, partitioning, eventField.Properties);

                    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;
        }
Exemplo n.º 7
0
        public static void Apply(this Schema schema, FieldAdded @event, FieldRegistry registry)
        {
            var partitioning =
                string.Equals(@event.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                Partitioning.Language :
                Partitioning.Invariant;

            var fieldId = @event.FieldId.Id;
            var field   = registry.CreateField(fieldId, @event.Name, partitioning, @event.Properties);

            schema.DeleteField(fieldId);
            schema.AddField(field);
        }
Exemplo n.º 8
0
        protected void On(FieldAdded @event, FieldRegistry registry)
        {
            var partitioning =
                string.Equals(@event.Partitioning, Partitioning.Language.Key, StringComparison.OrdinalIgnoreCase) ?
                Partitioning.Language :
                Partitioning.Invariant;

            var field = registry.CreateField(@event.FieldId.Id, @event.Name, partitioning, @event.Properties);

            SchemaDef = SchemaDef.DeleteField(@event.FieldId.Id);
            SchemaDef = SchemaDef.AddField(field);

            TotalFields++;
        }
Exemplo n.º 9
0
        public Schema ToSchema(FieldRegistry fieldRegistry)
        {
            var schema = new Schema(Name);

            if (Fields != null)
            {
                foreach (var fieldModel in Fields)
                {
                    var parititonKey = new Partitioning(fieldModel.Partitioning);

                    var field = fieldRegistry.CreateField(fieldModel.Id, fieldModel.Name, parititonKey, fieldModel.Properties);

                    if (fieldModel.IsDisabled)
                    {
                        field.Disable();
                    }

                    if (fieldModel.IsLocked)
                    {
                        field.Lock();
                    }

                    if (fieldModel.IsHidden)
                    {
                        field.Hide();
                    }

                    schema.AddField(field);
                }
            }

            if (IsPublished)
            {
                schema.Publish();
            }

            if (Properties != null)
            {
                schema.Update(Properties);
            }

            return(schema);
        }
Exemplo n.º 10
0
        public Schema ToSchema(FieldRegistry fieldRegistry)
        {
            Field[] fields = Empty;

            if (Fields != null)
            {
                fields = new Field[Fields.Count];

                for (var i = 0; i < fields.Length; i++)
                {
                    var fieldModel = Fields[i];

                    var parititonKey = new Partitioning(fieldModel.Partitioning);

                    var field = fieldRegistry.CreateField(fieldModel.Id, fieldModel.Name, parititonKey, fieldModel.Properties);

                    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));
        }
Exemplo n.º 11
0
 public void Should_throw_exception_if_creating_field_and_field_is_not_registered()
 {
     Assert.Throws <InvalidOperationException>(() => sut.CreateField(1, "name", Partitioning.Invariant, new InvalidProperties()));
 }
Exemplo n.º 12
0
 public static Schema Dispatch(FieldAdded @event, Schema schema, FieldRegistry registry)
 {
     return(schema.AddOrUpdateField(registry.CreateField(@event.FieldId.Id, @event.Name, @event.Properties)));
 }