Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions Src/Utilities/pcpatrflex/PcPatrFLExDll/FLExUtility.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// Copyright (c) 2018 SIL International
// Copyright (c) 2018-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SIL.FieldWorks.FwCoreDlgs;
using SIL.LCModel;

Expand Down Expand Up @@ -51,6 +45,7 @@ void IUtility.Process()
{
var pcpatrFlexForm = new PcPatrFLExForm();
pcpatrFlexForm.Cache = m_dlg.PropTable.GetValue<LcmCache>("cache");
pcpatrFlexForm.PropTable = m_dlg.PropTable;
pcpatrFlexForm.PrepareForm();
//pcpatrFlexForm.FillTextsListBox();
pcpatrFlexForm.Show();
Expand Down
15 changes: 8 additions & 7 deletions Src/Utilities/pcpatrflex/PcPatrFLExDll/PcPatrFLExForm.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
// Copyright (c) 2018-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using Microsoft.Win32;
using SIL.DisambiguateInFLExDB;
using SIL.FieldWorks.Common.FwUtils;
using SIL.LCModel;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.DomainServices;
using SIL.PcPatrBrowser;
using SIL.PrepFLExDB;
using SIL.WritingSystems;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using XCore;

namespace SIL.PcPatrFLEx
{
Expand Down Expand Up @@ -69,6 +67,7 @@ public partial class PcPatrFLExForm : Form
public int MaxAmbiguities { get; set; }
public int TimeLimit { get; set; }
public bool RunIndividually { get; set; }
public PropertyTable PropTable { get; set; }

private RegistryKey regkey;

Expand Down Expand Up @@ -220,8 +219,10 @@ public void SaveRegistryInfo()
private void EnsureDatabaseHasBeenPrepped()
{
var preparer = new Preparer(Cache, false);
preparer.PropTable = PropTable;
preparer.AddPCPATRList();
preparer.AddPCPATRSenseCustomField();
FwUtils.Publisher.Publish(new PublisherParameterObject(EventConstants.MasterRefresh, null, PropTable.GetWindow()));
Comment thread
AndyBlack marked this conversation as resolved.
}

public void PrepareForm()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2019 SIL International
// Copyright (c) 2018-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand All @@ -8,16 +8,13 @@
using SIL.FieldWorks.Common.FwUtils;
using SIL.LCModel;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Core.Text;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Utils;
using SIL.PrepFLExDB;
using SIL.WritingSystems;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using XCore;

namespace SIL.PrepFLExDBTests
{
Expand All @@ -31,7 +28,11 @@ class PreparerTests : MemoryOnlyBackendProviderTestBase
LcmCache MyCache { get; set; }
public ProjectId ProjId { get; set; }
private List<FieldDescription> customFields;
Preparer Preparer { get; set; }
Mediator Mediator { get; set; }
PropertyTable PropertyTable { get; set; }

[SetUp]
public override void FixtureSetup()
{
base.FixtureSetup();
Expand All @@ -49,14 +50,22 @@ public override void FixtureSetup()
var settings = new LcmSettings { DisableDataMigration = true };
var progress = new DisambiguateInFLExDBTests.NullThreadedProgress(synchronizeInvoke);
MyCache = LcmCache.CreateCacheFromExistingData(ProjId, "en", logger, dirs, settings, progress);
Preparer = new Preparer(MyCache, false);
Mediator = new Mediator();
PropertyTable = new PropertyTable(Mediator);
Preparer.PropTable = PropertyTable;

}

/// <summary></summary>
[TearDown]
public override void FixtureTeardown()
{
//Directory.Delete(m_projectsDirectory, true);
base.FixtureTeardown();
MyCache.Dispose();
Mediator.Dispose();
PropertyTable.Dispose();
}

/// <summary>
Expand All @@ -65,32 +74,30 @@ public override void FixtureTeardown()
[Test]
public void PCPATRPreparerTest()
{
FixtureSetup();
Assert.IsNotNull(MyCache);
Assert.AreEqual(5, MyCache.LangProject.AllPartsOfSpeech.Count);
Assert.AreEqual(0, MyCache.LangProject.LexDbOA.Entries.Count());
var preparer = new Preparer(MyCache, false);

// If we try to create the custom field before the master possibility list, the field is not created.
customFields = preparer.GetListOfCustomFields();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(0, customFields.Count);
preparer.AddPCPATRSenseCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddPCPATRSenseCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(0, customFields.Count);

var possListRepository = MyCache.ServiceLocator.GetInstance<ICmPossibilityListRepository>();
Assert.AreEqual(34, possListRepository.AllInstances().Count());
preparer.AddPCPATRList();
Preparer.AddPCPATRList();
CheckPossibilityList(possListRepository);
// Invoke it again. Only one copy should exist.
preparer.AddPCPATRList();
Preparer.AddPCPATRList();
CheckPossibilityList(possListRepository);

// Add custom field
customFields = preparer.GetListOfCustomFields();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(0, customFields.Count);
preparer.AddPCPATRSenseCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddPCPATRSenseCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(1, customFields.Count);
var cf = customFields.Find(fd => fd.Name == PcPatrConstants.PcPatrFeatureDescriptorCustomField);
Assert.IsNotNull(cf);
Expand All @@ -102,8 +109,8 @@ public void PCPATRPreparerTest()
Assert.AreEqual(CmCustomItemTags.kClassId, cf.DstCls);
Assert.AreEqual(WritingSystemServices.kwsAnal, cf.WsSelector);
// Invoke it again. Only one should exist.
preparer.AddPCPATRSenseCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddPCPATRSenseCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(1, customFields.Count);
FixtureTeardown();
}
Expand Down Expand Up @@ -131,35 +138,33 @@ private void CheckMatch(ICmPossibilityList last, string sToMatch)
[Test]
public void ToneParsPreparerTest()
{
FixtureSetup();
Assert.IsNotNull(MyCache);
Assert.AreEqual(5, MyCache.LangProject.AllPartsOfSpeech.Count);
Assert.AreEqual(0, MyCache.LangProject.LexDbOA.Entries.Count());
var preparer = new Preparer(MyCache, false);

// If we try to create the custom field before the master possibility list, the field is not created.
customFields = preparer.GetListOfCustomFields();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(0, customFields.Count);
preparer.AddToneParsSenseCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddToneParsSenseCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(0, customFields.Count);
preparer.AddToneParsFormCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddToneParsFormCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(0, customFields.Count);

var possListRepository = MyCache.ServiceLocator.GetInstance<ICmPossibilityListRepository>();
Assert.AreEqual(34, possListRepository.AllInstances().Count());
preparer.AddToneParsList();
Preparer.AddToneParsList();
ToneParsCheckPossibilityList(possListRepository);
// Invoke it again. Only one copy should exist.
preparer.AddToneParsList();
Preparer.AddToneParsList();
ToneParsCheckPossibilityList(possListRepository);

// Add sense custom field
customFields = preparer.GetListOfCustomFields();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(0, customFields.Count);
preparer.AddToneParsSenseCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddToneParsSenseCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(1, customFields.Count);
var cf = customFields.Find(fd => fd.Name == ToneParsConstants.ToneParsPropertiesSenseCustomField);
Assert.IsNotNull(cf);
Expand All @@ -171,15 +176,15 @@ public void ToneParsPreparerTest()
Assert.AreEqual(CmCustomItemTags.kClassId, cf.DstCls);
Assert.AreEqual(WritingSystemServices.kwsAnal, cf.WsSelector);
// Invoke it again. Only one should exist.
preparer.AddToneParsSenseCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddToneParsSenseCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(1, customFields.Count);

// Add form custom field
customFields = preparer.GetListOfCustomFields();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(1, customFields.Count);
preparer.AddToneParsFormCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddToneParsFormCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(2, customFields.Count);
cf = customFields.Find(fd => fd.Name == ToneParsConstants.ToneParsPropertiesFormCustomField);
Assert.IsNotNull(cf);
Expand All @@ -191,8 +196,8 @@ public void ToneParsPreparerTest()
Assert.AreEqual(CmCustomItemTags.kClassId, cf.DstCls);
Assert.AreEqual(WritingSystemServices.kwsAnal, cf.WsSelector);
// Invoke it again. Only two should still exist.
preparer.AddToneParsFormCustomField();
customFields = preparer.GetListOfCustomFields();
Preparer.AddToneParsFormCustomField();
customFields = Preparer.GetListOfCustomFields();
Assert.AreEqual(2, customFields.Count);

FixtureTeardown();
Expand Down
10 changes: 10 additions & 0 deletions Src/Utilities/pcpatrflex/PrepFLExDBDll/Preparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using SIL.DisambiguateInFLExDB;
using SIL.FieldWorks.Common.FwUtils;
using SIL.LCModel;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using XCore;

namespace SIL.PrepFLExDB
{
public class Preparer
{
public PropertyTable PropTable{ get; set; }

private static readonly string[] ToneParsProperties = { "sampleToneParsAllomorphProperty", "sampleToneParsMorphemeProperty" };

private static readonly string[] FeatureDescriptors =
Expand Down Expand Up @@ -204,6 +208,7 @@ public void AddPCPATRList()
CreateNewPcPatrFeaturePossibility(ws, pcpatrList, factPoss, name);
}
});
ReloadListsArea();
}

private static void CreateNewPcPatrFeaturePossibility(int ws, ICmPossibilityList newList, ICmCustomItemFactory factPoss, string name)
Expand Down Expand Up @@ -292,6 +297,7 @@ public void AddToneParsList()
CreateNewToneParsPropertyPossibility(ws, toneParsList, factPoss, name);
}
});
ReloadListsArea();
}

