Skip to content

Commit

Permalink
Upgraded to release version of SIL DLLs and got some additional minor…
Browse files Browse the repository at this point in the history
… upgrades to other DLLs

Fixed mocks in unit test corresponding to archiving model changes
  • Loading branch information
tombogle committed Jan 17, 2025
1 parent 3da1022 commit 4c3aa17
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 269 deletions.
7 changes: 6 additions & 1 deletion src/SayMore/Model/ArchivingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ internal static void SetIMDIMetadataToArchive(IArchivable element, IMDIArchiving
}
}

internal static void AddIMDISession(Session sayMoreSession, IMDIArchivingDlgViewModel model)
internal static IArchivingSession AddIMDISession(Session sayMoreSession, IMDIArchivingDlgViewModel model)
{
var sessionFile = sayMoreSession.MetaDataFile;
if (Project == null)
Expand Down Expand Up @@ -379,6 +379,11 @@ internal static void AddIMDISession(Session sayMoreSession, IMDIArchivingDlgView
if (!string.IsNullOrEmpty(microphone))
imdiSession.AddFileKeyValuePair(file, "RecordingEquipment", microphone);
}

// Not needed in production, but makes testing easier, so we don't have to do
// model.Object.ArchivingPackage.Sessions
// .OfType<SIL.Archiving.IMDI.Schema.Session>().Single()
return imdiSession;
}

private static string GetAnalysisLanguageIdentifier(Project sayMoreProject)
Expand Down
61 changes: 23 additions & 38 deletions src/SayMore/Model/Files/AnnotationComponentFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
using SIL.Windows.Forms.FileSystem;
using SayMore.Properties;
using SayMore.Transcription.Model;
using static System.IO.Path;

