Skip to content

Commit

Permalink
Elimination of background worker for project creation - shared methods
Browse files Browse the repository at this point in the history
Took the code that John Wimbish wrote and made methods for common code that he was using and was already being used by the background workers.
  • Loading branch information
AndrewChristensenFCBH committed Aug 18, 2020
1 parent e5924ee commit 2cf8d8d
Showing 1 changed file with 24 additions and 41 deletions.
65 changes: 24 additions & 41 deletions GlyssenEngine/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ public class Project : ProjectBase, IUserProject

public Func<bool> IsOkayToClearExistingRefBlocksWhenChangingReferenceText { get; set; }






/// <summary>
/// Creates a project and parses it from a Paratext project's Scriptures.
/// </summary>
Expand All @@ -101,12 +96,7 @@ public static async Task<Project> CreateAndLoadAsync(ParatextScrTextWrapper para

// From the other constructor
Writer.SetUpProjectPersistence(glyssenProject);
ProcessParatextProjectQuotationRules(paratextProject);
if (paratextProject.HasQuotationRulesSet)
{
glyssenProject.QuoteSystemStatus = QuoteSystemStatus.Obtained;
glyssenProject.SetWsQuotationMarksUsingFullySpecifiedContinuers(paratextProject.QuotationMarks);
}
ProcessParatextProjectQuotationRules(glyssenProject, paratextProject);

// Sanity Checks
if (glyssenProject.m_books.Any())
Expand Down Expand Up @@ -145,18 +135,8 @@ await Task.Run(() =>
bookScript.Initialize(Versification);
}

m_books.AddRange(bookScripts);
m_projectMetadata.ParserVersion = kParserVersion;
if (m_books.All(b => IsNullOrEmpty(b.PageHeader)))
ChapterAnnouncementStyle = ChapterAnnouncement.ChapterLabel;
UpdateControlFileVersion();
RemoveAvailableBooksThatDoNotCorrespondToExistingBooks();
AddMissingAvailableBooks();

if (QuoteSystem == null)
GuessAtQuoteSystem();
else if (IsQuoteSystemReadyForParse)
DoQuoteParse(bookScripts.Select(b => b.BookId));
ProcessNewProjectBooks(bookScripts);
ProcessQuotes(bookScripts);
});
}

Expand All @@ -183,12 +163,6 @@ private void ThrowIfNullBookScript(ICollection<BookScript> bookScripts, BookScri
$"BookScripts which are NOT null: {nonNullBookScriptsStr}");
}







/// <exception cref="ProjectNotFoundException">Paratext was unable to access the project (only pertains to
/// Glyssen projects that are associated with a live Paratext project)</exception>
public Project(GlyssenDblTextMetadata metadata, string recordingProjectName = null, bool installFonts = false,
Expand Down Expand Up @@ -304,17 +278,16 @@ public Project(ParatextScrTextWrapper paratextProject) :
this(paratextProject.GlyssenDblTextMetadata, null, false, paratextProject.WritingSystem)
{
Writer.SetUpProjectPersistence(this);
ProcessParatextProjectQuotationRules(paratextProject);

ProcessParatextProjectQuotationRules(this, paratextProject);
ParseAndSetBooks(paratextProject.UsxDocumentsForIncludedBooks, paratextProject.Stylesheet);
}

public static void ProcessParatextProjectQuotationRules(ParatextScrTextWrapper paratextProject)
public static void ProcessParatextProjectQuotationRules(Project glyssenProject, ParatextScrTextWrapper paratextProject)
{
if (paratextProject.HasQuotationRulesSet)
{
Project.QuoteSystemStatus = QuoteSystemStatus.Obtained;
SetWsQuotationMarksUsingFullySpecifiedContinuers(paratextProject.QuotationMarks);
glyssenProject.QuoteSystemStatus = QuoteSystemStatus.Obtained;
glyssenProject.SetWsQuotationMarksUsingFullySpecifiedContinuers(paratextProject.QuotationMarks);
}
}

Expand Down Expand Up @@ -1634,15 +1607,25 @@ private void UsxWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEvent
}
else
{
m_books.AddRange(bookScripts);
m_projectMetadata.ParserVersion = kParserVersion;
if (m_books.All(b => IsNullOrEmpty(b.PageHeader)))
ChapterAnnouncementStyle = ChapterAnnouncement.ChapterLabel;
UpdateControlFileVersion();
RemoveAvailableBooksThatDoNotCorrespondToExistingBooks();
AddMissingAvailableBooks();
ProcessNewProjectBooks(bookScripts);
}

ProcessQuotes(bookScripts);
}

public void ProcessNewProjectBooks(List<BookScript> bookScripts)
{
m_books.AddRange(bookScripts);
m_projectMetadata.ParserVersion = kParserVersion;
if (m_books.All(b => IsNullOrEmpty(b.PageHeader)))
ChapterAnnouncementStyle = ChapterAnnouncement.ChapterLabel;
UpdateControlFileVersion();
RemoveAvailableBooksThatDoNotCorrespondToExistingBooks();
AddMissingAvailableBooks();
}

public void ProcessQuotes(List<BookScript> bookScripts)
{
if (QuoteSystem == null)
GuessAtQuoteSystem();
else if (IsQuoteSystemReadyForParse)
Expand Down

0 comments on commit 2cf8d8d

Please sign in to comment.