private static void CreateNewToneParsPropertyPossibility(int ws, ICmPossibilityList newList, ICmCustomItemFactory factPoss, string name)
Expand Down Expand Up @@ -379,5 +385,9 @@ public void AddToneParsFormCustomField()
});
}

private void ReloadListsArea()
{
FwUtils.Publisher.Publish(new PublisherParameterObject(EventConstants.ReloadAreaTools, "lists", PropTable.GetWindow()));
}
}
}
8 changes: 2 additions & 6 deletions Src/Utilities/pcpatrflex/ToneParsFLExDll/FLExUtility.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright (c) 2019 SIL International
// Copyright (c) 2019-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SIL.FieldWorks.FwCoreDlgs;
using SIL.LCModel;

Expand Down Expand Up @@ -53,6 +48,7 @@ void IUtility.Process()
{
var toneParsFlexForm = new ToneParsFLExForm();
toneParsFlexForm.Cache = m_dlg.PropTable.GetValue<LcmCache>("cache");
toneParsFlexForm.PropTable = m_dlg.PropTable;
toneParsFlexForm.PrepareForm();
//pcpatrFlexForm.FillTextsListBox();
toneParsFlexForm.Show();
Expand Down
15 changes: 4 additions & 11 deletions Src/Utilities/pcpatrflex/ToneParsFLExDll/ToneParsFLExForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023 SIL International
// Copyright (c) 2019-2026 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand All @@ -7,27 +7,18 @@
using SIL.FieldWorks.LexText.Controls;
using SIL.FieldWorks.WordWorks.Parser;
using SIL.LCModel;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.DomainServices;
using SIL.PrepFLExDB;
using SIL.WritingSystems;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using XCore;
using XAmpleManagedWrapper;
using System.Text.RegularExpressions;
using SIL.LCModel.Infrastructure;
using SIL.FieldWorks.Common.FwUtils;
Expand All @@ -38,7 +29,7 @@ namespace SIL.ToneParsFLEx
public partial class ToneParsFLExForm : Form
{
public LcmCache Cache { get; set; }

public PropertyTable PropTable { get; set; }
protected IList<IText> Texts { get; set; }
protected IList<SegmentToShow> SegmentsInListBox { get; set; }
protected FLExDBExtractor Extractor { get; set; }
Expand Down Expand Up @@ -301,9 +292,11 @@ public void SaveRegistryInfo()
private void EnsureDatabaseHasBeenPrepped()
{
var preparer = new Preparer(Cache, false);
preparer.PropTable = PropTable;
preparer.AddToneParsList();
preparer.AddToneParsFormCustomField();
preparer.AddToneParsSenseCustomField();
FwUtils.Publisher.Publish(new PublisherParameterObject(EventConstants.MasterRefresh, null, PropTable.GetWindow()));
}

public void PrepareForm()
Expand Down
Loading