Ejemplo n.º 1
0
 public override void Read(ContentSchemaField schemaField, AssetField contentField, BsonValue bsonValue)
 {
     if (bsonValue is BsonBinaryData bsonBinary && bsonBinary.IsGuid)
     {
         contentField.Asset = ContentItemProxy.CreateAsset(bsonBinary.ToGuid());
     }
 }
Ejemplo n.º 2
0
 public override void Read(ContentSchemaField schemaField, StringField contentField, BsonValue bsonvalue)
 {
     if (bsonvalue is BsonString bsonString)
     {
         contentField.Value = bsonString.Value;
     }
 }
        public static ContentSchemaField ToModel(this RestContentSchemaField definition)
        {
            Type optionsType = ContentFieldManager.Default.GetOptionsType(definition.FieldType);

            ContentFieldOptions options = (ContentFieldOptions)definition.Options.ToObject(optionsType, NewtonJsonExtensions.CreateSerializer());

            ContentSchemaField schemaField = new ContentSchemaField(definition.FieldType, options);

            schemaField.Label   = definition.Label;
            schemaField.SortKey = definition.SortKey;

            return(schemaField);
        }
Ejemplo n.º 4
0
        public override void Read(ContentSchemaField schemaField, ReferenceField contentField, BsonValue bsonValue)
        {
            if (bsonValue is BsonDocument bsonDocument)
            {
                if (bsonDocument[ReferenceField.IdField] != BsonNull.Value)
                {
                    Guid   targetId   = bsonDocument[ReferenceField.IdField].AsGuid;
                    string targetType = bsonDocument[ReferenceField.SchemaField].AsString;

                    contentField.ContentItem = ContentItemProxy.CreateContentItem(targetId, targetType);
                }
            }
        }
        public static RestContentSchemaField ToRest(this ContentSchemaField schemaField)
        {
            RestContentSchemaField restContentFieldDefinition = new RestContentSchemaField();

            restContentFieldDefinition.Label     = schemaField.Label;
            restContentFieldDefinition.SortKey   = schemaField.SortKey;
            restContentFieldDefinition.FieldType = schemaField.FieldType;

            if (schemaField.Options != null)
            {
                restContentFieldDefinition.Options = JObject.FromObject(schemaField.Options, NewtonJsonExtensions.CreateSerializer());
            }

            return(restContentFieldDefinition);
        }
Ejemplo n.º 6
0
        public override void Read(ContentSchemaField schemaField, EmbedField contentField, BsonValue bsonValue)
        {
            string schemaName = bsonValue[ReferenceField.SchemaField].AsString;

            ContentSchema schema = MongoStorage.Default.GetContentSchemaAsync(schemaName).GetAwaiter().GetResult();

            contentField.ContentEmbedded = schema.CreateContentEmbedded();

            if (bsonValue[nameof(IContentElement.Fields)] is BsonDocument bsonDocument)
            {
                foreach (var field in bsonDocument)
                {
                    field.Value.FromBsonValue(field.Name, contentField.ContentEmbedded, schema);
                }
            }
        }
Ejemplo n.º 7
0
        public override void Read(ContentSchemaField schemaField, ArrayField contentField, BsonValue bsonvalue)
        {
            if (bsonvalue is BsonArray bsonArray)
            {
                ArrayFieldOptions arrayOptions = (ArrayFieldOptions)schemaField.Options;

                foreach (BsonDocument item in bsonArray)
                {
                    ArrayFieldItem arrayFieldItem = arrayOptions.CreateArrayField();

                    foreach (BsonElement subitem in item)
                    {
                        subitem.Value.FromBsonValue(subitem.Name, arrayFieldItem, arrayOptions);
                    }

                    contentField.Items.Add(arrayFieldItem);
                }
            }
        }
Ejemplo n.º 8
0
        public static ContentSchema ToModel(this MongoContentSchema mongoSchema)
        {
            ContentSchema schema = new ContentSchema(mongoSchema.Name);

            schema.Id              = mongoSchema.Id;
            schema.CreatedAt       = mongoSchema.CreatedAt;
            schema.ModifiedAt      = mongoSchema.ModifiedAt;
            schema.Version         = mongoSchema.Version;
            schema.ListFields      = mongoSchema.ListFields.ToList();
            schema.ReferenceFields = mongoSchema.ReferenceFields.ToList();
            schema.OrderFields     = mongoSchema.OrderFields.ToList();

            foreach (var field in mongoSchema.Fields)
            {
                Type optionsType            = ContentFieldManager.Default.GetOptionsType(field.Value.FieldType);
                ContentFieldOptions?options = null;

                if (field.Value.Options != BsonNull.Value)
                {
                    options = (ContentFieldOptions)BsonSerializer.Deserialize((BsonDocument)field.Value.Options, optionsType);
                }

                if (options == null)
                {
                    options = ContentFieldManager.Default.CreateOptions(field.Value.FieldType);
                }

                ContentSchemaField schemaField = new ContentSchemaField(field.Value.FieldType, options);
                schemaField.Label   = field.Value.Label;
                schemaField.SortKey = field.Value.SortKey;

                schema.Fields.Add(field.Key, schemaField);
            }

            return(schema);
        }
Ejemplo n.º 9
0
 public override void Read(ContentSchemaField schemaField, IntegerField contentField, BsonValue bsonvalue)
 {
     contentField.Value = (long?)bsonvalue;
 }
Ejemplo n.º 10
0
 public override void Read(ContentSchemaField schemaField, DateField contentField, BsonValue bsonvalue)
 {
     contentField.Value = (DateTime?)bsonvalue;
 }
Ejemplo n.º 11
0
 public override void Read(ContentSchemaField schemaField, BoolField contentField, BsonValue bsonvalue)
 {
     contentField.Value = (bool?)bsonvalue;
 }
Ejemplo n.º 12
0
 public override void Read(ContentSchemaField schemaField, FloatField contentField, BsonValue bsonvalue)
 {
     contentField.Value = (double?)bsonvalue;
 }
Ejemplo n.º 13
0
 void IFieldSerializer.Read(ContentSchemaField definition, ContentField contentField, BsonValue bsonvalue)
 {
     Read(definition, (TContentField)contentField, bsonvalue);
 }
Ejemplo n.º 14
0
 public abstract void Read(ContentSchemaField schemaField, TContentField contentField, BsonValue bsonValue);