Skip to content

Commit

Permalink
Got archiving test app to work correctly for both RAMP and IMDI archi…
Browse files Browse the repository at this point in the history
…ves.

Improved documentation and did code cleanup for some of the IMDI stuff. Closed some loopholes to make it easier for clients to create valid packages
  • Loading branch information
tombogle committed Aug 5, 2024
1 parent defcf71 commit 445b557
Show file tree
Hide file tree
Showing 15 changed files with 693 additions and 609 deletions.
1 change: 1 addition & 0 deletions ArchivingTestApp/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 59 additions & 4 deletions ArchivingTestApp/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using L10NSharp;
using SIL.Archiving;
using SIL.Archiving.Generic;
using SIL.Archiving.IMDI;
using SIL.IO;
using SIL.Windows.Forms.Archiving;
using SIL.Windows.Forms.Archiving.IMDI;
using static System.IO.Path;
using static System.String;

Expand All @@ -9,16 +13,23 @@ namespace ArchivingTestApp
public partial class MainForm : Form
{
private const string kAppName = "Archiving Test App";

private string GetTitle()
{
var title = m_txtTitle.Text;
if (title.Length == 0)
title = "Arbitrary title";
return title;
}

public MainForm()
{
InitializeComponent();
}

private void m_btnRamp_Click(object sender, EventArgs e)
{
var title = m_txtTitle.Text;
if (title.Length == 0)
title = "Arbitrary title";
var title = GetTitle();
var model = new RampArchivingDlgViewModel(kAppName, title,
title.ToLatinOnly("~", "_", ""), SetFilesToArchive, GetFileDescription);
using (var rampArchiveDlg = new ArchivingDlg(model, LocalizationManager.GetString(
Expand All @@ -28,6 +39,50 @@ private void m_btnRamp_Click(object sender, EventArgs e)
}
}

private void m_btnIMDI_Click(object sender, EventArgs e)
{
var title = GetTitle();
TempFile.NamePrefix = kAppName.Replace(" ", "_");
var folder = new TempFile().Path;
RobustFile.Delete(folder);
Directory.CreateDirectory(folder);
var model = new IMDIArchivingDlgViewModel(kAppName, title,
title.ToLatinOnly("~", "_", ""), false, SetFilesToArchive, folder);

model.ArchivingPackage.AccessCode = "internal";
model.ArchivingPackage.Access.DateAvailable = "3 March 2029";
model.ArchivingPackage.Access.Owner = "Fred";
model.ArchivingPackage.Publisher = "SIL Elbonia";
model.ArchivingPackage.Location = new ArchivingLocation
{
Address = "1234 Shoulder St.; Armstrong",
Country = "Elbonia"
};
model.ArchivingPackage.Author = "Test Dude";
model.ArchivingPackage.Owner = "Mike";

foreach (ListViewGroup group in m_listFiles.Groups)
{
var session = model.AddSession(group.Header);
foreach (var file in (from ListViewItem item in @group.Items select item.Text))
{
session.AddFile(new ArchivingFile(file));
session.AddFileAccess(file, (ArchivingPackage)model.ArchivingPackage);
}

session.Genre = "Dance";
session.SubGenre = "Entertainment";
session.PlanningType = "Spontaneous";
}


using (var imdiArchiveDlg = new IMDIArchivingDlg(model, LocalizationManager.GetString(
"ArchivingTestApp.MainForm.AdditionalImdiArchiveProcessInfo", "This is a test of IMDI archival.")))
{
imdiArchiveDlg.ShowDialog(this);
}
}

private void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken cancellationToken)
{
foreach (ListViewGroup group in m_listFiles.Groups)
Expand All @@ -41,7 +96,7 @@ private void SetFilesToArchive(ArchivingDlgViewModel model, CancellationToken ca

private static string GetFileDescription(string key, string filename)
{
return $"{key} - {filename}";
return filename.Replace("\\", "_");
}

private void HandleAddFilesClick(object sender, EventArgs e)
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [SIL.Windows.Forms.Archiving] Added (protected) override of method PackageCreationComplete to IMDIArchivingDlg.
- [SIL.Windows.Forms.Archiving] Added (public) override of method GetMessage to IMDIArchivingDlg.
- [SIL.Windows.Forms.Archiving] Added public extensions class LinkLabelExtensions with some methods that were formerly in Extensions class (now in SIL.Archiving).
- [SIL.Archiving] Added public property isValid to IMDIPackage.
- [SIL.Archiving] Added public event InitializationFailed to IMDIArchivingDlgViewModel.

### Changed

Expand All @@ -61,6 +63,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [SIL.Windows.Forms] Split ClearShare code, moving non-Winforms portions to SIL.Core (SIL.Core.ClearShare namespace)
- [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.

### Fixed
- [SIL.Archiving] Fixed typo in RampArchivingDlgViewModel for Ethnomusicology performance collection.
Expand Down
5 changes: 5 additions & 0 deletions Palaso.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=adaptor/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=analytics/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Annotatable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=anonymised/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Anonymize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Anonymized/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Arbil/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Argb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=autosize/@EntryIndexedValue">True</s:Boolean>
Expand Down Expand Up @@ -77,11 +80,13 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=localised/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=macrolanguage/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=malware/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Metatranscript/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mets/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=migrator/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=modally/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=OLAC/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=optimizable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Organisation/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Palaso/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Paratext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=parsable/@EntryIndexedValue">True</s:Boolean>
Expand Down
11 changes: 9 additions & 2 deletions SIL.Archiving/ArchivingDlgViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public enum StringId
PreArchivingStatus,
SearchingForArchiveUploadingProgram,
ArchiveUploadingProgramNotFound,
IMDIPackageInvalid,
ErrorStartingArchivalProgram,
PreparingFiles,
SavingFilesInPackage,
Expand Down Expand Up @@ -597,8 +598,14 @@ protected string GetFileExcludedMsg(string file) =>
/// ------------------------------------------------------------------------------------
public static bool IsMono => (Type.GetType("Mono.Runtime") != null);

/// <summary></summary>
/// <param name="sessionId"></param>
/// ------------------------------------------------------------------------------------
/// <summary>Adds a "session" or "resource bundle". This usually corresponds to a
/// meaningful unit of analysis, e.g., to a piece of data having the same overall
/// content, the same set of actors, and the same location and time (e.g., one
/// elicitation session on topic X, or one folktale, or one ‘matching game’, or one
/// conversation between several speakers).</summary>
/// <param name="sessionId">Unique Identifier for this session.</param>
/// ------------------------------------------------------------------------------------
[PublicAPI]
public abstract IArchivingSession AddSession(string sessionId);

Expand Down
1 change: 0 additions & 1 deletion SIL.Archiving/Generic/ArchivingPackage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using SIL.Archiving.Generic.AccessProtocol;

namespace SIL.Archiving.Generic
Expand Down
22 changes: 18 additions & 4 deletions SIL.Archiving/Generic/ArchivingSession.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;

namespace SIL.Archiving.Generic
{
Expand All @@ -10,10 +11,11 @@ public interface IArchivingSession : IArchivingGenericObject
void AddFile(ArchivingFile file);

/// <summary></summary>
[PublicAPI]
void AddFileAccess(string fullFileName, ArchivingPackage package);

/// <summary></summary>
List<string> Files { get; }
/// <summary>The paths of all resource files in the session.</summary>
IReadOnlyList<string> Files { get; }

/// <summary>Set session date with DateTime object</summary>
void SetDate(DateTime date);
Expand All @@ -25,36 +27,47 @@ public interface IArchivingSession : IArchivingGenericObject
void SetDate(int year);

/// <summary></summary>
[PublicAPI]
void AddContentLanguage(ArchivingLanguage language, LanguageString description);

/// <summary></summary>
[PublicAPI]
void AddActor(ArchivingActor actor);

/// <summary></summary>
[PublicAPI]
void AddGroupKeyValuePair(string key, string value);

/// <summary></summary>
[PublicAPI]
void AddContentKeyValuePair(string key, string value);

/// <summary></summary>
[PublicAPI]
void AddFileKeyValuePair(string fullFileName, string key, string value);

/// <summary></summary>
[PublicAPI]
void AddContentDescription(LanguageString description);

/// <summary></summary>
[PublicAPI]
void AddActorDescription(ArchivingActor actor, LanguageString description);

/// <summary></summary>
[PublicAPI]
void AddFileDescription(string fullFileName, LanguageString description);

/// <summary></summary>
[PublicAPI]
void AddActorContact(ArchivingActor actor, ArchivingContact contact);

/// <summary></summary>
[PublicAPI]
void AddMediaFileTimes(string fullFileName, string start, string stop);

/// <summary></summary>
[PublicAPI]
void AddProject(ArchivingPackage package);

/// <summary></summary>
Expand All @@ -66,10 +79,11 @@ public interface IArchivingSession : IArchivingGenericObject
/// <summary></summary>
string Interactivity { get; set; }

/// <summary></summary>
/// <summary>Indicates in how far the researcher was involved in the linguistic event</summary>
[PublicAPI]
string Involvement { get; set; }

/// <summary></summary>
/// <summary>Degree of planning of the event</summary>
string PlanningType { get; set; }

/// <summary></summary>
Expand Down
10 changes: 8 additions & 2 deletions SIL.Archiving/IMDI/IMDIArchivingDlgViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class IMDIArchivingDlgViewModel : ArchivingDlgViewModel, ISupportMetadata
private readonly string _configFileName = Path.Combine(ArchivingFileSystem.SilCommonArchivingDataFolder, "IMDIProgram.config");
private string _outputFolder;

public event EventHandler InitializationFailed;

#region Properties

public override Standard ArchiveType => Standard.IMDI;
Expand Down Expand Up @@ -92,8 +94,12 @@ public IMDIArchivingDlgViewModel(string appName, string title, string id, bool c
/// ------------------------------------------------------------------------------------
protected override bool DoArchiveSpecificInitialization()
{
// no-op
return true;
if (_imdiData.IsValid)
return true;

DisplayMessage(Progress.GetMessage(StringId.IMDIPackageInvalid), MessageType.Error);
InitializationFailed?.Invoke(this, EventArgs.Empty);
return false;
}

/// ------------------------------------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion SIL.Archiving/IMDI/IMDIPackage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -53,6 +52,12 @@ public string PackagePath
_packagePath = value;
}
}

/// <summary>Generally an IMDI package should have at least one session. (This is not
/// strictly required for a corpus package, though it would be strange to want to
/// archive a corpus with no sessions.)</summary>
public bool IsValid => _corpus || Sessions.Any();

#endregion

// **** Corpus Layout ****
Expand All @@ -70,6 +75,9 @@ public string PackagePath
/// <returns></returns>
public bool CreateIMDIPackage()
{
if (!IsValid)
return false;

_creationStarted = true;

// list of session files for the corpus
Expand Down
5 changes: 2 additions & 3 deletions SIL.Archiving/IMDI/Schema/IMDIExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.Archiving.Generic;
using SIL.Archiving.Generic;
using SIL.Archiving.IMDI.Lists;

namespace SIL.Archiving.IMDI.Schema
Expand All @@ -15,8 +15,7 @@ public static void SetValue(this VocabularyType vocabularyType, string value, bo
{
if (value == null) return;

if (vocabularyType == null)
vocabularyType = new VocabularyType();
vocabularyType ??= new VocabularyType();

vocabularyType.Value = value;
vocabularyType.Type = isClosedVocabulary
Expand Down
Loading

0 comments on commit 445b557

Please sign in to comment.