From 90da1c131d283bc1bc2c1db855c438926745c60e Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 24 Jul 2022 21:14:12 +0430 Subject: [PATCH] docs: re-assigning prosody rhymes to regenerated poem sections --- RMuseum/Controllers/GanjoorController.cs | 1 + .../GanjoorService-PoemSections.cs | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index a896772b..67c30d57 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -2580,6 +2580,7 @@ namespace RMuseum.Controllers /// /// user bookmarks /// + /// /// /// a phrase to be searched through user private notes /// diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs index cc6621dc..c174f3cc 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs @@ -654,11 +654,51 @@ namespace RMuseum.Services.Implementation try { var sections = await _context.GanjoorPoemSections.Where(s => s.PoemId == id).ToListAsync(); + int? meterId = sections.Any(s => s.SectionType == PoemSectionType.WholePoem && s.VerseType == VersePoemSectionType.First) ? sections.First(s => s.SectionType == PoemSectionType.WholePoem && s.VerseType == VersePoemSectionType.First).GanjoorMetreId : null; _context.RemoveRange(sections); await _context.SaveChangesAsync(); var poem = await _context.GanjoorPoems.Include(p => p.Cat).AsNoTracking().SingleAsync(p => p.Id == id); await _SectionizePoem(_context, poem, jobProgressServiceEF, job); + + if(meterId != null) + { + List rhymes = new List(); + var newSections = await _context.GanjoorPoemSections.Where(s => s.PoemId == id).ToListAsync(); + foreach (var section in newSections) + { + section.GanjoorMetreId = meterId; + if(!string.IsNullOrEmpty(section.RhymeLetters)) + { + if(!rhymes.Contains(section.RhymeLetters)) + { + rhymes.Add(section.RhymeLetters); + } + } + } + _context.UpdateRange(newSections); + await _context.SaveChangesAsync(); + if (rhymes.Count > 0) + { + _backgroundTaskQueue.QueueBackgroundWorkItem + ( + async token => + { + using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions())) //this is long running job, so _context might be already been freed/collected by GC + { + LongRunningJobProgressServiceEF jobProgressServiceEF2 = new LongRunningJobProgressServiceEF(context); + var job2 = (await jobProgressServiceEF2.NewJob($"RegeneratePoemSections - Updating related sections", "Query data")).Result; + foreach (var rhyme in rhymes) + { + await _UpdateRelatedSections(context, (int)meterId, rhyme, jobProgressServiceEF2, job2); + } + } + } + ); + } + + } + await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true); return new RServiceResult(true); }