Browse Source

Serializer fixed.

pull/152/head
Sebastian Stehle 8 years ago
parent
commit
655270d1a0
  1. 14
      src/Squidex.Domain.Apps.Events/Apps/Utils/AppEventDispatcher.cs
  2. 1
      src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonAttribute.cs
  3. 13
      src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonConvention.cs
  4. 8
      src/Squidex.Infrastructure.MongoDb/MongoDb/JsonBsonSerializer.cs
  5. 6
      src/Squidex.Infrastructure/CQRS/Events/CompoundEventConsumer.cs
  6. 4
      src/Squidex/Config/Domain/Serializers.cs
  7. 5
      src/Squidex/Pipeline/ActionContextLogAppender.cs

14
src/Squidex.Domain.Apps.Events/Apps/Utils/AppEventDispatcher.cs

@ -1,11 +1,12 @@
// ==========================================================================
// MongoAppRepository_EventHandling.cs
// AppEventDispatcher.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Linq;
using Squidex.Domain.Apps.Core.Apps;
namespace Squidex.Domain.Apps.Events.Apps.Utils
@ -60,7 +61,16 @@ namespace Squidex.Domain.Apps.Events.Apps.Utils
public static void Apply(this LanguagesConfig languagesConfig, AppLanguageUpdated @event)
{
languagesConfig.Set(new LanguageConfig(@event.Language, @event.IsOptional, @event.Fallback));
var fallback = @event.Fallback;
if (fallback != null && fallback.Count > 0)
{
var existingLangauges = languagesConfig.OfType<LanguageConfig>().Select(x => x.Language);
fallback = fallback.Intersect(existingLangauges).ToList();
}
languagesConfig.Set(new LanguageConfig(@event.Language, @event.IsOptional, fallback));
if (@event.IsMaster)
{

1
src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonAttribute.cs

@ -10,6 +10,7 @@ using System;
namespace Squidex.Infrastructure.MongoDb
{
[AttributeUsage(AttributeTargets.Property)]
public sealed class BsonJsonAttribute : Attribute
{
}

13
src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonConvention.cs

@ -6,8 +6,10 @@
// All rights reserved.
// ==========================================================================
using System;
using System.Linq;
using System.Reflection;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;
using Newtonsoft.Json;
@ -19,13 +21,16 @@ namespace Squidex.Infrastructure.MongoDb
{
var pack = new ConventionPack();
var bsonSerializer = new JsonBsonSerializer(serializer);
pack.AddMemberMapConvention("JsonBson", memberMap =>
{
if (memberMap.MemberType.GetCustomAttributes().OfType<BsonJsonAttribute>().Any())
var attributes = memberMap.MemberInfo.GetCustomAttributes();
if (attributes.OfType<BsonJsonAttribute>().Any())
{
memberMap.SetSerializer(bsonSerializer);
var bsonSerializerType = typeof(JsonBsonSerializer<>).MakeGenericType(memberMap.MemberType);
var bsonSerializer = Activator.CreateInstance(bsonSerializerType, serializer);
memberMap.SetSerializer((IBsonSerializer)bsonSerializer);
}
});

8
src/Squidex.Infrastructure.MongoDb/MongoDb/JsonBsonSerializer.cs

@ -14,7 +14,7 @@ using Newtonsoft.Json.Linq;
namespace Squidex.Infrastructure.MongoDb
{
public class JsonBsonSerializer : ClassSerializerBase<object>
public class JsonBsonSerializer<T> : ClassSerializerBase<T> where T : class
{
private readonly JsonSerializer serializer;
@ -25,12 +25,12 @@ namespace Squidex.Infrastructure.MongoDb
this.serializer = serializer;
}
protected override object DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
protected override T DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
{
return BsonSerializer.Deserialize<BsonDocument>(context.Reader).ToJson().ToObject(args.NominalType, serializer);
return BsonSerializer.Deserialize<BsonDocument>(context.Reader).ToJson().ToObject<T>(serializer);
}
protected override void SerializeValue(BsonSerializationContext context, BsonSerializationArgs args, object value)
protected override void SerializeValue(BsonSerializationContext context, BsonSerializationArgs args, T value)
{
BsonSerializer.Serialize(context.Writer, JObject.FromObject(value, serializer).ToBson());
}

6
src/Squidex.Infrastructure/CQRS/Events/CompoundEventConsumer.cs

@ -34,7 +34,11 @@ namespace Squidex.Infrastructure.CQRS.Events
Name = name;
EventsFilter = string.Join("|", this.inners.Where(x => !string.IsNullOrWhiteSpace(x.EventsFilter)).Select(x => $"({x.EventsFilter})"));
var innerFilters =
this.inners.Where(x => !string.IsNullOrWhiteSpace(x.EventsFilter))
.Select(x => $"({x.EventsFilter})");
EventsFilter = string.Join("|", innerFilters);
}
public Task ClearAsync()

4
src/Squidex/Config/Domain/Serializers.cs

@ -64,9 +64,9 @@ namespace Squidex.Config.Domain
TypeNameRegistry.Map(typeof(SquidexEvent).GetTypeInfo().Assembly);
TypeNameRegistry.Map(typeof(NoopEvent).GetTypeInfo().Assembly);
BsonJsonConvention.Register(JsonSerializer.Create(SerializerSettings));
ConfigureJson(SerializerSettings, TypeNameHandling.Auto);
BsonJsonConvention.Register(JsonSerializer.Create(SerializerSettings));
}
public static IServiceCollection AddMyEventFormatter(this IServiceCollection services)

5
src/Squidex/Pipeline/ActionContextLogAppender.cs

@ -32,6 +32,11 @@ namespace Squidex.Pipeline
var httpContext = actionContext.HttpContext;
if (string.IsNullOrEmpty(httpContext.Request.Method))
{
return;
}
Guid requestId;
if (httpContext.Items.TryGetValue(nameof(requestId), out var value) && value is Guid requestIdValue)

Loading…
Cancel
Save