Skip to content

Instantly share code, notes, and snippets.

@Evgenus
Last active August 29, 2015 14:07
Show Gist options
  • Save Evgenus/16ac8d9d0da7539887ee to your computer and use it in GitHub Desktop.
Save Evgenus/16ac8d9d0da7539887ee to your computer and use it in GitHub Desktop.
Dialogs
public class DialogueEntry
{
public string ConversationID;
public string ConversationTitle;
public string DialogueEntryID;
public string DialogueEntryTitle;
}
class InvalidConversationTitle : Exception
{
public readonly DialogueEntry entry;
public InvalidConversationTitle(DialogueEntry _entry)
{
entry = _entry;
}
}
class DuplicatedDialogueEntryID : Exception
{
public readonly DialogueEntry entry;
public DuplicatedDialogueEntryID(DialogueEntry _entry)
{
entry = _entry;
}
}
class DuplicatedDialogueEntryTitle : Exception
{
public readonly DialogueEntry entry;
public DuplicatedDialogueEntryTitle(DialogueEntry _entry)
{
entry = _entry;
}
}
class Program
{
static void Main(string[] args)
{
}
private void Validate(IEnumerable<DialogueEntry> enumerable)
{
foreach(var conversation in enumerable.GroupBy(x => x.ConversationID)) {
var titlesOfConversation = conversation.GroupBy(x => x.ConversationTitle).ToList();
if(titlesOfConversation.Count() > 1) {
var titleWithMinimalOccurences = titlesOfConversation.Aggregate((min, x) => (min == null || x.Count() < min.Count() ? x : min));
throw new InvalidConversationTitle(titleWithMinimalOccurences.First());
}
var entryIdDuplicates = conversation.GroupBy(x => x.DialogueEntryID).FirstOrDefault(x => x.Count() > 1);
if(entryIdDuplicates != null) {
throw new DuplicatedDialogueEntryID(entryIdDuplicates.Last());
}
var entryTitleDuplicates = conversation.GroupBy(x => x.DialogueEntryTitle).FirstOrDefault(x => x.Count() > 1);
if (entryIdDuplicates != null)
{
throw new DuplicatedDialogueEntryTitle(entryIdDuplicates.Last());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment