Exemplo n.º 1
0
        public IEvent Migrate()
        {
            var schema = new Schema(Name, Properties, Singleton ? SchemaType.Singleton : SchemaType.Default);

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

            var totalFields = 0;

            if (Fields != null)
            {
                foreach (var eventField in Fields)
                {
                    totalFields++;

                    var partitioning = Partitioning.FromString(eventField.Partitioning);

                    var field =
                        eventField.Properties.CreateRootField(
                            totalFields,
                            eventField.Name, partitioning,
                            eventField);

                    if (field is ArrayField arrayField && eventField.Nested?.Length > 0)
                    {
                        foreach (var nestedEventField in eventField.Nested)
                        {
                            totalFields++;

                            var nestedField =
                                nestedEventField.Properties.CreateNestedField(
                                    totalFields,
                                    nestedEventField.Name,
                                    nestedEventField);

                            arrayField = arrayField.AddField(nestedField);
                        }

                        field = arrayField;
                    }

                    schema = schema.AddField(field);
                }
            }

            return(SimpleMapper.Map(this, new SchemaCreatedV2 {
                Schema = schema
            }));
        }
Exemplo n.º 2
0
        protected void On(FieldAdded @event)
        {
            if (@event.ParentFieldId != null)
            {
                var field = @event.Properties.CreateNestedField(@event.FieldId.Id, @event.Name);

                SchemaDef = SchemaDef.UpdateField(@event.ParentFieldId.Id, x => ((ArrayField)x).AddField(field));
            }
            else
            {
                var partitioning = Partitioning.FromString(@event.Partitioning);

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

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

            SchemaFieldsTotal = Math.Max(SchemaFieldsTotal, @event.FieldId.Id);
        }
Exemplo n.º 3
0
        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++;
        }
