Browse Source

Formatting fixed.

pull/250/head
Sebastian Stehle 8 years ago
parent
commit
88b89836d8
  1. 8
      src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEvent.cs
  2. 2
      src/Squidex.Infrastructure/EventSourcing/DefaultEventDataFormatter.cs
  3. 11
      src/Squidex.Infrastructure/States/DefaultStreamNameResolver.cs
  4. 45
      src/Squidex.Infrastructure/TypeNameRegistry.cs
  5. 2
      src/Squidex/Config/Domain/InfrastructureServices.cs

8
src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEvent.cs

@ -10,19 +10,19 @@ using Newtonsoft.Json.Linq;
namespace Squidex.Infrastructure.EventSourcing
{
public class MongoEvent
public sealed class MongoEvent
{
[BsonElement]
[BsonRequired]
public string Payload { get; set; }
public string Type { get; set; }
[BsonElement]
[BsonRequired]
public JToken Metadata { get; set; }
public string Payload { get; set; }
[BsonElement]
[BsonRequired]
public string Type { get; set; }
public JToken Metadata { get; set; }
public static MongoEvent FromEventData(EventData data)
{

2
src/Squidex.Infrastructure/EventSourcing/DefaultEventDataFormatter.cs

@ -29,7 +29,7 @@ namespace Squidex.Infrastructure.EventSourcing
{
var eventType = typeNameRegistry.GetType(eventData.Type);
var headers = eventData.Metadata.ToObject<EnvelopeHeaders>();
var headers = eventData.Metadata.ToObject<EnvelopeHeaders>(serializer);
var content = eventData.Payload.ToObject(eventType, serializer) as IEvent;
if (migrate && content is IMigratedEvent migratedEvent)

11
src/Squidex.Infrastructure/States/DefaultStreamNameResolver.cs

@ -11,15 +11,20 @@ namespace Squidex.Infrastructure.States
{
public sealed class DefaultStreamNameResolver : IStreamNameResolver
{
private const string Suffix = "DomainObject";
private static readonly string[] Suffixes = { "Grain", "DomainObject" };
public string GetStreamName(Type aggregateType, string id)
{
var typeName = char.ToLower(aggregateType.Name[0]) + aggregateType.Name.Substring(1);
if (typeName.EndsWith(Suffix, StringComparison.Ordinal))
foreach (var suffix in Suffixes)
{
typeName = typeName.Substring(0, typeName.Length - Suffix.Length);
if (typeName.EndsWith(suffix, StringComparison.Ordinal))
{
typeName = typeName.Substring(0, typeName.Length - suffix.Length);
break;
}
}
return $"{typeName}-{id}";

45
src/Squidex.Infrastructure/TypeNameRegistry.cs

@ -23,19 +23,14 @@ namespace Squidex.Infrastructure
lock (namesByType)
{
try
if (typesByName.TryGetValue(name, out var existingType) && existingType != type)
{
typesByName.Add(name, type);
}
catch (ArgumentException)
{
if (typesByName[name] != type)
{
var message = $"The name '{name}' is already registered with type '{typesByName[name]}'";
var message = $"The name '{name}' is already registered with type '{typesByName[name]}'";
throw new ArgumentException(message, nameof(type));
}
throw new ArgumentException(message, nameof(type));
}
typesByName[name] = type;
}
return this;
@ -62,33 +57,23 @@ namespace Squidex.Infrastructure
lock (namesByType)
{
try
{
namesByType.Add(type, name);
}
catch (ArgumentException)
if (namesByType.TryGetValue(type, out var existingName) && existingName != name)
{
if (namesByType[type] != name)
{
var message = $"The type '{type}' is already registered with name '{namesByType[type]}'";
var message = $"The type '{type}' is already registered with name '{namesByType[type]}'";
throw new ArgumentException(message, nameof(type));
}
throw new ArgumentException(message, nameof(type));
}
try
{
typesByName.Add(name, type);
}
catch (ArgumentException)
namesByType[type] = name;
if (typesByName.TryGetValue(name, out var existingType) && existingType != type)
{
if (typesByName[name] != type)
{
var message = $"The name '{name}' is already registered with type '{typesByName[name]}'";
var message = $"The name '{name}' is already registered with type '{typesByName[name]}'";
throw new ArgumentException(message, nameof(type));
}
throw new ArgumentException(message, nameof(type));
}
typesByName[name] = type;
}
return this;

2
src/Squidex/Config/Domain/InfrastructureServices.cs

@ -91,6 +91,8 @@ namespace Squidex.Config.Domain
services.AddSingletonAs<Migrator>()
.AsSelf();
services.AddSingleton(typeof(IStore<>), typeof(Store<>));
}
}
}

Loading…
Cancel
Save