Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Driver.Linq;
using WorkflowCore.Interface;
using WorkflowCore.Models;
Expand All @@ -24,6 +26,13 @@ public MongoPersistenceProvider(IMongoDatabase database)

static MongoPersistenceProvider()
{
ConventionRegistry.Register(
"workflow.conventions",
new ConventionPack
{
new EnumRepresentationConvention(BsonType.String)
}, t => t.FullName?.StartsWith("WorkflowCore") ?? false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this compatible with existing databases out there that have done it the old way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can serialize/deserialize in both ways. The new or replaced documents will have the new representation and the old ones will remain as they are.


BsonClassMap.RegisterClassMap<WorkflowInstance>(x =>
{
x.MapIdProperty(y => y.Id)
Expand Down Expand Up @@ -72,8 +81,14 @@ static void CreateIndexes(MongoPersistenceProvider instance)
{
if (!indexesCreated)
{
instance.WorkflowInstances.Indexes.CreateOne(Builders<WorkflowInstance>.IndexKeys.Ascending(x => x.NextExecution), new CreateIndexOptions() { Background = true, Name = "idx_nextExec" });
instance.Events.Indexes.CreateOne(Builders<Event>.IndexKeys.Ascending(x => x.IsProcessed), new CreateIndexOptions() { Background = true, Name = "idx_processed" });
instance.WorkflowInstances.Indexes.CreateOne(new CreateIndexModel<WorkflowInstance>(
Builders<WorkflowInstance>.IndexKeys.Ascending(x => x.NextExecution),
new CreateIndexOptions {Background = true, Name = "idx_nextExec"}));

instance.Events.Indexes.CreateOne(new CreateIndexModel<Event>(
Builders<Event>.IndexKeys.Ascending(x => x.IsProcessed),
new CreateIndexOptions {Background = true, Name = "idx_processed"}));

indexesCreated = true;
}
}
Expand Down