|
|
|
@ -7,6 +7,7 @@ |
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
@ -72,14 +73,14 @@ namespace Migrations.Migrations.MongoDb |
|
|
|
metadata["AggregateId"] = newDomainId; |
|
|
|
metadata.Remove("AppId"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var filter = Builders<BsonDocument>.Filter.Eq("_id", document["_id"].AsString); |
|
|
|
var filter = Builders<BsonDocument>.Filter.Eq("_id", document["_id"].AsString); |
|
|
|
|
|
|
|
updates.Add(new ReplaceOneModel<BsonDocument>(filter, document) |
|
|
|
{ |
|
|
|
IsUpsert = true |
|
|
|
}); |
|
|
|
} |
|
|
|
updates.Add(new ReplaceOneModel<BsonDocument>(filter, document) |
|
|
|
{ |
|
|
|
IsUpsert = true |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
await collectionNew.BulkWriteAsync(updates, writeOptions); |
|
|
|
@ -104,6 +105,8 @@ namespace Migrations.Migrations.MongoDb |
|
|
|
|
|
|
|
private static bool TryGetAppId(BsonDocument document, [MaybeNullWhen(false)] out string appId) |
|
|
|
{ |
|
|
|
const int guidLength = 36; |
|
|
|
|
|
|
|
foreach (var @event in document["Events"].AsBsonArray) |
|
|
|
{ |
|
|
|
var metadata = @event["Metadata"].AsBsonDocument; |
|
|
|
@ -113,6 +116,27 @@ namespace Migrations.Migrations.MongoDb |
|
|
|
appId = value.AsString; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (metadata.TryGetValue("AggregateId", out var aggregateId)) |
|
|
|
{ |
|
|
|
var parts = aggregateId.AsString.Split("--"); |
|
|
|
|
|
|
|
if (parts.Length == 2) |
|
|
|
{ |
|
|
|
appId = parts[0]; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var payload = @event["Payload"].AsString; |
|
|
|
|
|
|
|
var indexOfAppId = payload.IndexOf("appId\":\"", StringComparison.OrdinalIgnoreCase); |
|
|
|
|
|
|
|
if (indexOfAppId > 0) |
|
|
|
{ |
|
|
|
appId = payload.Substring(indexOfAppId, guidLength); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
appId = null; |
|
|
|
|