@@ -194,7 +194,7 @@ public Project(GlyssenBundle bundle, string recordingProjectName = null, Project
194
194
PopulateAndParseBooks ( bundle ) ;
195
195
}
196
196
197
- public Project ( ParatextScrTextWrapper paratextProject ) :
197
+ public Project ( ParatextScrTextWrapper paratextProject , Action < Exception > exceptionHandler = null ) :
198
198
this ( paratextProject . GlyssenDblTextMetadata , null , false , paratextProject . WritingSystem )
199
199
{
200
200
Writer . SetUpProjectPersistence ( this ) ;
@@ -204,7 +204,7 @@ public Project(ParatextScrTextWrapper paratextProject) :
204
204
SetWsQuotationMarksUsingFullySpecifiedContinuers ( paratextProject . QuotationMarks ) ;
205
205
}
206
206
207
- ParseAndSetBooks ( paratextProject . UsxDocumentsForIncludedBooks , paratextProject . Stylesheet ) ;
207
+ ParseAndSetBooks ( paratextProject . UsxDocumentsForIncludedBooks , paratextProject . Stylesheet , exceptionHandler ) ;
208
208
}
209
209
210
210
/// <summary>
@@ -1440,7 +1440,7 @@ public void IncludeExistingBook(BookScript book)
1440
1440
m_books . Insert ( i , book ) ;
1441
1441
}
1442
1442
1443
- public void IncludeBooksFromParatext ( ParatextScrTextWrapper wrapper , ISet < int > bookNumbers , Action < BookScript > postParseAction )
1443
+ public async Task IncludeBooksFromParatext ( ParatextScrTextWrapper wrapper , ISet < int > bookNumbers , Action < BookScript > postParseAction )
1444
1444
{
1445
1445
wrapper . IncludeBooks ( bookNumbers . Select ( BCVRef . NumberToBookCode ) ) ;
1446
1446
var usxBookInfoList = wrapper . GetUsxDocumentsForIncludedParatextBooks ( bookNumbers ) ;
@@ -1453,25 +1453,49 @@ void EnhancedPostParseAction(BookScript book)
1453
1453
postParseAction ? . Invoke ( book ) ;
1454
1454
}
1455
1455
1456
- ParseAndIncludeBooks ( usxBookInfoList , wrapper . Stylesheet , EnhancedPostParseAction ) ;
1456
+ await ParseAndIncludeBooks ( usxBookInfoList , wrapper . Stylesheet , null , EnhancedPostParseAction ) ;
1457
1457
}
1458
1458
1459
- private void ParseAndSetBooks ( IEnumerable < UsxDocument > books , IStylesheet stylesheet )
1459
+ private async Task ParseAndSetBooks ( IEnumerable < UsxDocument > books , IStylesheet stylesheet , Action < Exception > exceptionHandler = null )
1460
1460
{
1461
1461
if ( m_books . Any ( ) )
1462
1462
throw new InvalidOperationException ( "Project already contains books. If the intention is to replace the existing ones, let's clear the list first. Otherwise, call ParseAndIncludeBooks." ) ;
1463
- ParseAndIncludeBooks ( books , stylesheet ) ;
1463
+ await ParseAndIncludeBooks ( books , stylesheet , exceptionHandler ) ;
1464
1464
}
1465
1465
1466
- private async Task ParseAndIncludeBooks ( IEnumerable < UsxDocument > books , IStylesheet stylesheet , Action < BookScript > postParseAction = null )
1466
+ private async Task ParseAndIncludeBooks ( IEnumerable < UsxDocument > books , IStylesheet stylesheet ,
1467
+ Action < Exception > exceptionHandler /* = null*/ , Action < BookScript > postParseAction = null )
1467
1468
{
1468
1469
if ( Versification == null )
1469
1470
throw new NullReferenceException ( "What!!!" ) ;
1470
1471
ProjectState = ProjectState . Initial | ( ProjectState & ProjectState . WritingSystemRecoveryInProcess ) ;
1471
- await Task . Run ( ( ) => { UsxParse ( books , stylesheet , postParseAction ) ; } ) ;
1472
+ List < BookScript > parsedBooks = null ;
1473
+ try
1474
+ {
1475
+ await Task . Run ( ( ) =>
1476
+ {
1477
+ parsedBooks = UsxParse ( books , stylesheet , postParseAction ) ;
1478
+ } ) ;
1479
+
1480
+ await Task . Run ( ( ) =>
1481
+ {
1482
+ if ( QuoteSystem == null )
1483
+ GuessAtQuoteSystem ( ) ;
1484
+ else if ( IsQuoteSystemReadyForParse )
1485
+ DoQuoteParse ( parsedBooks . Select ( b => b . BookId ) ) ;
1486
+ } ) ;
1487
+ }
1488
+ catch ( Exception e )
1489
+ {
1490
+ Console . WriteLine ( e ) ;
1491
+ if ( exceptionHandler == null )
1492
+ ErrorReport . ReportFatalException ( e ) ;
1493
+ else
1494
+ exceptionHandler ( e ) ;
1495
+ }
1472
1496
}
1473
1497
1474
- private void UsxParse ( IEnumerable < UsxDocument > books , IStylesheet stylesheet , Action < BookScript > postParseAction = null )
1498
+ private List < BookScript > UsxParse ( IEnumerable < UsxDocument > books , IStylesheet stylesheet , Action < BookScript > postParseAction = null )
1475
1499
{
1476
1500
var parsedBooks = UsxParser . ParseBooks ( books , stylesheet , i =>
1477
1501
{
@@ -1517,20 +1541,17 @@ private void UsxParse(IEnumerable<UsxDocument> books, IStylesheet stylesheet, Ac
1517
1541
AddMissingAvailableBooks ( ) ;
1518
1542
}
1519
1543
1520
- if ( QuoteSystem == null )
1521
- GuessAtQuoteSystemAsync ( ) ;
1522
- else if ( IsQuoteSystemReadyForParse )
1523
- DoQuoteParseAsync ( parsedBooks . Select ( b => b . BookId ) ) ;
1544
+ return parsedBooks ;
1524
1545
}
1525
1546
1526
1547
private async Task GuessAtQuoteSystemAsync ( )
1527
1548
{
1528
- ProjectState = ProjectState . UsxComplete | ( ProjectState & ProjectState . WritingSystemRecoveryInProcess ) ;
1529
1549
await Task . Run ( GuessAtQuoteSystem ) ;
1530
1550
}
1531
1551
1532
1552
private void GuessAtQuoteSystem ( )
1533
1553
{
1554
+ ProjectState = ProjectState . UsxComplete | ( ProjectState & ProjectState . WritingSystemRecoveryInProcess ) ;
1534
1555
var quoteSystem = QuoteSystemGuesser . Guess ( ControlCharacterVerseData . Singleton , m_books , Versification , out _ ,
1535
1556
i =>
1536
1557
{
@@ -1539,19 +1560,19 @@ private void GuessAtQuoteSystem()
1539
1560
OnReport ( pe ) ;
1540
1561
} ) ;
1541
1562
1542
- SetQuoteSystem ( QuoteSystemStatus . Guessed , quoteSystem ) ;
1563
+ SetQuoteSystem ( QuoteSystemStatus . Guessed , quoteSystem ) ;
1543
1564
Save ( ) ;
1544
1565
}
1545
1566
1546
1567
private async Task DoQuoteParseAsync ( IEnumerable < string > booksToParse = null )
1547
1568
{
1548
- m_projectMetadata . ParserVersion = kParserVersion ;
1549
- ProjectState = ProjectState . Parsing ;
1550
1569
await Task . Run ( ( ) => { DoQuoteParse ( booksToParse ) ; } ) ;
1551
1570
}
1552
1571
1553
1572
private void DoQuoteParse ( IEnumerable < string > bookIds )
1554
1573
{
1574
+ m_projectMetadata . ParserVersion = kParserVersion ;
1575
+ ProjectState = ProjectState . Parsing ;
1555
1576
try
1556
1577
{
1557
1578
QuoteParser . ParseProject ( this , i =>
0 commit comments