adding poem plaintext + html text

This commit is contained in:
Hamid Reza Mohammadi 2020-12-03 18:48:24 +03:30
parent d274326a97
commit 22fbf23a90
10 changed files with 1853 additions and 2 deletions

View File

@ -30,6 +30,24 @@ namespace RMuseum.Controllers
return BadRequest(res.ExceptionString);
}
/// <summary>
/// updates poems text and html
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("updatetext")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.ImportOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public IActionResult UpdatePoemsText()
{
RServiceResult<bool> res =
_ganjoorService.UpdatePoemsText();
if (res.Result)
return Ok();
return BadRequest(res.ExceptionString);
}
/// <summary>
/// Ganjoor Service
/// </summary>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace RMuseum.Migrations
{
public partial class GanjoorPoemTextAndHtml : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "HtmlText",
table: "GanjoorPoems",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "PlainText",
table: "GanjoorPoems",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "HtmlText",
table: "GanjoorPoems");
migrationBuilder.DropColumn(
name: "PlainText",
table: "GanjoorPoems");
}
}
}

View File

@ -381,6 +381,12 @@ namespace RMuseum.Migrations
b.Property<string>("FullUrl")
.HasColumnType("nvarchar(450)");
b.Property<string>("HtmlText")
.HasColumnType("nvarchar(max)");
b.Property<string>("PlainText")
.HasColumnType("nvarchar(max)");
b.Property<string>("Title")
.HasColumnType("nvarchar(max)");

View File

@ -43,5 +43,15 @@ namespace RMuseum.Models.Ganjoor
/// sample: /hafez/ghazal/sh1
/// </summary>
public string FullUrl { get; set; }
/// <summary>
/// verses text
/// </summary>
public string PlainText { get; set; }
/// <summary>
/// verses text as html (ganjoor.net format)
/// </summary>
public string HtmlText { get; set; }
}
}

View File

@ -87,5 +87,15 @@ namespace RMuseum.Models.GanjoorAudio.ViewModels
/// </summary>
public string XmlText { get; set; }
/// <summary>
/// Poem Plain Text
/// </summary>
public string PlainText { get; set; }
/// <summary>
/// Poem Html Text
/// </summary>
public string HtmlText { get; set; }
}
}

View File

@ -621,6 +621,12 @@
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.UpdatePoemsText">
<summary>
updates poems text and html
</summary>
<returns></returns>
</member>
<member name="F:RMuseum.Controllers.GanjoorController._ganjoorService">
<summary>
Ganjoor Service
@ -2239,6 +2245,16 @@
Xml Url
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.PublicRecitationViewModel.PlainText">
<summary>
Poem Plain Text
</summary>
</member>
<member name="P:RMuseum.Models.GanjoorAudio.ViewModels.PublicRecitationViewModel.HtmlText">
<summary>
Poem Html Text
</summary>
</member>
<member name="T:RMuseum.Models.GanjoorAudio.ViewModels.PoemNarrationModerationResult">
<summary>
Moderation Result
@ -3215,6 +3231,16 @@
sample: /hafez/ghazal/sh1
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorPoem.PlainText">
<summary>
verses text
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.GanjoorPoem.HtmlText">
<summary>
verses text as html (ganjoor.net format)
</summary>
</member>
<member name="T:RMuseum.Models.Ganjoor.GanjoorPoet">
<summary>
Ganjoor Poet
@ -4325,6 +4351,12 @@
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.UpdatePoemsText">
<summary>
updates poems text
</summary>
<returns></returns>
</member>
<member name="T:RMuseum.Services.Implementation.ArtifactService">
<summary>
IArtifactService implementation
@ -5030,6 +5062,12 @@
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.UpdatePoemsText">
<summary>
updates poems text
</summary>
<returns></returns>
</member>
<member name="F:RMuseum.Services.Implementation.GanjoorService._context">
<summary>
Database Contetxt
@ -5040,12 +5078,18 @@
Configuration
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.#ctor(RMuseum.DbContext.RMuseumDbContext,Microsoft.Extensions.Configuration.IConfiguration)">
<member name="F:RMuseum.Services.Implementation.GanjoorService._backgroundTaskQueue">
<summary>
Background Task Queue Instance
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.#ctor(RMuseum.DbContext.RMuseumDbContext,Microsoft.Extensions.Configuration.IConfiguration,RMuseum.Services.IBackgroundTaskQueue)">
<summary>
constructor
</summary>
<param name="context"></param>
<param name="configuration"></param>
<param name="backgroundTaskQueue"></param>
</member>
<member name="T:RMuseum.Services.Implementation.ImportedFromDesktopGanjoor.GPersianTextSync">
<summary>

View File

@ -13,5 +13,11 @@ namespace RMuseum.Services
/// </summary>
/// <returns></returns>
Task<RServiceResult<bool>> ImportLocalSQLiteDb();
/// <summary>
/// updates poems text
/// </summary>
/// <returns></returns>
RServiceResult<bool> UpdatePoemsText();
}
}

