Last active
August 29, 2015 14:07
-
-
Save Evgenus/16ac8d9d0da7539887ee to your computer and use it in GitHub Desktop.
Dialogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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