#442 tag category poems with sources
This commit is contained in:
parent
6aafd19791
commit
cf8f12f592
@ -3941,6 +3941,18 @@
|
||||
<member name="M:RMuseum.Migrations.PaperSources.BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder)">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
<member name="T:RMuseum.Migrations.SureNameFix">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
<member name="M:RMuseum.Migrations.SureNameFix.Up(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
<member name="M:RMuseum.Migrations.SureNameFix.Down(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
<member name="M:RMuseum.Migrations.SureNameFix.BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder)">
|
||||
<inheritdoc />
|
||||
</member>
|
||||
<member name="T:RMuseum.Models.Accounting.DonationExpenditure">
|
||||
<summary>
|
||||
donation expenditures
|
||||
@ -17864,6 +17876,9 @@
|
||||
<summary>
|
||||
IGanjoorService implementation
|
||||
</summary>
|
||||
<summary>
|
||||
IGanjoorService implementation
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.SwitchCoupletBookmark(System.Guid,System.Int32,System.Int32)">
|
||||
<summary>
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RSecurityBackend.Models.Generic;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using RMuseum.DbContext;
|
||||
using System.Collections.Generic;
|
||||
using RSecurityBackend.Services.Implementation;
|
||||
|
||||
namespace RMuseum.Services.Implementation
|
||||
{
|
||||
/// <summary>
|
||||
/// IGanjoorService implementation
|
||||
/// </summary>
|
||||
public partial class GanjoorService : IGanjoorService
|
||||
{
|
||||
public void TagCategoryWithSource(int catId, string sourceUrlSlug)
|
||||
{
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
|
||||
{
|
||||
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
|
||||
var job = (await jobProgressServiceEF.NewJob($"TagCategoryWithSource(catId: {catId} - source:{sourceUrlSlug})", "Query data")).Result;
|
||||
try
|
||||
{
|
||||
var page = await context.GanjoorPages.AsNoTracking().Where(p => p.FullUrl == $"/sources/{sourceUrlSlug}").SingleOrDefaultAsync();
|
||||
if(page == null)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, $"Page not found : /sources/{sourceUrlSlug}");
|
||||
}
|
||||
|
||||
string sourceName = page.Title;
|
||||
switch(sourceUrlSlug)
|
||||
{
|
||||
case "wikidorj":
|
||||
sourceName = "ویکیدرج";
|
||||
break;
|
||||
case "frankfurt":
|
||||
sourceName = "دانشگاه فرانکفورت";
|
||||
break;
|
||||
case "tariqmo":
|
||||
sourceName = "طریق التحقیق دکتر مؤذنی";
|
||||
break;
|
||||
case "tebyan":
|
||||
sourceName = "تبیان";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
List<int> catIdList = new List<int>
|
||||
{
|
||||
catId
|
||||
};
|
||||
await _populateCategoryChildren(context, catId, catIdList);
|
||||
int poemCount = 0;
|
||||
int progress = 0;
|
||||
foreach (int catId in catIdList)
|
||||
{
|
||||
var poems = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == catId).ToListAsync();
|
||||
poemCount += poems.Count;
|
||||
foreach (var poem in poems)
|
||||
{
|
||||
poem.SourceName = sourceName;
|
||||
poem.SourceUrlSlug = sourceUrlSlug;
|
||||
context.Update(poem);
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, progress, $"{progress} از {poemCount}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user