static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage: hand2xml site file"); return; } PluginServices host = PluginServices.Instance; host.PluginDirectory = AppDomain.CurrentDomain.BaseDirectory; host.AddPlugin("HandParserInterface.IHandParser"); host.FindPlugins(); AvailablePlugins parsers = host.Plugins["HandParserInterface.IHandParser"]; foreach (AvailablePlugin plugin in parsers) { IHandParser parser = (IHandParser)plugin.Instance; if (parser.Switch == args[0]) { PokerHandXML hands = parser.ParseFile(args[1]); TextWriter output = new StreamWriter(args[1] + ".xml"); XmlSerializer serializer = new XmlSerializer(typeof(PokerHandXML)); serializer.Serialize(output, hands); output.Flush(); output.Close(); return; } } }
static void Main(string[] args) { args = new string[] { "ft", @"<inputhhfile>", @"<outputxmlfile>" }; if (args.Length != 3) { Console.WriteLine("Usage: hand2xml site inFile outFile"); return; } PluginServices host = PluginServices.Instance; host.PluginDirectory = AppDomain.CurrentDomain.BaseDirectory; host.AddPlugin("HandParserInterface.IHandParser"); host.FindPlugins(); AvailablePlugins parsers = host.Plugins["HandParserInterface.IHandParser"]; foreach (AvailablePlugin plugin in parsers) { IHandParser parser = (IHandParser)plugin.Instance; if (parser.Switch == args[0]) { PokerHandXML hands = parser.ParseFile(args[1]); TextWriter output = new StreamWriter(args[2]); XmlSerializer serializer = new XmlSerializer(typeof(PokerHandXML)); serializer.Serialize(output, hands); output.Flush(); output.Close(); return; } else { } } //int fileNum = 0; //String filename = "ps NLH handhq_"; //String dir = @"C:\Users\Emre Kenci\Desktop\PSTEST\"; //for (int i = 146; i < 203; i++) //{ // args = new string[] { "ps", dir+@"\"+filename+""+i+".txt", // dir+@"\"+"result"+i+".xml" }; // if (args.Length != 3) // { // Console.WriteLine("Usage: hand2xml site inFile outFile"); // return; // } // PluginServices host = PluginServices.Instance; // host.PluginDirectory = AppDomain.CurrentDomain.BaseDirectory; // host.AddPlugin("HandParserInterface.IHandParser"); // host.FindPlugins(); // AvailablePlugins parsers = host.Plugins["HandParserInterface.IHandParser"]; // foreach (AvailablePlugin plugin in parsers) // { // IHandParser parser = (IHandParser)plugin.Instance; // if (parser.Switch == args[0]) // { // PokerHandXML hands = parser.ParseFile(args[1]); // TextWriter output = new StreamWriter(args[2]); // XmlSerializer serializer = new XmlSerializer(typeof(PokerHandXML)); // serializer.Serialize(output, hands); // output.Flush(); // output.Close(); // break; // } // } //} }
static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: hand2xml site inFile outFile [-buckets n]"); return; } int buckets = 1; #region Parse optional parameters for (int i = 0; i < args.Length; i++) { if (args[i][0] != '-') { continue; } switch (args[i]) { case "-buckets": case "-b": buckets = int.Parse(args[++i]); break; default: Console.WriteLine("Unknown parameter: {0}", args[i]); return; } } #endregion PluginServices host = PluginServices.Instance; host.PluginDirectory = AppDomain.CurrentDomain.BaseDirectory; host.AddPlugin("HandParserInterface.IHandParser"); host.FindPlugins(); AvailablePlugins parsers = host.Plugins["HandParserInterface.IHandParser"]; IHandParser parser = null; foreach (AvailablePlugin plugin in parsers) { IHandParser curParser = (IHandParser)plugin.Instance; if (curParser.Switch == args[0]) { parser = curParser; break; } } #region Validate parameters if (parser == null) { Console.WriteLine("Unknown parser type: {0}", args[0]); return; } if (!File.Exists(args[1]) && !Directory.Exists(args[1])) { Console.WriteLine("Unknown file or directory: {0}", args[1]); return; } if (buckets < 1) { Console.WriteLine("Invalid bucket count. Must have at least one bucket."); return; } #endregion PokerHandXML result; // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(args[1]); //detect whether its a directory or file if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { List <PokerHand> hands = new List <PokerHand>(); foreach (string filename in Directory.GetFiles(args[1])) { hands.AddRange(parser.ParseFile(filename).Hands); } result = new PokerHandXML() { Hands = hands.ToArray() }; } else { result = parser.ParseFile(args[1]); } string outfile = args[2]; int handsPerFile = result.Hands.Length / buckets; for (int i = 0; i < buckets; i++) { int start = handsPerFile * i; int end = start + handsPerFile; if (i == (buckets - 1)) { end = result.Hands.Length; } var subset = new PokerHandXML() { Hands = result.Hands.Where((h, idx) => idx >= start && idx < end).ToArray() }; SaveHands(subset, outfile + i + ".xml"); } }