#3 importing Ganjoor MySql data for audio narrations is functional
This commit is contained in:
parent
a0ae50bf0b
commit
104a845fa2
61
RMuseum/Controllers/AudioNarrationController.cs
Normal file
61
RMuseum/Controllers/AudioNarrationController.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using RMuseum.Models.Auth.Memory;
|
||||||
|
using RMuseum.Services;
|
||||||
|
using RSecurityBackend.Models.Generic;
|
||||||
|
using RSecurityBackend.Services;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace RMuseum.Controllers
|
||||||
|
{
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("api/audio")]
|
||||||
|
public class AudioNarrationController : Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// imports data from ganjoor MySql database
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
[Route("mysqlonetimeimport")]
|
||||||
|
[Authorize(Policy = RMuseumSecurableItem.AudioNarrationEntityShortName + ":" + RMuseumSecurableItem.ImportOperationShortName)]
|
||||||
|
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||||
|
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||||
|
public async Task<IActionResult> MysqlonetimeImport()
|
||||||
|
{
|
||||||
|
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||||
|
RServiceResult<bool> res =
|
||||||
|
await _audioService.OneTimeImport(loggedOnUserId);
|
||||||
|
if (res.Result)
|
||||||
|
return Ok();
|
||||||
|
return BadRequest(res.ExceptionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="audioService">
|
||||||
|
/// </param>
|
||||||
|
/// <param name="userPermissionChecker"></param>
|
||||||
|
public AudioNarrationController(IAudioNarrationService audioService, IUserPermissionChecker userPermissionChecker)
|
||||||
|
{
|
||||||
|
_audioService = audioService;
|
||||||
|
_userPermissionChecker = userPermissionChecker;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Artifact Service
|
||||||
|
/// </summary>
|
||||||
|
protected readonly IAudioNarrationService _audioService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// IUserPermissionChecker instance
|
||||||
|
/// </summary>
|
||||||
|
protected IUserPermissionChecker _userPermissionChecker;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -620,6 +620,30 @@
|
|||||||
Captcha service
|
Captcha service
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:RMuseum.Controllers.AudioNarrationController.MysqlonetimeImport">
|
||||||
|
<summary>
|
||||||
|
imports data from ganjoor MySql database
|
||||||
|
</summary>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:RMuseum.Controllers.AudioNarrationController.#ctor(RMuseum.Services.IAudioNarrationService,RSecurityBackend.Services.IUserPermissionChecker)">
|
||||||
|
<summary>
|
||||||
|
constructor
|
||||||
|
</summary>
|
||||||
|
<param name="audioService">
|
||||||
|
</param>
|
||||||
|
<param name="userPermissionChecker"></param>
|
||||||
|
</member>
|
||||||
|
<member name="F:RMuseum.Controllers.AudioNarrationController._audioService">
|
||||||
|
<summary>
|
||||||
|
Artifact Service
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="F:RMuseum.Controllers.AudioNarrationController._userPermissionChecker">
|
||||||
|
<summary>
|
||||||
|
IUserPermissionChecker instance
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Controllers.AuditLogController">
|
<member name="T:RMuseum.Controllers.AuditLogController">
|
||||||
<summary>
|
<summary>
|
||||||
Audit Log Controller Base
|
Audit Log Controller Base
|
||||||
@ -3000,6 +3024,18 @@
|
|||||||
<param name="checkJobs"></param>
|
<param name="checkJobs"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:RMuseum.Services.IAudioNarrationService">
|
||||||
|
<summary>
|
||||||
|
Audio Narration Service
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:RMuseum.Services.IAudioNarrationService.OneTimeImport(System.Guid)">
|
||||||
|
<summary>
|
||||||
|
imports data from ganjoor MySql database
|
||||||
|
</summary>
|
||||||
|
<param name="OwnrRAppUserId">User Id which becomes owner of imported data</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Services.Implementation.ArtifactService">
|
<member name="T:RMuseum.Services.Implementation.ArtifactService">
|
||||||
<summary>
|
<summary>
|
||||||
IArtifactService implementation
|
IArtifactService implementation
|
||||||
@ -3708,6 +3744,34 @@
|
|||||||
<param name="backgroundTaskQueue"></param>
|
<param name="backgroundTaskQueue"></param>
|
||||||
<param name="userService"></param>
|
<param name="userService"></param>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:RMuseum.Services.Implementation.AudioNarrationService">
|
||||||
|
<summary>
|
||||||
|
Audio Narration Service Implementation
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.OneTimeImport(System.Guid)">
|
||||||
|
<summary>
|
||||||
|
imports data from ganjoor MySql database
|
||||||
|
</summary>
|
||||||
|
<param name="OwnrRAppUserId">User Id which becomes owner of imported data</param>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Services.Implementation.AudioNarrationService.Configuration">
|
||||||
|
<summary>
|
||||||
|
Configuration
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="F:RMuseum.Services.Implementation.AudioNarrationService._context">
|
||||||
|
<summary>
|
||||||
|
Database Contetxt
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.#ctor(RMuseum.DbContext.RMuseumDbContext,Microsoft.Extensions.Configuration.IConfiguration)">
|
||||||
|
<summary>
|
||||||
|
constructor
|
||||||
|
</summary>
|
||||||
|
<param name="context"></param>
|
||||||
|
<param name="configuration"></param>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Services.Implementation.BLTileMixer">
|
<member name="T:RMuseum.Services.Implementation.BLTileMixer">
|
||||||
<summary>
|
<summary>
|
||||||
British Library Tile Downloader And Mixer
|
British Library Tile Downloader And Mixer
|
||||||
|
|||||||
19
RMuseum/Services/IAudioNarrationService.cs
Normal file
19
RMuseum/Services/IAudioNarrationService.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using RSecurityBackend.Models.Generic;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace RMuseum.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Audio Narration Service
|
||||||
|
/// </summary>
|
||||||
|
public interface IAudioNarrationService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// imports data from ganjoor MySql database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="OwnrRAppUserId">User Id which becomes owner of imported data</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<RServiceResult<bool>> OneTimeImport(Guid OwnrRAppUserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
118
RMuseum/Services/Implementation/AudioNarrationService.cs
Normal file
118
RMuseum/Services/Implementation/AudioNarrationService.cs
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
using RMuseum.DbContext;
|
||||||
|
using RMuseum.Models.GanjoorAudio;
|
||||||
|
using RSecurityBackend.Models.Generic;
|
||||||
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Policy;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace RMuseum.Services.Implementation
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Audio Narration Service Implementation
|
||||||
|
/// </summary>
|
||||||
|
public class AudioNarrationService : IAudioNarrationService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// imports data from ganjoor MySql database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="OwnrRAppUserId">User Id which becomes owner of imported data</param>
|
||||||
|
public async Task<RServiceResult<bool>> OneTimeImport(Guid OwnrRAppUserId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PoemNarration sampleCheck = await _context.AudioFiles.FirstOrDefaultAsync();
|
||||||
|
if(sampleCheck != null)
|
||||||
|
{
|
||||||
|
return new RServiceResult<bool>(false, "OneTimeImport is a one time operation and cannot be called multiple times.");
|
||||||
|
}
|
||||||
|
using (MySqlConnection connection = new MySqlConnection
|
||||||
|
(
|
||||||
|
$"server={Configuration.GetSection("AudioMySqlServer")["Server"]};uid={Configuration.GetSection("AudioMySqlServer")["Username"]};pwd={Configuration.GetSection("AudioMySqlServer")["Password"]};database={Configuration.GetSection("AudioMySqlServer")["Database"]};charset=utf8"
|
||||||
|
))
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
using(MySqlDataAdapter src = new MySqlDataAdapter(
|
||||||
|
"SELECT audio_ID, audio_post_ID, audio_order, audio_xml, audio_ogg, audio_mp3, " +
|
||||||
|
"audio_title, audio_artist, audio_artist_url, audio_src, audio_src_url, audio_guid, " +
|
||||||
|
"audio_fchecksum, audio_mp3bsize, audio_oggbsize, audio_date " +
|
||||||
|
"FROM adab.ganja_gaudio ORDER BY audio_ID",
|
||||||
|
connection
|
||||||
|
))
|
||||||
|
{
|
||||||
|
using(DataTable srcData = new DataTable())
|
||||||
|
{
|
||||||
|
await src.FillAsync(srcData);
|
||||||
|
|
||||||
|
int audioSyncStatus = (int)AudioSyncStatus.SynchronizedOrRejected;
|
||||||
|
foreach (DataRow row in srcData.Rows)
|
||||||
|
{
|
||||||
|
PoemNarration newRecord = new PoemNarration()
|
||||||
|
{
|
||||||
|
OwnerId = OwnrRAppUserId,
|
||||||
|
GanjoorAudioId = int.Parse(row["audio_ID"].ToString()),
|
||||||
|
GanjoorPostId = (int)row["audio_post_ID"],
|
||||||
|
AudioOrder = (int)row["audio_order"],
|
||||||
|
AudioTitle = row["audio_title"].ToString(),
|
||||||
|
AudioArtist = row["audio_artist"].ToString(),
|
||||||
|
AudioArtistUrl = row["audio_artist_url"].ToString(),
|
||||||
|
AudioSrc = row["audio_src"].ToString(),
|
||||||
|
AudioSrcUrl = row["audio_src_url"].ToString(),
|
||||||
|
LegacyAudioGuid = new Guid(row["audio_guid"].ToString()),
|
||||||
|
Mp3FileCheckSum = row["audio_fchecksum"].ToString(),
|
||||||
|
Mp3SizeInBytes = (int)row["audio_mp3bsize"],
|
||||||
|
OggSizeInBytes = (int)row["audio_oggbsize"],
|
||||||
|
UploadDate = (DateTime)row["audio_date"],
|
||||||
|
AudioSyncStatus = audioSyncStatus,
|
||||||
|
ReviewStatus = AudioReviewStatus.Approved
|
||||||
|
};
|
||||||
|
newRecord.ReviewDate = newRecord.UploadDate;
|
||||||
|
string audio_xml = row["audio_xml"].ToString();
|
||||||
|
//sample audio_xml value: /i/a/x/11876-Simorgh.xml
|
||||||
|
audio_xml = audio_xml.Substring("/i/".Length); // /i/a/x/11876-Simorgh.xml -> a/x/11876-Simorgh.xml
|
||||||
|
newRecord.SoundFilesFolder = audio_xml.Substring(0, audio_xml.IndexOf('/')); //(a)
|
||||||
|
newRecord.FileNameWithoutExtension = Path.GetFileNameWithoutExtension(audio_xml.Substring(audio_xml.LastIndexOf('/') + 1)); //(11876-Simorgh)
|
||||||
|
|
||||||
|
_context.AudioFiles.Add(newRecord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new RServiceResult<bool>(true);
|
||||||
|
}
|
||||||
|
catch(Exception exp)
|
||||||
|
{
|
||||||
|
return new RServiceResult<bool>(false, exp.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configuration
|
||||||
|
/// </summary>
|
||||||
|
protected IConfiguration Configuration { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Database Contetxt
|
||||||
|
/// </summary>
|
||||||
|
protected readonly RMuseumDbContext _context;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <param name="configuration"></param>
|
||||||
|
public AudioNarrationService(RMuseumDbContext context, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -248,6 +248,9 @@ namespace RMuseum
|
|||||||
//artifact service
|
//artifact service
|
||||||
services.AddTransient<IArtifactService, ArtifactService>();
|
services.AddTransient<IArtifactService, ArtifactService>();
|
||||||
|
|
||||||
|
//audio service
|
||||||
|
services.AddTransient<IAudioNarrationService, AudioNarrationService>();
|
||||||
|
|
||||||
|
|
||||||
services.AddHostedService<QueuedHostedService>();
|
services.AddHostedService<QueuedHostedService>();
|
||||||
services.AddSingleton<IBackgroundTaskQueue, BackgroundTaskQueue>();
|
services.AddSingleton<IBackgroundTaskQueue, BackgroundTaskQueue>();
|
||||||
|
|||||||
@ -33,6 +33,11 @@
|
|||||||
"Password": "password",
|
"Password": "password",
|
||||||
"From": "test@gmail.com"
|
"From": "test@gmail.com"
|
||||||
},
|
},
|
||||||
|
"AudioMySqlServer": {
|
||||||
|
"Server": "localhost",
|
||||||
|
"Username": "root",
|
||||||
|
"Password": "",
|
||||||
|
"Database": "adab"
|
||||||
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user