View File

@ -137,6 +137,106 @@ namespace RMuseum.Services.Implementation
return slug;
}
/// <summary>
/// updates poems text
/// </summary>
/// <returns></returns>
public RServiceResult<bool> UpdatePoemsText()
{
try
{
_backgroundTaskQueue.QueueBackgroundWorkItem
(
async token =>
{
using (RMuseumDbContext context = new RMuseumDbContext(Configuration)) //this is long running job, so _context might be already been freed/collected by GC
{
var poems = await context.GanjoorPoems.Where(p => p.PlainText == null).ToListAsync();
foreach (GanjoorPoem poem in poems)
{
var verses = await context.GanjoorVerses.Where(v => v.PoemId == poem.Id).OrderBy(v => v.VOrder).ToListAsync();
string plainText = "";
string htmlText = "";
for (int vIndex = 0; vIndex < verses.Count; vIndex++)
{
GanjoorVerse v = verses[vIndex];
if (string.IsNullOrEmpty(plainText))
plainText = v.Text;
else
{
plainText += $" {v.Text}";
}
switch (v.VersePosition)
{
case VersePosition.CenteredVerse1:
if (((vIndex + 1) < verses.Count) && (verses[vIndex + 1].VersePosition == VersePosition.CenteredVerse2))
{
htmlText += $"<div class=\"b2\"><p>{v.Text.Replace("ـ", "").Trim()}</p>{Environment.NewLine}"; //div is not closed
}
else
{
htmlText += $"<div class=\"b2\"><p>{v.Text.Replace("ـ", "").Trim()}</p></div>{Environment.NewLine}";
}
break;
case VersePosition.CenteredVerse2:
htmlText += $"<p>{v.Text.Replace("ـ", "").Trim()}</p></div>{Environment.NewLine}";
break;
case VersePosition.Right:
htmlText += $"<div class=\"b\"><div class=\"m1\"><p>{v.Text.Replace("ـ", "").Trim()}</p></div>{Environment.NewLine}";
break;
case VersePosition.Left:
htmlText += $"<div class=\"m2\"><p>{v.Text.Replace("ـ", "").Trim()}</p></div></div>{Environment.NewLine}";
break;
case VersePosition.Paragraph:
case VersePosition.Single:
{
string[] lines = v.Text.Replace("ـ", "").Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
if (lines.Length != 0)
{
if (v.Text.Replace("ـ", "").Length / lines.Length < 150)
{
htmlText += $"<div class=\"n\"><p>{v.Text.Replace("ـ", "").Replace("\r\n", " ")}</p></div>{Environment.NewLine}";
}
else
{
foreach (string line in lines)
htmlText += $"<div class=\"n\"><p>{line}</p></div>{Environment.NewLine}";
}
}
}
break;
}
poem.PlainText = plainText;
poem.HtmlText = htmlText;
context.Update(poem);
await context.SaveChangesAsync();
}
}
}
});
return new RServiceResult<bool>(true);
}
catch(Exception exp)
{
return new RServiceResult<bool>(false, exp.ToString());
}
}
/// <summary>
/// Database Contetxt
/// </summary>
@ -147,14 +247,21 @@ namespace RMuseum.Services.Implementation
/// </summary>
protected IConfiguration Configuration { get; }
/// <summary>
/// Background Task Queue Instance
/// </summary>
protected readonly IBackgroundTaskQueue _backgroundTaskQueue;
/// <summary>
/// constructor
/// </summary>
/// <param name="context"></param>
/// <param name="configuration"></param>
public GanjoorService(RMuseumDbContext context, IConfiguration configuration)
/// <param name="backgroundTaskQueue"></param>
public GanjoorService(RMuseumDbContext context, IConfiguration configuration, IBackgroundTaskQueue backgroundTaskQueue)
{
_context = context;
_backgroundTaskQueue = backgroundTaskQueue;
Configuration = configuration;
}
}

View File

@ -98,6 +98,8 @@ namespace RMuseum.Services.Implementationa
audio.AudioTitle.Contains(searchTerm)
||
poem.FullTitle.Contains(searchTerm)
||
poem.PlainText.Contains(searchTerm)
))
)
orderby audio.ReviewDate descending
@ -119,6 +121,8 @@ namespace RMuseum.Services.Implementationa
FileLastUpdated = audio.FileLastUpdated,
Mp3Url = $"https://ganjgah.ir/api/audio/file/{audio.Id}.mp3",
XmlText = $"https://ganjgah.ir/api/audio/xml/{audio.Id}",
PlainText = poem.PlainText,
HtmlText = poem.HtmlText
};
(PaginationMetadata PagingMeta, PublicRecitationViewModel[] Items) paginatedResult =