namespace SayMore.Model.Files
{
public class AnnotationComponentFile : ComponentFile
{
public ComponentFile AssociatedComponentFile { get; private set; }
public const string kEafSettingsFileExtension = ".psfx";
public ComponentFile AssociatedComponentFile { get; }
private OralAnnotationComponentFile _oralAnnotationFile;

/// ------------------------------------------------------------------------------------
Expand Down Expand Up @@ -64,29 +66,21 @@ public string GetPathToAssociatedMediaFile()
/// ------------------------------------------------------------------------------------
public OralAnnotationComponentFile OralAnnotationFile
{
get
{
return (_oralAnnotationFile != null && File.Exists(_oralAnnotationFile.PathToAnnotatedFile) ?
_oralAnnotationFile : null);
}
set
{
_oralAnnotationFile = (value != null &&
get => _oralAnnotationFile != null &&
File.Exists(_oralAnnotationFile.PathToAnnotatedFile) ? _oralAnnotationFile : null;

set => _oralAnnotationFile = (value != null &&
File.Exists(value.PathToAnnotatedFile) ? value : null);
}
}

/// ------------------------------------------------------------------------------------
public override int DisplayIndentLevel
{
get { return 1; }
}
public override int DisplayIndentLevel => 1;

/// ------------------------------------------------------------------------------------
public bool GetIsAnnotatingAudioFile()
{
return FileUtils.AudioFileExtensions.Contains(
Path.GetExtension(GetPathToAssociatedMediaFile().ToLower()));
GetExtension(GetPathToAssociatedMediaFile().ToLower()));
}

/// ------------------------------------------------------------------------------------
Expand Down Expand Up @@ -139,25 +133,26 @@ public string GetSuggestedPathToOralAnnotationFile()
/// ------------------------------------------------------------------------------------
public override void RenameAnnotatedFile(string newPath)
{
var oldPfsxFile = Path.ChangeExtension(PathToAnnotatedFile, ".pfsx");
var oldEafSettingsFile = ChangeExtension(PathToAnnotatedFile,
kEafSettingsFileExtension);
base.RenameAnnotatedFile(newPath);
AnnotationFileHelper.ChangeMediaFileName(PathToAnnotatedFile, GetPathToAssociatedMediaFile());

if (!File.Exists(oldPfsxFile))
if (!File.Exists(oldEafSettingsFile))
return;

var newPfsxFile = Path.ChangeExtension(PathToAnnotatedFile, ".pfsx");
File.Move(oldPfsxFile, newPfsxFile);
var newEafSettingsFile = ChangeExtension(PathToAnnotatedFile,
kEafSettingsFileExtension);
File.Move(oldEafSettingsFile, newEafSettingsFile);

if (_oralAnnotationFile != null)
_oralAnnotationFile.RenameAnnotatedFile(GetSuggestedPathToOralAnnotationFile());
_oralAnnotationFile?.RenameAnnotatedFile(GetSuggestedPathToOralAnnotationFile());
}

/// ------------------------------------------------------------------------------------
protected internal override bool Delete()
{
// If the annotation file has an associated ELAN preference file, then delete it.
var prefFilePath = Path.ChangeExtension(PathToAnnotatedFile, ".pfsx");
var prefFilePath = ChangeExtension(PathToAnnotatedFile, ".pfsx");
var oralAnnotationFile = OralAnnotationFile;

if (!base.Delete())
Expand Down Expand Up @@ -192,16 +187,12 @@ protected internal override bool Delete()
}

/// ------------------------------------------------------------------------------------
public string SegmentAnnotationFileFolder
{
get { return AssociatedComponentFile + Settings.Default.OralAnnotationsFolderSuffix; }
}
public string SegmentAnnotationFileFolder =>
AssociatedComponentFile + Settings.Default.OralAnnotationsFolderSuffix;

/// ------------------------------------------------------------------------------------
public override bool HasSubordinateFiles
{
get { return _oralAnnotationFile != null || Directory.Exists(SegmentAnnotationFileFolder); }
}
public override bool HasSubordinateFiles =>
_oralAnnotationFile != null || Directory.Exists(SegmentAnnotationFileFolder);

/// ------------------------------------------------------------------------------------
public override bool GetCanHaveAnnotationFile()
Expand All @@ -210,16 +201,10 @@ public override bool GetCanHaveAnnotationFile()
}

/// ------------------------------------------------------------------------------------
public override bool CanBeRenamedForRole
{
get { return false; }
}
public override bool CanBeRenamedForRole => false;

/// ------------------------------------------------------------------------------------
public override bool CanBeCustomRenamed
{
get { return false; }
}
public override bool CanBeCustomRenamed => false;

/// ------------------------------------------------------------------------------------
/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions src/SayMore/Model/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,15 +786,17 @@ public void SetFilesToArchive(ArchivingDlgViewModel model,
"Adding Files for Session '{0}'"), Title);

/// ------------------------------------------------------------------------------------
public IEnumerable<string> GetSessionFilesToArchive(Type typeOfArchive, CancellationToken cancellationToken)
public IEnumerable<string> GetSessionFilesToArchive(Type typeOfArchive,
CancellationToken cancellationToken)
{
// RAMP packages must not be compressed or RAMP can't read them.
var tempZipFilePath = ChangeExtension(GetTempFileName(), "zip");
// RAMP packages must not be compressed or RAMP can't read them.
ZipFile.CreateFromDirectory(FolderPath, tempZipFilePath, CompressionLevel.NoCompression, true);
var filesInDir = Directory.GetFiles(FolderPath);
var zipFilePath = Combine(FolderPath, "Sessions.zip");
RobustFile.Move(tempZipFilePath, zipFilePath, true);
return filesInDir.Where(f => ArchivingHelper.IncludeFileInArchive(f, typeOfArchive, Settings.Default.SessionFileExtension, CancellationToken.None));
return Directory.GetFiles(FolderPath).Where(f =>
ArchivingHelper.IncludeFileInArchive(f, typeOfArchive,
Settings.Default.SessionFileExtension, CancellationToken.None));
}
#endregion
}
Expand Down
Loading

0 comments on commit 4c3aa17

Please sign in to comment.