/// <summary> /// Constructor /// Initializes everything /// </summary> /// <param name="handtaskToProcess">The HandTask which has to be processed</param> protected HandProcessor(HandTask handtaskToProcess) { if (ConfigurationManager.AppSettings["StoreHands"] == "1") { this.storeProcessedHands = true; this.storageDirectory = ConfigurationManager.AppSettings["StorageFolder"]; } if (ConfigurationManager.AppSettings["ArchiveUnprocessedHands"] == "1") { this.archiveUnprocessedHands = true; this.archiveDirectory = ConfigurationManager.AppSettings["ArchiveHandsFolder"]; } this.workingDirectory = ConfigurationManager.AppSettings["WorkingDirectory"]; this.outputDirectory = ConfigurationManager.AppSettings["OutputDirectory"]; this.fakePlayername = ConfigurationManager.AppSettings["FakeplayerName"]; this.handTask = handtaskToProcess; this.outputFilename = this.handTask.handNum + ".txt"; using (FileStream fs = new FileStream(Manager.appPath + "\\Localizations\\HandProcessing\\" + handtaskToProcess.handLanguage + ".json", FileMode.Open, FileAccess.Read, FileShare.Read)) { using (StreamReader sr = new StreamReader(fs, new UTF8Encoding())) { this.languageDictionary = JsonConvert.DeserializeObject <Dictionary <String, String> >(sr.ReadToEnd()); } } }
/// <summary> /// Creates HandTasks and serializes them for further processing. /// This method is used in normal processing, but can also be called directly from the GUI to process larger (more then 10 MB) old PokerStars-files. /// </summary> /// <param name="fileLines">A List of String containing one complete PokerStars-Hand</param> public void createHandTasks(List <String> fileLines) { bool lastLineWasFreeSpace = false; /* * normaly a hands ends with 3 space-lines... * well an export of my HM2-Database showed that is is only true in 99.81% of all cases... (4 hands where missing out of 2083) * -> this was actually another bug in HM2 where the Database forgot the empty spaces after the hand. * To even process this I use this slightly crude evaluation. * TODO: implement a better solution to detect the beginning of a new hand... this one works for english and german, but might cause trouble in the future */ XmlSerializer serializer = new XmlSerializer(typeof(HandTask)); List <String> handLines = new List <string>(); foreach (String line in fileLines) { if (line != "") // normal Line { handLines.Add(line); lastLineWasFreeSpace = false; } else { if (lastLineWasFreeSpace == false) { this.detectedHands++; HandTask ht = new HandTask(); ht.handSourceFilename = Path.GetFileNameWithoutExtension(this.sourceFilePath); //Handnumberdetection string handnum = handLines[0].Split(':')[0]; char[] handnumArray = handnum.ToCharArray(); for (int x = handnumArray.Length - 1; x > 0; x--) { if (Char.IsNumber(handnumArray[x]) == false && x > 0) { handnum = handnum.Substring(x + 1, handnum.Length - x - 1); break; } } ht.handNum = handnum; ht.lines = new string[handLines.Count]; handLines.CopyTo(ht.lines); ht.handLanguage = new HandLanguageDetector().detectHandLanguage(handLines, this.sourceFilePath, new DirectoryInfo(Path.GetDirectoryName(sourceFilePath)).Name); List <String> supportedLanguages = new List <string>(Directory.GetFiles(Manager.appPath + "\\Localizations\\HandProcessing")); using (FileStream fs = new FileStream(this.workingDirectory + handnum + ".xml", FileMode.CreateNew, FileAccess.Write, FileShare.None)) { serializer.Serialize(fs, ht); } handLines = new List <string>(); this.createdHandTasks.Add(ht); } lastLineWasFreeSpace = true; } } }
/// <summary> /// Creates a HandProcessor based on the language of the handtask /// </summary> /// <param name="ht">HandTask</param> /// <returns></returns> private IHandProcessor createHandProcessor(HandTask ht) { switch (ht.handLanguage) { case "English": return(new EnglishHandProcessor(ht)); default: return(new UnsupportedLanguageHandProcessor(ht)); } }
/// <summary> /// Checks the filesystem for any unprocessed hands from previous sessions /// </summary> private void initializeHandProcessDispatcher() { string[] serializedHandTasks = Directory.GetFiles(this.workingDirectory); XmlSerializer serializer = new XmlSerializer(typeof(HandTask)); foreach (string serializedFile in serializedHandTasks) { using (FileStream fs = new FileStream(serializedFile, FileMode.Open, FileAccess.Read, FileShare.None)) { HandTask ht = (HandTask)serializer.Deserialize(fs); HandProcessDispatcher.tasksToProcess.Enqueue(ht); } } }
public UnsupportedLanguageHandProcessor(HandTask ht) : base(ht) { this.unsupportedLanguageDirectory = ConfigurationManager.AppSettings["UnsupportedLanguageDirectory"]; }
public EnglishHandProcessor(HandTask ht) : base(ht) { }