Skip to content

Commit

Permalink
Changed signature of IMDIPackage.CreateIMDIPackage to take a Cancella…
Browse files Browse the repository at this point in the history
…tionToken parameter and return Task<bool>.
  • Loading branch information
tombogle committed Aug 14, 2024
1 parent 7f5b100 commit 995b464
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [SIL.Core] Added optional parameter to OlacSystem.GetRoles to allow caller to provide its own XML with role definitions.
- [SIL.Windows.Forms] Split License into a base class called License and a derived LicenseWithLogo, so that License could be in SIL.Core.
- [SIL.Archiving] Changed IArchivingSession.Files (and Session.Files) into an IReadonlyList.
- [SIL.Archiving] Changed signature of IMDIPackage.CreateIMDIPackage to take a CancellationToken parameter and return Task<bool>.

### Fixed
- [SIL.Archiving] Fixed typo in RampArchivingDlgViewModel for Ethnomusicology performance collection.
Expand Down
2 changes: 1 addition & 1 deletion SIL.Archiving/IMDI/IMDIArchivingDlgViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public override async Task<string> CreatePackage(CancellationToken cancellationT

// write the xml files
if (success)
success = _imdiData.CreateIMDIPackage(); // REVIEW: Should this also be awaited?
success = await _imdiData.CreateIMDIPackage(cancellationToken);

// copy the content files
if (success && !MetadataOnly)
Expand Down
24 changes: 15 additions & 9 deletions SIL.Archiving/IMDI/IMDIPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using SIL.Archiving.Generic;
using SIL.Archiving.IMDI.Lists;
using SIL.Archiving.IMDI.Schema;
Expand Down Expand Up @@ -71,22 +73,24 @@ public string PackagePath
// Test_Corpus\Test_Session\Files*.* (session files)
// Test_Corpus\Contributors\Files*.* (contributor/actor files)

/// <summary>Creates the corpus directory structure, meta data files, and copies content files</summary>
/// <summary>Creates the corpus directory structure, meta data files, and copies content
/// files, checking for cancellation before each IO operation.</summary>
/// <returns></returns>
public bool CreateIMDIPackage()
public Task<bool> CreateIMDIPackage(CancellationToken cancellationToken)
{
if (!IsValid)
return false;
return Task.FromResult(false);

_creationStarted = true;

// list of session files for the corpus
List<string> sessionFiles = new List<string>();

// create the session directories
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var session in Sessions)
{
cancellationToken.ThrowIfCancellationRequested();

var sessionImdi = new MetaTranscript {
Items = new object[] { session },
Type = MetatranscriptValueType.SESSION
Expand All @@ -97,7 +101,7 @@ public bool CreateIMDIPackage()
if (!_corpus)
{
MainExportFile = Path.Combine(PackagePath, sessionFiles[0]);
return true;
return Task.FromResult(true);
}

var corpus = (Corpus) BaseMajorObject;
Expand All @@ -109,13 +113,17 @@ public bool CreateIMDIPackage()
foreach (var fileName in sessionFiles)
corpus.CorpusLink.Add(new CorpusLinkType { Value = fileName.Replace("\\", "/"), Name = string.Empty });

cancellationToken.ThrowIfCancellationRequested();

// create the catalogue
corpus.CatalogueLink = CreateCorpusCatalogue();

cancellationToken.ThrowIfCancellationRequested();

// Create the corpus imdi file
MainExportFile = BaseImdiFile.WriteImdiFile(PackagePath, Name);

return true;
return Task.FromResult(true);
}

private string CreateCorpusCatalogue()
Expand Down Expand Up @@ -218,10 +226,8 @@ public void AddDescription(string sessionId, LanguageString description)
// prevent duplicate description
if (_corpus)
{
foreach (var session in Sessions.Where(sess => sess.Name == sessionId))
{
foreach (var session in Sessions.Where(s => s.Name == sessionId))
session.AddDescription(description);
}
}
else
{
Expand Down

0 comments on commit 995b464

Please sign in to comment.