@@ -73,7 +73,10 @@ IRepository<UserSecret> userSecrets
7373 public async Task < string > AddSmtProjectAsync ( string sfProjectId , CancellationToken cancellationToken )
7474 {
7575 // Load the project from the realtime service
76- Attempt < SFProject > attempt = await realtimeService . TryGetSnapshotAsync < SFProject > ( sfProjectId ) ;
76+ Attempt < SFProject > attempt = await realtimeService . TryGetSnapshotAsync < SFProject > (
77+ sfProjectId ,
78+ cancellationToken
79+ ) ;
7780 if ( ! attempt . TryResult ( out SFProject project ) )
7881 {
7982 throw new DataNotFoundException ( "The project does not exist." ) ;
@@ -134,7 +137,8 @@ await projectSecrets.UpdateAsync(
134137 {
135138 u . Unset ( p => p . ServalData . TranslationQueuedAt ) ;
136139 }
137- }
140+ } ,
141+ cancellationToken : cancellationToken
138142 ) ;
139143 }
140144 catch ( ServalApiException e ) when ( e . StatusCode == 409 )
@@ -154,7 +158,8 @@ await projectSecrets.UpdateAsync(
154158 u . Unset ( p => p . ServalData . TranslationJobId ) ;
155159 u . Unset ( p => p . ServalData . TranslationQueuedAt ) ;
156160 }
157- }
161+ } ,
162+ cancellationToken : cancellationToken
158163 ) ;
159164 }
160165 catch ( DataNotFoundException e )
@@ -191,7 +196,8 @@ await projectSecrets.UpdateAsync(
191196 u . Unset ( p => p . ServalData . TranslationJobId ) ;
192197 u . Unset ( p => p . ServalData . TranslationQueuedAt ) ;
193198 }
194- }
199+ } ,
200+ cancellationToken : cancellationToken
195201 ) ;
196202 }
197203 }
@@ -213,7 +219,10 @@ CancellationToken cancellationToken
213219 )
214220 {
215221 // Load the project from the realtime service
216- Attempt < SFProject > attempt = await realtimeService . TryGetSnapshotAsync < SFProject > ( sfProjectId ) ;
222+ Attempt < SFProject > attempt = await realtimeService . TryGetSnapshotAsync < SFProject > (
223+ sfProjectId ,
224+ cancellationToken
225+ ) ;
217226 if ( ! attempt . TryResult ( out SFProject project ) )
218227 {
219228 throw new DataNotFoundException ( "The project does not exist." ) ;
@@ -244,7 +253,11 @@ CancellationToken cancellationToken
244253 )
245254 {
246255 // Load the target project secrets, so we can get the translation engine ID
247- if ( ! ( await projectSecrets . TryGetAsync ( sfProjectId ) ) . TryResult ( out SFProjectSecret projectSecret ) )
256+ if (
257+ ! ( await projectSecrets . TryGetAsync ( sfProjectId , cancellationToken ) ) . TryResult (
258+ out SFProjectSecret projectSecret
259+ )
260+ )
248261 {
249262 throw new DataNotFoundException ( "The project secret cannot be found." ) ;
250263 }
@@ -364,7 +377,8 @@ await projectSecrets.UpdateAsync(
364377
365378 // Remove all corpora that were deleted
366379 u . RemoveAll ( p => p . ServalData . CorpusFiles , p => corpusIdsToRemove . Contains ( p . CorpusId ) ) ;
367- }
380+ } ,
381+ cancellationToken : cancellationToken
368382 ) ;
369383 }
370384
@@ -519,7 +533,11 @@ CancellationToken cancellationToken
519533 )
520534 {
521535 // Load the target project secrets, so we can get the translation engine ID
522- if ( ! ( await projectSecrets . TryGetAsync ( buildConfig . ProjectId ) ) . TryResult ( out SFProjectSecret projectSecret ) )
536+ if (
537+ ! ( await projectSecrets . TryGetAsync ( buildConfig . ProjectId , cancellationToken ) ) . TryResult (
538+ out SFProjectSecret projectSecret
539+ )
540+ )
523541 {
524542 throw new DataNotFoundException ( "The project secret cannot be found." ) ;
525543 }
@@ -564,7 +582,7 @@ await RecreateOrUpdateTranslationEngineIfRequiredAsync(
564582 ) ;
565583
566584 // Get the updated project secret
567- projectSecret = await projectSecrets . GetAsync ( buildConfig . ProjectId ) ;
585+ projectSecret = await projectSecrets . GetAsync ( buildConfig . ProjectId , cancellationToken : cancellationToken ) ;
568586
569587 // Ensure we have the ServalData
570588 if ( projectSecret . ServalData is null )
@@ -622,7 +640,8 @@ await projectSecrets.UpdateAsync(
622640 u . Unset ( p => p . ServalData . TranslationJobId ) ;
623641 u . Unset ( p => p . ServalData . TranslationQueuedAt ) ;
624642 }
625- }
643+ } ,
644+ cancellationToken : cancellationToken
626645 ) ;
627646
628647 return translationBuild . Id ;
@@ -727,7 +746,7 @@ CancellationToken cancellationToken
727746 )
728747 {
729748 // Get the existing project secret, so we can see how to create the engine and update the Serval data
730- SFProjectSecret projectSecret = await projectSecrets . GetAsync ( sfProject . Id ) ;
749+ SFProjectSecret projectSecret = await projectSecrets . GetAsync ( sfProject . Id , cancellationToken ) ;
731750 string translationEngineId = GetTranslationEngineId ( projectSecret , preTranslate ) ;
732751 if ( string . IsNullOrWhiteSpace ( translationEngineId ) )
733752 {
@@ -757,15 +776,17 @@ CancellationToken cancellationToken
757776 // Store the Pre-Translation Engine ID
758777 await projectSecrets . UpdateAsync (
759778 sfProject . Id ,
760- u => u . Set ( p => p . ServalData . PreTranslationEngineId , translationEngineId )
779+ u => u . Set ( p => p . ServalData . PreTranslationEngineId , translationEngineId ) ,
780+ cancellationToken : cancellationToken
761781 ) ;
762782 }
763783 else if ( projectSecret . ServalData is not null )
764784 {
765785 // Store the Translation Engine ID
766786 await projectSecrets . UpdateAsync (
767787 sfProject . Id ,
768- u => u . Set ( p => p . ServalData . TranslationEngineId , translationEngineId )
788+ u => u . Set ( p => p . ServalData . TranslationEngineId , translationEngineId ) ,
789+ cancellationToken : cancellationToken
769790 ) ;
770791 }
771792 else if ( preTranslate )
@@ -777,7 +798,8 @@ await projectSecrets.UpdateAsync(
777798 u . Set (
778799 p => p . ServalData ,
779800 new ServalData { PreTranslationEngineId = translationEngineId , CorpusFiles = [ ] }
780- )
801+ ) ,
802+ cancellationToken : cancellationToken
781803 ) ;
782804 }
783805 else
@@ -789,7 +811,8 @@ await projectSecrets.UpdateAsync(
789811 u . Set (
790812 p => p . ServalData ,
791813 new ServalData { TranslationEngineId = translationEngineId , CorpusFiles = [ ] }
792- )
814+ ) ,
815+ cancellationToken : cancellationToken
793816 ) ;
794817 }
795818 }
@@ -913,7 +936,7 @@ CancellationToken cancellationToken
913936 )
914937 {
915938 // Get the user secret
916- Attempt < UserSecret > userSecretAttempt = await userSecrets . TryGetAsync ( curUserId ) ;
939+ Attempt < UserSecret > userSecretAttempt = await userSecrets . TryGetAsync ( curUserId , cancellationToken ) ;
917940 if ( ! userSecretAttempt . TryResult ( out UserSecret userSecret ) )
918941 {
919942 throw new DataNotFoundException ( "The user does not exist." ) ;
@@ -987,7 +1010,8 @@ await projectSecrets.UpdateAsync(
9871010 {
9881011 u . Unset ( p => p . ServalData . TranslationEngineId ) ;
9891012 }
990- }
1013+ } ,
1014+ cancellationToken : cancellationToken
9911015 ) ;
9921016
9931017 // Create the Serval project, and get the translation engine id
@@ -1333,7 +1357,8 @@ await projectSecrets.UpdateAsync(
13331357 {
13341358 u . Unset ( p => p . ServalData . TranslationEngineId ) ;
13351359 }
1336- }
1360+ } ,
1361+ cancellationToken : cancellationToken
13371362 ) ;
13381363
13391364 // Create the new translation engine id
@@ -1358,7 +1383,11 @@ CancellationToken cancellationToken
13581383 )
13591384 {
13601385 // Load the target project secrets, so we can get the translation engine ID
1361- if ( ! ( await projectSecrets . TryGetAsync ( sfProjectId ) ) . TryResult ( out SFProjectSecret projectSecret ) )
1386+ if (
1387+ ! ( await projectSecrets . TryGetAsync ( sfProjectId , cancellationToken ) ) . TryResult (
1388+ out SFProjectSecret projectSecret
1389+ )
1390+ )
13621391 {
13631392 throw new DataNotFoundException ( "The project secret cannot be found." ) ;
13641393 }
@@ -1410,13 +1439,21 @@ await translationEnginesClient.DeleteCorpusAsync(
14101439 }
14111440
14121441 // Remove our record of the corpus
1413- await projectSecrets . UpdateAsync ( sfProjectId , u => u . Unset ( p => p . ServalData . Corpora [ corpusId ] ) ) ;
1442+ await projectSecrets . UpdateAsync (
1443+ sfProjectId ,
1444+ u => u . Unset ( p => p . ServalData . Corpora [ corpusId ] ) ,
1445+ cancellationToken : cancellationToken
1446+ ) ;
14141447 }
14151448
14161449 // Remove the corpora property if it is empty
14171450 if ( projectSecret . ServalData ? . Corpora ? . Any ( c => c . Value . PreTranslate != preTranslate ) == false )
14181451 {
1419- await projectSecrets . UpdateAsync ( sfProjectId , u => u . Unset ( p => p . ServalData . Corpora ) ) ;
1452+ await projectSecrets . UpdateAsync (
1453+ sfProjectId ,
1454+ u => u . Unset ( p => p . ServalData . Corpora ) ,
1455+ cancellationToken : cancellationToken
1456+ ) ;
14201457 }
14211458 }
14221459
@@ -1567,14 +1604,21 @@ CancellationToken cancellationToken
15671604 )
15681605 {
15691606 // Load the project from the realtime service
1570- Attempt < SFProject > attempt = await realtimeService . TryGetSnapshotAsync < SFProject > ( buildConfig . ProjectId ) ;
1607+ Attempt < SFProject > attempt = await realtimeService . TryGetSnapshotAsync < SFProject > (
1608+ buildConfig . ProjectId ,
1609+ cancellationToken
1610+ ) ;
15711611 if ( ! attempt . TryResult ( out SFProject project ) )
15721612 {
15731613 throw new DataNotFoundException ( "The project does not exist." ) ;
15741614 }
15751615
15761616 // Load the project secrets, so we can get the corpus files
1577- if ( ! ( await projectSecrets . TryGetAsync ( project . Id ) ) . TryResult ( out SFProjectSecret projectSecret ) )
1617+ if (
1618+ ! ( await projectSecrets . TryGetAsync ( project . Id , cancellationToken ) ) . TryResult (
1619+ out SFProjectSecret projectSecret
1620+ )
1621+ )
15781622 {
15791623 throw new DataNotFoundException ( "The project secret cannot be found." ) ;
15801624 }
@@ -1840,7 +1884,8 @@ await projectSecrets.UpdateAsync(
18401884 {
18411885 u . Set ( p => p . ServalData . ParallelCorpusIdForSmt , translationParallelCorpusId ) ;
18421886 }
1843- }
1887+ } ,
1888+ cancellationToken : cancellationToken
18441889 ) ;
18451890
18461891 return corporaSyncInfo ;
0 commit comments