Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into Create-project-with…
Browse files Browse the repository at this point in the history
…out-background-worker-shared-methods
  • Loading branch information
AndrewChristensenFCBH committed Aug 24, 2020
2 parents 2cf8d8d + a2e6016 commit 0094b1c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 26 deletions.
4 changes: 1 addition & 3 deletions Glyssen/Dialogs/AssignCharacterDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,7 @@ private void SetReferenceTextForeColor(DataGridViewRow row, AssignCharacterViewM

private void SetDeliveryCellValue(DataGridViewRow row, Block correlatedBlock)
{
var delivery = correlatedBlock.Delivery;
if (IsNullOrEmpty(delivery))
delivery = correlatedBlock.ReferenceBlocks.Single().Delivery;
var delivery = m_viewModel.GetEffectiveDelivery(correlatedBlock);
if (IsNullOrEmpty(delivery))
delivery = ((AssignCharacterViewModel.Delivery)colDelivery.Items[0]).LocalizedDisplay;
row.Cells[colDelivery.Index].Value = delivery;
Expand Down
1 change: 1 addition & 0 deletions Glyssen/Glyssen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<WarningLevel>1</WarningLevel>
<OutputPath>..\output\Debug\</OutputPath>
<Prefer32Bit>false</Prefer32Bit>
<DefineConstants>DEBUG</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>..\output\Release\</OutputPath>
Expand Down
2 changes: 2 additions & 0 deletions GlyssenEngine/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ public bool RemoveProjectCharacterDetail(string character)
public bool AddNewReportingClauses(IEnumerable<string> reportingClauses)
{
var retVal = false;
if (m_metadata.Language.ReportingClauses == null)
m_metadata.Language.ReportingClauses = new HashSet<string>();
foreach (var reportingClause in reportingClauses)
retVal |= m_metadata.Language.ReportingClauses.Add(reportingClause);
return retVal;
Expand Down
62 changes: 39 additions & 23 deletions GlyssenEngine/ViewModels/AssignCharacterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using CollectionExtensions = SIL.Extensions.CollectionExtensions;
using SIL;
using SIL.Reporting;
using static System.String;

namespace GlyssenEngine.ViewModels
{
Expand Down Expand Up @@ -148,7 +149,7 @@ private void AddPendingProjectCharacterVerseDataIfNeeded(Block block, string cha

private void AddPendingProjectCharacterVerseData(Block block, string characterId, Delivery delivery = null)
{
Debug.Assert(!String.IsNullOrEmpty(characterId));
Debug.Assert(!IsNullOrEmpty(characterId));
m_pendingCharacterDeliveryAdditions.Add(new CharacterSpeakingMode(
characterId,
delivery == null ? Delivery.Normal.Text : delivery.Text,
Expand Down Expand Up @@ -313,7 +314,7 @@ public IEnumerable<Character> GetUniqueCharacters(string filterText = null)
{
var charactersForCurrentRef = GetUniqueCharacterVerseObjectsForCurrentReference();

if (string.IsNullOrWhiteSpace(filterText))
if (IsNullOrWhiteSpace(filterText))
{
m_currentCharacters = new HashSet<ICharacterDeliveryInfo>(m_combinedCharacterVerseData.GetUniqueCharacterDeliveryInfo(CurrentBookId));
}
Expand Down Expand Up @@ -353,7 +354,7 @@ public IEnumerable<Delivery> GetDeliveriesForCharacter(Character selectedCharact
if (!selectedCharacter.IsNarrator)
{
foreach (var cv in m_currentCharacters.Where(c => c.Character == selectedCharacter.CharacterId &&
!string.IsNullOrEmpty(c.Delivery) &&
!IsNullOrEmpty(c.Delivery) &&
m_currentDeliveries.All(d => d.Text != c.Delivery)))
{
m_currentDeliveries.Add(new Delivery(cv.Delivery, cv.ProjectSpecific));
Expand All @@ -365,7 +366,7 @@ public IEnumerable<Delivery> GetDeliveriesForCharacter(Character selectedCharact
public IEnumerable<Delivery> GetUniqueDeliveries(string filterText = null)
{
List<Delivery> deliveries;
if (string.IsNullOrWhiteSpace(filterText))
if (IsNullOrWhiteSpace(filterText))
deliveries = m_combinedCharacterVerseData.GetUniqueDeliveries()
.Select(d => m_currentDeliveries.FirstOrDefault(cd => cd.Text == d) ?? new Delivery(d)).ToList();
else
Expand All @@ -386,14 +387,16 @@ public IEnumerable<Delivery> GetDeliveriesForCurrentReferenceTextMatchup()

foreach (var block in CurrentReferenceTextMatchup.CorrelatedBlocks)
{
foreach (var delivery in GetUniqueCharacterVerseObjectsForBlock(block).Where(cv => !String.IsNullOrEmpty(cv.Delivery))
foreach (var delivery in GetUniqueCharacterVerseObjectsForBlock(block).Where(cv => !IsNullOrEmpty(cv.Delivery))
.Select(cv => new Delivery(cv.Delivery, cv.ProjectSpecific)))
{
if (!m_currentDeliveries.Any(d => d.Text == delivery.Text))
m_currentDeliveries.Add(delivery);
}
if (!String.IsNullOrEmpty(block.Delivery) && !m_currentDeliveries.Any(d => d.Text == block.Delivery))
m_currentDeliveries.Add(new Delivery(block.Delivery));

var deliveryFromBlock = GetEffectiveDelivery(block);
if (!IsNullOrEmpty(deliveryFromBlock) && !m_currentDeliveries.Any(d => d.Text == deliveryFromBlock))
m_currentDeliveries.Add(new Delivery(deliveryFromBlock));
}

m_currentDeliveries.Sort(m_deliveryComparer);
Expand All @@ -402,6 +405,19 @@ public IEnumerable<Delivery> GetDeliveriesForCurrentReferenceTextMatchup()

return m_currentDeliveries;
}

public string GetEffectiveDelivery(Block block)
{
var delivery = block.Delivery;
if (IsNullOrEmpty(delivery) && block.MatchesReferenceText)
{
var refBlock = block.ReferenceBlocks.Single();
delivery = refBlock.Delivery ??
(m_project.ReferenceText.HasSecondaryReferenceText ? refBlock.ReferenceBlocks.SingleOrDefault()?.Delivery : null);
}

return delivery;
}

public IEnumerable<Delivery> GetDeliveriesForCharacterInCurrentReferenceTextMatchup(Character character)
{
Expand Down Expand Up @@ -430,7 +446,7 @@ public bool IsModified(Character newCharacter, Delivery newDelivery)
return true;

if (newDelivery.IsNormal)
return (!string.IsNullOrEmpty(currentBlock.Delivery));
return (!IsNullOrEmpty(currentBlock.Delivery));

return newDelivery.Text != currentBlock.Delivery;
}
Expand Down Expand Up @@ -581,7 +597,7 @@ private string GetCurrentRelevantAlias(string characterId)
{
if (character.CharacterId == characterId)
{
if (!string.IsNullOrEmpty(character.LocalizedAlias))
if (!IsNullOrEmpty(character.LocalizedAlias))
return character.LocalizedAlias;
break;
}
Expand All @@ -602,7 +618,7 @@ public void SplitBlock(IEnumerable<BlockSplitData> blockSplits, List<KeyValuePai
var firstCharacterId = characters.First(c => c.Key == 0).Value;
if (currentBlock.CharacterId != firstCharacterId)
{
if (string.IsNullOrEmpty(firstCharacterId))
if (IsNullOrEmpty(firstCharacterId))
currentBlock.CharacterId = CharacterVerseData.kUnexpectedCharacter;
else
{
Expand All @@ -625,7 +641,7 @@ public void SplitBlock(IEnumerable<BlockSplitData> blockSplits, List<KeyValuePai
var originalNextBlock = BlockAccessor.GetNthNextBlockWithinBook(1, blockSplitData.BlockToSplit);
var chipOffTheOldBlock = CurrentBook.SplitBlock(blockSplitData.BlockToSplit, blockSplitData.VerseToSplit,
blockSplitData.CharacterOffsetToSplit, true, characterId);
if (!string.IsNullOrEmpty(characterId))
if (!IsNullOrEmpty(characterId))
AddPendingProjectCharacterVerseDataIfNeeded(chipOffTheOldBlock, characterId);

var isNewBlock = originalNextBlock != chipOffTheOldBlock;
Expand Down Expand Up @@ -712,15 +728,15 @@ public Character(string characterId, string localizedCharacterId = null, string
m_characterId = CharacterVerseData.IsCharacterOfType(characterId, CharacterVerseData.StandardCharacter.Narrator) ?
s_narrator.CharacterId : characterId;
m_localizedCharacterId = localizedCharacterId ?? characterId;
m_alias = String.IsNullOrWhiteSpace(alias) ? null : alias;
m_localizedAlias = String.IsNullOrWhiteSpace(localizedAlias) ? null : localizedAlias;
m_alias = IsNullOrWhiteSpace(alias) ? null : alias;
m_localizedAlias = IsNullOrWhiteSpace(localizedAlias) ? null : localizedAlias;
m_projectSpecific = projectSpecific;
}

public override string ToString()
{
if (IsNarrator)
return String.Format(CharacterId, s_funcToGetBookId());
return Format(CharacterId, s_funcToGetBookId());
return LocalizedAlias ?? CharacterId;
}

Expand All @@ -736,9 +752,9 @@ public static string GetCharacterIdForUi(string characterId)
switch (CharacterVerseData.GetStandardCharacterType(characterId))
{
case CharacterVerseData.StandardCharacter.Narrator: return s_narrator.ToString();
case CharacterVerseData.StandardCharacter.Intro: return String.Format(s_introCharacter, s_funcToGetBookId());
case CharacterVerseData.StandardCharacter.ExtraBiblical: return String.Format(s_extraCharacter, s_funcToGetBookId());
case CharacterVerseData.StandardCharacter.BookOrChapter: return String.Format(s_bookChapterCharacter, s_funcToGetBookId());
case CharacterVerseData.StandardCharacter.Intro: return Format(s_introCharacter, s_funcToGetBookId());
case CharacterVerseData.StandardCharacter.ExtraBiblical: return Format(s_extraCharacter, s_funcToGetBookId());
case CharacterVerseData.StandardCharacter.BookOrChapter: return Format(s_bookChapterCharacter, s_funcToGetBookId());
default:
if (characterId == CharacterVerseData.kAmbiguousCharacter || characterId == CharacterVerseData.kUnexpectedCharacter)
return "";
Expand All @@ -753,7 +769,7 @@ public static string GetCharacterIdForUi(string characterId)
#region Equality members
protected bool Equals(Character other)
{
return string.Equals(CharacterId, other.CharacterId);
return String.Equals(CharacterId, other.CharacterId);
}

public override bool Equals(object obj)
Expand Down Expand Up @@ -804,7 +820,7 @@ protected int CompareSpecialCases(Character x, Character y, string xTextToCompar
}

// this is not a special case
return string.Compare(xTextToCompare, yTextToCompare, StringComparison.InvariantCultureIgnoreCase);
return Compare(xTextToCompare, yTextToCompare, StringComparison.InvariantCultureIgnoreCase);
}
}

Expand All @@ -822,11 +838,11 @@ public class AliasComparer : CharacterComparer, IComparer<Character>
{
int IComparer<Character>.Compare(Character x, Character y)
{
var xTextToCompare = string.IsNullOrEmpty(x.Alias) ? x.CharacterId : x.Alias;
var yTextToCompare = string.IsNullOrEmpty(y.Alias) ? y.CharacterId : y.Alias;
var xTextToCompare = IsNullOrEmpty(x.Alias) ? x.CharacterId : x.Alias;
var yTextToCompare = IsNullOrEmpty(y.Alias) ? y.CharacterId : y.Alias;

var result = CompareSpecialCases(x, y, xTextToCompare, yTextToCompare);
return result != 0 ? result : string.Compare(x.CharacterId, y.CharacterId, StringComparison.InvariantCultureIgnoreCase);
return result != 0 ? result : Compare(x.CharacterId, y.CharacterId, StringComparison.InvariantCultureIgnoreCase);
}
}
#endregion
Expand Down Expand Up @@ -907,7 +923,7 @@ public class DeliveryComparer : IComparer<Delivery>
{
int IComparer<Delivery>.Compare(Delivery x, Delivery y)
{
return String.Compare(x.Text, y.Text, StringComparison.InvariantCultureIgnoreCase);
return Compare(x.Text, y.Text, StringComparison.InvariantCultureIgnoreCase);
}
}
#endregion
Expand Down
42 changes: 42 additions & 0 deletions GlyssenEngineTests/ViewModelTests/AssignCharacterViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public void GetDeliveriesForCurrentReferenceTextMatchup_CannedDeliveries_GetsNor
[Test]
public void GetDeliveriesForCurrentReferenceTextMatchup_BlockSetToProjectSpecificDelivery_ResultIncludesProjectSpecificDelivery()
{
m_fullProjectRefreshRequired = true;
FindRefInMark(10, 49);
m_model.SetCharacterAndDelivery(m_model.GetUniqueCharactersForCurrentReference().First(c => c.CharacterId == "Jesus"),
new AssignCharacterViewModel.Delivery("ordering"));
Expand All @@ -186,6 +187,47 @@ public void GetDeliveriesForCurrentReferenceTextMatchup_BlockSetToProjectSpecifi
Assert.AreEqual(1, result.Count(d => d.Text == "ordering"));
}


#region PG-1401
[Test]
public void GetDeliveriesForCurrentReferenceTextMatchup_BlockReferenceTextSetToNonstandardDelivery_ResultIncludesNonstandardDelivery()
{
FindRefInMark(10, 49);
m_model.SetMode(m_model.Mode, true);
var baseList = m_model.GetDeliveriesForCurrentReferenceTextMatchup().ToList();
var block = m_model.CurrentReferenceTextMatchup.CorrelatedBlocks.First(b => b.MatchesReferenceText &&
b.CharacterId != CharacterVerseData.GetStandardCharacterId("MRK", CharacterVerseData.StandardCharacter.Narrator));
block.ReferenceBlocks.Single().Delivery = "slurred";

var result = m_model.GetDeliveriesForCurrentReferenceTextMatchup().ToList();
Assert.AreEqual(baseList.Count + 1, result.Count);
Assert.IsTrue(result[0].IsNormal);
Assert.IsTrue(baseList.All(d => result.Contains(d)));
Assert.IsTrue(result.Any(d => d.Text == "slurred"));
}

[Test]
public void GetDeliveriesForCurrentReferenceTextMatchup_SecondLevelBlockReferenceTextSetToNonstandardDelivery_ResultIncludesNonstandardDelivery()
{
m_fullProjectRefreshRequired = true;
m_testProject.ReferenceText = ReferenceText.GetStandardReferenceText(ReferenceTextType.Russian);
FindRefInMark(10, 49);
m_model.SetMode(m_model.Mode, true);
var baseList = m_model.GetDeliveriesForCurrentReferenceTextMatchup().ToList();
var block = m_model.CurrentReferenceTextMatchup.CorrelatedBlocks.First(b => b.MatchesReferenceText &&
b.CharacterId != CharacterVerseData.GetStandardCharacterId("MRK", CharacterVerseData.StandardCharacter.Narrator));
var refBlock = block.ReferenceBlocks.Single();
refBlock.Delivery = null;
refBlock.ReferenceBlocks.Single().Delivery = "squealing";

var result = m_model.GetDeliveriesForCurrentReferenceTextMatchup().ToList();
Assert.AreEqual(baseList.Count + 1, result.Count);
Assert.IsTrue(result[0].IsNormal);
Assert.IsTrue(baseList.All(d => result.Contains(d)));
Assert.IsTrue(result.Any(d => d.Text == "squealing"));
}
#endregion

[Test]
public void GetUniqueCharacters_AmbiguousQuoteNoFilter_GetsAllCharactersInMark()
{
Expand Down

1 comment on commit 0094b1c

@palaso-bob
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Glyssen / Glyssen pull requests (64-bit) Build 1.6.0-Create-project-without-background-worker-shared-methods.10 outcome was SUCCESS
Summary: Tests passed: 2531, ignored: 19 Build time: 00:07:23

Please sign in to comment.