Exemplo n.º 4
0
        public IEvent Migrate()
        {
            var schema = new Schema(Name, Properties, Singleton);

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

            var totalFields = 0;

            if (Fields != null)
            {
                foreach (var eventField in Fields)
                {
                    totalFields++;

                    var partitioning = Partitioning.FromString(eventField.Partitioning);

                    var field = eventField.Properties.CreateRootField(totalFields, eventField.Name, partitioning);

                    if (field is ArrayField arrayField && eventField.Nested?.Length > 0)
                    {
                        foreach (var nestedEventField in eventField.Nested)
                        {
                            totalFields++;

                            var nestedField = nestedEventField.Properties.CreateNestedField(totalFields, nestedEventField.Name);

                            if (nestedEventField.IsHidden)
                            {
                                nestedField = nestedField.Hide();
                            }

                            if (nestedEventField.IsDisabled)
                            {
                                nestedField = nestedField.Disable();
                            }

                            if (nestedEventField.IsLocked)
                            {
                                nestedField = nestedField.Lock();
                            }

                            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);
                }
            }

            return(SimpleMapper.Map(this, new SchemaCreatedV2 {
                Schema = schema
            }));
        }
Exemplo n.º 5
0
        public override bool ApplyEvent(IEvent @event)
        {
            var previousSchema = SchemaDef;

            switch (@event)
            {
            case SchemaCreated e:
            {
                SchemaDef         = e.Schema;
                SchemaFieldsTotal = e.Schema.MaxId();

                AppId = e.AppId;

                return(true);
            }

            case FieldAdded e:
            {
                if (e.ParentFieldId != null)
                {
                    var field = e.Properties.CreateNestedField(e.FieldId.Id, e.Name);

                    SchemaDef = SchemaDef.UpdateField(e.ParentFieldId.Id, x => ((ArrayField)x).AddField(field));
                }
                else
                {
                    var partitioning = Partitioning.FromString(e.Partitioning);

                    var field = e.Properties.CreateRootField(e.FieldId.Id, e.Name, partitioning);

                    SchemaDef = SchemaDef.DeleteField(e.FieldId.Id);
                    SchemaDef = SchemaDef.AddField(field);
                }

                SchemaFieldsTotal = Math.Max(SchemaFieldsTotal, e.FieldId.Id);

                break;
            }

            case SchemaUIFieldsConfigured e:
            {
                if (e.FieldsInLists != null)
                {
                    SchemaDef = SchemaDef.SetFieldsInLists(e.FieldsInLists);
                }

                if (e.FieldsInReferences != null)
                {
                    SchemaDef = SchemaDef.SetFieldsInReferences(e.FieldsInReferences);
                }

                break;
            }

            case SchemaCategoryChanged e:
            {
                SchemaDef = SchemaDef.ChangeCategory(e.Name);

                break;
            }

            case SchemaPreviewUrlsConfigured e:
            {
                SchemaDef = SchemaDef.SetPreviewUrls(e.PreviewUrls);

                break;
            }

            case SchemaScriptsConfigured e:
            {
                SchemaDef = SchemaDef.SetScripts(e.Scripts);

                break;
            }

            case SchemaPublished _:
            {
                SchemaDef = SchemaDef.Publish();

                break;
            }

            case SchemaUnpublished _:
            {
                SchemaDef = SchemaDef.Unpublish();

                break;
            }

            case SchemaUpdated e:
            {
                SchemaDef = SchemaDef.Update(e.Properties);

                break;
            }

            case SchemaFieldsReordered e:
            {
                SchemaDef = SchemaDef.ReorderFields(e.FieldIds, e.ParentFieldId?.Id);

                break;
            }

            case FieldUpdated e:
            {
                SchemaDef = SchemaDef.UpdateField(e.FieldId.Id, e.Properties, e.ParentFieldId?.Id);

                break;
            }

            case FieldLocked e:
            {
                SchemaDef = SchemaDef.LockField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldDisabled e:
            {
                SchemaDef = SchemaDef.DisableField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldEnabled e:
            {
                SchemaDef = SchemaDef.EnableField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldHidden e:
            {
                SchemaDef = SchemaDef.HideField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldShown e:
            {
                SchemaDef = SchemaDef.ShowField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case FieldDeleted e:
            {
                SchemaDef = SchemaDef.DeleteField(e.FieldId.Id, e.ParentFieldId?.Id);

                break;
            }

            case SchemaDeleted _:
            {
                IsDeleted = true;

                return(true);
            }
            }

            return(!ReferenceEquals(previousSchema, SchemaDef));
        }
Exemplo n.º 6
0
        public Schema ToSchema(string name, bool isSingleton)
        {
            var schema = new Schema(name, Properties, isSingleton);

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

            if (Scripts != null)
            {
                schema = schema.ConfigureScripts(Scripts);
            }

            if (PreviewUrls != null)
            {
                schema = schema.ConfigurePreviewUrls(PreviewUrls);
            }

            if (FieldsInLists != null)
            {
                schema = schema.ConfigureFieldsInLists(FieldsInLists);
            }

            if (FieldsInReferences != null)
            {
                schema = schema.ConfigureFieldsInReferences(FieldsInReferences);
            }

            if (!string.IsNullOrWhiteSpace(Category))
            {
                schema = schema.ChangeCategory(Category);
            }

            var totalFields = 0;

            if (Fields != null)
            {
                foreach (var eventField in Fields)
                {
                    totalFields++;

                    var partitioning = Partitioning.FromString(eventField.Partitioning);

                    var field = eventField.Properties.CreateRootField(totalFields, eventField.Name, partitioning);

                    if (field is ArrayField arrayField && eventField.Nested?.Count > 0)
                    {
                        foreach (var nestedEventField in eventField.Nested)
                        {
                            totalFields++;

                            var nestedField = nestedEventField.Properties.CreateNestedField(totalFields, nestedEventField.Name);

                            if (nestedEventField.IsHidden)
                            {
                                nestedField = nestedField.Hide();
                            }

                            if (nestedEventField.IsDisabled)
                            {
                                nestedField = nestedField.Disable();
                            }

                            if (nestedEventField.IsLocked)
                            {
                                nestedField = nestedField.Lock();
                            }

                            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);
                }
            }

            return(schema);
        }
Exemplo n.º 7
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 = 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;
        }