public override void Read(ContentSchemaField schemaField, AssetField contentField, BsonValue bsonValue) { if (bsonValue is BsonBinaryData bsonBinary && bsonBinary.IsGuid) { contentField.Asset = ContentItemProxy.CreateAsset(bsonBinary.ToGuid()); } }
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); }
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); }
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); } } }
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); } } }
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); }
public override void Read(ContentSchemaField schemaField, IntegerField contentField, BsonValue bsonvalue) { contentField.Value = (long?)bsonvalue; }
public override void Read(ContentSchemaField schemaField, DateField contentField, BsonValue bsonvalue) { contentField.Value = (DateTime?)bsonvalue; }
public override void Read(ContentSchemaField schemaField, BoolField contentField, BsonValue bsonvalue) { contentField.Value = (bool?)bsonvalue; }
public override void Read(ContentSchemaField schemaField, FloatField contentField, BsonValue bsonvalue) { contentField.Value = (double?)bsonvalue; }
void IFieldSerializer.Read(ContentSchemaField definition, ContentField contentField, BsonValue bsonvalue) { Read(definition, (TContentField)contentField, bsonvalue); }
public abstract void Read(ContentSchemaField schemaField, TContentField contentField, BsonValue bsonValue);