From 2fa2777acf154b5a24394887e872b3e92896a0be Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Wed, 4 Nov 2020 11:39:48 +0330 Subject: [PATCH] #3 having a more complete set of data for mysql imported records --- .../Implementation/AudioNarrationService.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/RMuseum/Services/Implementation/AudioNarrationService.cs b/RMuseum/Services/Implementation/AudioNarrationService.cs index 926fcf8b..99c0ee4d 100644 --- a/RMuseum/Services/Implementation/AudioNarrationService.cs +++ b/RMuseum/Services/Implementation/AudioNarrationService.cs @@ -11,8 +11,6 @@ using RMuseum.Models.GanjoorAudio; using RMuseum.Models.GanjoorAudio.ViewModels; using RMuseum.Models.UploadSession; using RMuseum.Models.UploadSession.ViewModels; -using RSecurityBackend.Models.Auth.Db; -using RSecurityBackend.Models.Auth.ViewModels; using RSecurityBackend.Models.Generic; using RSecurityBackend.Services.Implementation; using System; @@ -158,6 +156,9 @@ namespace RMuseum.Services.Implementation await src.FillAsync(srcData); int audioSyncStatus = (int)AudioSyncStatus.SynchronizedOrRejected; + + + foreach (DataRow row in srcData.Rows) { PoemNarration newRecord = new PoemNarration() @@ -184,12 +185,20 @@ namespace RMuseum.Services.Implementation //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) + string targetForAudioFile = Path.Combine(Configuration.GetSection("AudioUploadService")["LocalAudioRepositoryPath"], newRecord.SoundFilesFolder); + string targetForXmlAudioFile = Path.Combine(targetForAudioFile, "x"); + newRecord.FileNameWithoutExtension = Path.GetFileNameWithoutExtension(audio_xml.Substring(audio_xml.LastIndexOf('/') + 1)); //(11876-Simorgh) + newRecord.LocalMp3FilePath = Path.Combine(targetForAudioFile, $"{newRecord.FileNameWithoutExtension}.mp3"); + newRecord.LocalXmlFilePath = Path.Combine(targetForXmlAudioFile, $"{newRecord.FileNameWithoutExtension}.xml"); _context.AudioFiles.Add(newRecord); + await _context.SaveChangesAsync(); //this logically should be outside this loop, + //but it messes with the order of records so I decided + //to wait a little longer and have an ordered set of records } } - await _context.SaveChangesAsync(); + } } return new RServiceResult(true);