本文整理汇总了C#中IProgress.WriteMessageWithColor方法的典型用法代码示例。如果您正苦于以下问题:C# IProgress.WriteMessageWithColor方法的具体用法?C# IProgress.WriteMessageWithColor怎么用?C# IProgress.WriteMessageWithColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProgress
的用法示例。
在下文中一共展示了IProgress.WriteMessageWithColor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryMergeEntries
public static bool TryMergeEntries(LexEntry entry1, LexEntry entry2, string[] traitsWithMultiplicity, IProgress progress)
{
if (!entry1.LexicalForm.CanBeUnifiedWith(entry2.LexicalForm))
{
progress.WriteMessageWithColor("gray","Attempting to merge entries, but could not because their Lexical Forms clash in some writing system.");
return false;
}
if (!SenseMerger.TryMergeProperties(entry1, entry2, traitsWithMultiplicity, "entries for "+entry1.ToString(), progress))
return false;
// at this point, we're committed to doing the merge
entry1.LexicalForm.MergeIn(entry2.LexicalForm);
var senses = entry2.Senses.ToArray();
foreach (var sense in senses)
{
MergeOrAddSense(entry1, sense, traitsWithMultiplicity, progress);
}
if (entry2.ModificationTime > entry1.ModificationTime)
{
entry1.ModificationTime = entry2.ModificationTime;
}
entry1.IsDirty = true;
return true;
}
示例2: TryMergeSenseWithSomeExistingSense
public static bool TryMergeSenseWithSomeExistingSense(LexSense targetSense, LexSense incomingSense, string[] traitsWithMultiplicity, IProgress progress)
{
//can we unify the properites?
if (!TryMergeProperties(targetSense, incomingSense, traitsWithMultiplicity, "senses of " + targetSense.Parent.ToString(), progress))
{
return false;
}
progress.WriteMessageWithColor("blue", "Merged two senses of {0} together: {1} into {2}", targetSense.Parent.ToString(), incomingSense.Id, targetSense.Id);
//at this point, we're committed);
foreach (var lexExampleSentence in incomingSense.ExampleSentences)
{
targetSense.ExampleSentences.Add(lexExampleSentence);
}
return true;
}
示例3: TryMergeProperties
public static bool TryMergeProperties(PalasoDataObject targetItem, PalasoDataObject incomingItem, string[] traitsWithMultiplicity, string itemDescriptionForMessage, IProgress progress)
{
var knownMergableOptionCollectionTraits = new[] { LexSense.WellKnownProperties.SemanticDomainDdp4 };
if (traitsWithMultiplicity == null)
{
traitsWithMultiplicity = new string[0];
}
foreach (var incomingProperty in incomingItem.Properties)
{
if (targetItem.Properties.Any(p => p.Key == incomingProperty.Key))
{
var targetProperty = targetItem.Properties.First(p => p.Key == incomingProperty.Key);
if (incomingProperty.Value is MultiText && targetProperty.Value is MultiText &&
((MultiText)incomingProperty.Value).CanBeUnifiedWith(((MultiText)targetProperty.Value)))
{
continue;
}
//NB: Some of the complexity here is that we can't really tell from here if what the multiplicity is of the <trait>, unless we
//recognize the trait (e.d. semantic domains) or we see that one side has > 1 values already.
if (incomingProperty.Value is OptionRefCollection && targetProperty.Value is OptionRefCollection)
{
var targetCollection = ((OptionRefCollection)targetProperty.Value);
var incomingCollection = ((OptionRefCollection)incomingProperty.Value);
var clearlyHasMultiplicityGreaterThan1 = (incomingCollection.Count > 1 || targetCollection.Count > 1);
var atLeastOneSideIsEmpty = (incomingCollection.Count == 0 || targetCollection.Count == 0);
if (knownMergableOptionCollectionTraits.Contains(targetProperty.Key)
|| traitsWithMultiplicity.Contains(targetProperty.Key)
|| clearlyHasMultiplicityGreaterThan1
|| atLeastOneSideIsEmpty)
{
var mergeSuccess = targetCollection.MergeByKey(
(OptionRefCollection) incomingProperty.Value);
if (mergeSuccess)
continue;
else
{
progress.WriteMessageWithColor("gray",
"Attempting to merge " + itemDescriptionForMessage +
", but could not due to inability to merge contents of the property '{0}' (possibly due to incompatible embedded xml).",
targetProperty.Key, targetProperty.Value,
incomingProperty.Value);
return false;
}
}
else
//at this point, we know that both sides have a count of 1, a common thing for a <trait> with multiplicity of 1
if (((OptionRef) incomingCollection.Members[0]).Key == ((OptionRef) targetCollection.Members[0]).Key &&
((OptionRef) incomingCollection.Members[0]).Value == ((OptionRef) targetCollection.Members[0]).Value)
{
continue; //same, single value
}
}
if (incomingProperty.Value is OptionRef && targetProperty.Value is OptionRef &&
(((OptionRef)incomingProperty.Value).Value == ((OptionRef)targetProperty.Value).Value))
{
continue;
}
if (targetProperty.Value != incomingProperty.Value)
{
progress.WriteMessageWithColor("gray","Attempting to merge "+itemDescriptionForMessage+", but could not because of the property '{0}' ('{1}' vs. '{2}')", targetProperty.Key, targetProperty.Value, incomingProperty.Value);
return false; //clashing properties
}
}
}
//at this point, we're committed
//I (JH) once saw this foreach break saying the collection was modified, so I'm makinkg this safeProperties thing
var safeProperties = new List<KeyValuePair<string, IPalasoDataObjectProperty>>(incomingItem.Properties.ToArray());
foreach (var pair in safeProperties)
{
var match = targetItem.Properties.FirstOrDefault(p => p.Key == pair.Key);
if (match.Key != default(KeyValuePair<string, object>).Key &&
pair.Value is MultiText && match.Value is MultiText &&
((MultiText)pair.Value).CanBeUnifiedWith(((MultiText)match.Value)))
{
((MultiText)match.Value).MergeIn(((MultiText)pair.Value));
}
else
{
targetItem.MergeProperty(pair);
}
}
return true;
}
示例4: Merge
/// <summary>
/// Merge homographs.
/// </summary>
public static void Merge(LiftLexEntryRepository repo, string writingSystemIdForMatching, string[] traitsWithMultiplicity, IProgress progress)
{
var alreadyProcessed = new List<RepositoryId>();
var ids = new List<RepositoryId>(repo.GetAllItems());
foreach (RepositoryId id in ids)
{
if (progress.CancelRequested)
{
throw new OperationCanceledException("User cancelled");
}
if (alreadyProcessed.Contains(id))
continue;
alreadyProcessed.Add(id);
var entry = repo.GetItem(id);
var writingSystemForMatching = new WritingSystemDefinition(writingSystemIdForMatching) {DefaultCollation = new IcuRulesCollationDefinition("standard")};
var matches = repo.GetEntriesWithMatchingLexicalForm(
entry.LexicalForm.GetExactAlternative(writingSystemIdForMatching), writingSystemForMatching
);
//at this point we have entries which match along a single ws axis. We may or may not be able to merge them...
var lexicalForm = entry.LexicalForm.GetExactAlternative(writingSystemForMatching.LanguageTag);
if (matches.Count > 1) //>1 becuase each will match itself
{
progress.WriteMessageWithColor("gray", "Found {0} homograph(s) for {1}", matches.Count, lexicalForm);
}
var mergeCount = 0;
var matchAlreadyProcessed = new List<RepositoryId>();
foreach (RecordToken<LexEntry> incomingMatch in matches)
{
if (incomingMatch.Id == id)
continue; // The entry will match itself at least this time.
if (matchAlreadyProcessed.Contains(incomingMatch.Id))
continue; //we'll be here at least as each element matches itself
matchAlreadyProcessed.Add(incomingMatch.Id);
if (EntryMerger.TryMergeEntries(entry, incomingMatch.RealObject, traitsWithMultiplicity, progress))
{
mergeCount++;
alreadyProcessed.Add(incomingMatch.Id);
repo.DeleteItem(incomingMatch.RealObject);
repo.SaveItem(entry);
}
}
if (matches.Count > 1)
{
if (mergeCount == 0)
{
//progress.WriteMessageWithColor("gray", "Not merged.");
}
else
{
progress.WriteMessageWithColor("black", "Merged {0} homographs of {1}.", 1 + mergeCount,
lexicalForm);
}
progress.WriteMessage(""); //blank line
}
}
MergeSensesWithinEntries(repo, traitsWithMultiplicity, progress);
}