@@ -4,7 +4,7 @@ namespace System.Data
44{
55 public static class DbConverterExtensions
66 {
7- private static void CheckDbVersion < TDbConnection > ( TDbConnection connection , Func < TDbConnection , Version > getDbVersion , Version dbVersion ) where TDbConnection : IDbConnection
7+ private static void CheckDbVersion < TDbConnection > ( TDbConnection connection , Func < TDbConnection , CancellationToken , Version > getDbVersion , Version dbVersion , CancellationToken cancellationToken ) where TDbConnection : IDbConnection
88 {
99#if NET6_0_OR_GREATER
1010 ArgumentNullException . ThrowIfNull ( connection ) ;
@@ -15,14 +15,14 @@ private static void CheckDbVersion<TDbConnection>(TDbConnection connection, Func
1515 Throw . IfNull ( getDbVersion ) ;
1616 Throw . IfNull ( dbVersion ) ;
1717#endif
18- var version = getDbVersion ( connection ) ;
18+ var version = getDbVersion ( connection , cancellationToken ) ;
1919 if ( version > dbVersion )
2020 {
2121 throw new DataException ( "File created in a later version of the program. Install the new version to open this file." ) ;
2222 }
2323 }
2424
25- public static void Initialize < TDbConnection > ( this IReadOnlyList < DbConverter < TDbConnection > > converters , IDbContext context ) where TDbConnection : IDbConnection
25+ public static void Initialize < TDbConnection > ( this IReadOnlyList < DbConverter < TDbConnection > > converters , IDbContext context , CancellationToken cancellationToken ) where TDbConnection : IDbConnection
2626 {
2727#if NET6_0_OR_GREATER
2828 ArgumentNullException . ThrowIfNull ( converters ) ;
@@ -31,10 +31,10 @@ public static void Initialize<TDbConnection>(this IReadOnlyList<DbConverter<TDbC
3131 Throw . IfNull ( converters ) ;
3232 Throw . IfNull ( context ) ;
3333#endif
34- converters . Initialize ( ( TDbConnection ) context . Connection ) ;
34+ converters . Initialize ( ( TDbConnection ) context . Connection , cancellationToken ) ;
3535 }
3636
37- public static void Initialize < TDbConnection > ( this IReadOnlyList < DbConverter < TDbConnection > > converters , TDbConnection connection ) where TDbConnection : IDbConnection
37+ public static void Initialize < TDbConnection > ( this IReadOnlyList < DbConverter < TDbConnection > > converters , TDbConnection connection , CancellationToken cancellationToken ) where TDbConnection : IDbConnection
3838 {
3939#if NET6_0_OR_GREATER
4040 ArgumentNullException . ThrowIfNull ( converters ) ;
@@ -57,15 +57,15 @@ public static void Initialize<TDbConnection>(this IReadOnlyList<DbConverter<TDbC
5757#else
5858 var dbVersion = converters [ ^ 1 ] . Version ;
5959#endif
60- if ( converters . RequiresUpdate ( connection ) )
60+ if ( converters . RequiresUpdate ( connection , cancellationToken ) )
6161 {
62- bool result = converters . Update ( connection , dbVersion ) ;
62+ bool result = converters . Update ( connection , dbVersion , cancellationToken ) ;
6363 Debug . Assert ( result ) ;
6464 }
6565#if NETFRAMEWORK || NETSTANDARD2_0
66- CheckDbVersion ( connection , converters [ converters . Count - 1 ] . GetDbVersion , dbVersion ) ;
66+ CheckDbVersion ( connection , converters [ converters . Count - 1 ] . GetDbVersion , dbVersion , cancellationToken ) ;
6767#else
68- CheckDbVersion ( connection , converters [ ^ 1 ] . GetDbVersion , dbVersion ) ;
68+ CheckDbVersion ( connection , converters [ ^ 1 ] . GetDbVersion , dbVersion , cancellationToken ) ;
6969#endif
7070 }
7171 catch ( Exception ex )
@@ -88,7 +88,7 @@ private static bool IsOrderedByAscending<TDbConnection>(this IReadOnlyList<DbCon
8888 return true ;
8989 }
9090
91- private static bool RequiresUpdate < TDbConnection > ( this IReadOnlyList < DbConverter < TDbConnection > > converters , TDbConnection connection ) where TDbConnection : IDbConnection
91+ private static bool RequiresUpdate < TDbConnection > ( this IReadOnlyList < DbConverter < TDbConnection > > converters , TDbConnection connection , CancellationToken cancellationToken ) where TDbConnection : IDbConnection
9292 {
9393#if NET6_0_OR_GREATER
9494 ArgumentNullException . ThrowIfNull ( converters ) ;
@@ -104,14 +104,14 @@ private static bool RequiresUpdate<TDbConnection>(this IReadOnlyList<DbConverter
104104#else
105105 converters [ ^ 1 ]
106106#endif
107- . RequiresUpdate ( connection ) )
107+ . RequiresUpdate ( connection , cancellationToken ) )
108108 {
109109 return true ;
110110 }
111111 return false ;
112112 }
113113
114- private static bool Update < TDbConnection > ( this IReadOnlyList < DbConverter < TDbConnection > > converters , TDbConnection connection , Version dbVersion , bool forceUpdate = false ) where TDbConnection : IDbConnection
114+ private static bool Update < TDbConnection > ( this IReadOnlyList < DbConverter < TDbConnection > > converters , TDbConnection connection , Version dbVersion , CancellationToken cancellationToken ) where TDbConnection : IDbConnection
115115 {
116116 Debug . Assert ( converters != null ) ;
117117 Debug . Assert ( connection is { State : ConnectionState . Open } ) ;
@@ -120,9 +120,9 @@ private static bool Update<TDbConnection>(this IReadOnlyList<DbConverter<TDbConn
120120 Version ? latestVersion = null ;
121121 foreach ( var converter in converters ! )
122122 {
123- if ( forceUpdate || converter . RequiresUpdate ( connection ) )
123+ if ( /* forceUpdate || */ converter . RequiresUpdate ( connection , cancellationToken ) )
124124 {
125- bool updated = converter . Update ( connection ) ;
125+ bool updated = converter . Update ( connection , cancellationToken ) ;
126126 Debug . Assert ( updated ) ;
127127 if ( ! updated )
128128 {
0 commit comments