5
5
using System . Collections . Generic ;
6
6
using System . Linq ;
7
7
using System . Threading . Tasks ;
8
+ using MongoDB . Bson ;
9
+ using MongoDB . Bson . Serialization . Conventions ;
8
10
using MongoDB . Driver . Linq ;
9
11
using WorkflowCore . Interface ;
10
12
using WorkflowCore . Models ;
@@ -24,6 +26,13 @@ public MongoPersistenceProvider(IMongoDatabase database)
24
26
25
27
static MongoPersistenceProvider ( )
26
28
{
29
+ ConventionRegistry . Register (
30
+ "workflow.conventions" ,
31
+ new ConventionPack
32
+ {
33
+ new EnumRepresentationConvention ( BsonType . String )
34
+ } , t => t . FullName ? . StartsWith ( "WorkflowCore" ) ?? false ) ;
35
+
27
36
BsonClassMap . RegisterClassMap < WorkflowInstance > ( x =>
28
37
{
29
38
x . MapIdProperty ( y => y . Id )
@@ -73,8 +82,14 @@ static void CreateIndexes(MongoPersistenceProvider instance)
73
82
{
74
83
if ( ! indexesCreated )
75
84
{
76
- instance . WorkflowInstances . Indexes . CreateOne ( Builders < WorkflowInstance > . IndexKeys . Ascending ( x => x . NextExecution ) , new CreateIndexOptions ( ) { Background = true , Name = "idx_nextExec" } ) ;
77
- instance . Events . Indexes . CreateOne ( Builders < Event > . IndexKeys . Ascending ( x => x . IsProcessed ) , new CreateIndexOptions ( ) { Background = true , Name = "idx_processed" } ) ;
85
+ instance . WorkflowInstances . Indexes . CreateOne ( new CreateIndexModel < WorkflowInstance > (
86
+ Builders < WorkflowInstance > . IndexKeys . Ascending ( x => x . NextExecution ) ,
87
+ new CreateIndexOptions { Background = true , Name = "idx_nextExec" } ) ) ;
88
+
89
+ instance . Events . Indexes . CreateOne ( new CreateIndexModel < Event > (
90
+ Builders < Event > . IndexKeys . Ascending ( x => x . IsProcessed ) ,
91
+ new CreateIndexOptions { Background = true , Name = "idx_processed" } ) ) ;
92
+
78
93
indexesCreated = true ;
79
94
}
80
95
}
0 commit comments