99using System . Collections . Generic ;
1010using System . Collections . Immutable ;
1111using System . IO ;
12+ using System . Linq ;
1213using System . Threading ;
1314using System . Threading . Tasks ;
1415
1516namespace publisher ;
1617
17- internal delegate Option < PublisherAction > FindBackendAction ( FileInfo file ) ;
18+ internal delegate ValueTask ProcessBackendsToPut ( CancellationToken cancellationToken ) ;
19+ internal delegate ValueTask ProcessDeletedBackends ( CancellationToken cancellationToken ) ;
1820
1921file delegate Option < BackendName > TryParseBackendName ( FileInfo file ) ;
2022
@@ -32,6 +34,30 @@ namespace publisher;
3234
3335file delegate ValueTask DeleteBackendFromApim ( BackendName name , CancellationToken cancellationToken ) ;
3436
37+ file sealed class ProcessBackendsToPutHandler ( GetPublisherFiles getPublisherFiles ,
38+ TryParseBackendName tryParseBackendName ,
39+ IsBackendNameInSourceControl isNameInSourceControl ,
40+ PutBackend putBackend )
41+ {
42+ public async ValueTask Handle ( CancellationToken cancellationToken ) =>
43+ await getPublisherFiles ( )
44+ . Choose ( tryParseBackendName . Invoke )
45+ . Where ( isNameInSourceControl . Invoke )
46+ . IterParallel ( putBackend . Invoke , cancellationToken ) ;
47+ }
48+
49+ file sealed class ProcessDeletedBackendsHandler ( GetPublisherFiles getPublisherFiles ,
50+ TryParseBackendName tryParseBackendName ,
51+ IsBackendNameInSourceControl isNameInSourceControl ,
52+ DeleteBackend deleteBackend )
53+ {
54+ public async ValueTask Handle ( CancellationToken cancellationToken ) =>
55+ await getPublisherFiles ( )
56+ . Choose ( tryParseBackendName . Invoke )
57+ . Where ( name => isNameInSourceControl ( name ) is false )
58+ . IterParallel ( deleteBackend . Invoke , cancellationToken ) ;
59+ }
60+
3561file sealed class FindBackendActionHandler ( TryParseBackendName tryParseName , ProcessBackend processBackend )
3662{
3763 public Option < PublisherAction > Handle ( FileInfo file ) =>
@@ -189,13 +215,14 @@ public async ValueTask Handle(BackendName name, CancellationToken cancellationTo
189215
190216internal static class BackendServices
191217{
192- public static void ConfigureFindBackendAction ( IServiceCollection services )
218+ public static void ConfigureProcessBackendsToPut ( IServiceCollection services )
193219 {
194220 ConfigureTryParseBackendName ( services ) ;
195- ConfigureProcessBackend ( services ) ;
221+ ConfigureIsBackendNameInSourceControl ( services ) ;
222+ ConfigurePutBackend ( services ) ;
196223
197- services . TryAddSingleton < FindBackendActionHandler > ( ) ;
198- services . TryAddSingleton < FindBackendAction > ( provider => provider . GetRequiredService < FindBackendActionHandler > ( ) . Handle ) ;
224+ services . TryAddSingleton < ProcessBackendsToPutHandler > ( ) ;
225+ services . TryAddSingleton < ProcessBackendsToPut > ( provider => provider . GetRequiredService < ProcessBackendsToPutHandler > ( ) . Handle ) ;
199226 }
200227
201228 private static void ConfigureTryParseBackendName ( IServiceCollection services )
@@ -241,6 +268,16 @@ private static void ConfigurePutBackendInApim(IServiceCollection services)
241268 services . TryAddSingleton < PutBackendInApim > ( provider => provider . GetRequiredService < PutBackendInApimHandler > ( ) . Handle ) ;
242269 }
243270
271+ public static void ConfigureProcessDeletedBackends ( IServiceCollection services )
272+ {
273+ ConfigureTryParseBackendName ( services ) ;
274+ ConfigureIsBackendNameInSourceControl ( services ) ;
275+ ConfigureDeleteBackend ( services ) ;
276+
277+ services . TryAddSingleton < ProcessDeletedBackendsHandler > ( ) ;
278+ services . TryAddSingleton < ProcessDeletedBackends > ( provider => provider . GetRequiredService < ProcessDeletedBackendsHandler > ( ) . Handle ) ;
279+ }
280+
244281 private static void ConfigureDeleteBackend ( IServiceCollection services )
245282 {
246283 ConfigureDeleteBackendFromApim ( services ) ;
0 commit comments