/// <summary> /// The main thread method that will pop from the stack, then split the file /// based on the header defined in the passed in stack /// </summary> /// <param name="filename"></param> /// <param name="stack"></param> /// <param name="numOfFiles"></param> public void split(string filename, ConcurrentStack <String> stack, int numOfFiles) { while (!stack.IsEmpty) { //If we fail popping, we may be attempting to access //at the same time as someone else. This means the stack //might have emptied since we last checked so we check again if (!stack.TryPop(out string header)) { continue; } //If we got this far, then we have a header FieldSplitter splitter = new FieldSplitter(); DebugLog.logConsole("Splitting " + filename + " file based on " + header); splitter.splitFile(filename, header, numOfFiles); //remove our reference to splitter for the next iteration splitter = null; double perc = ((double)(numOfFiles - stack.Count) / (double)numOfFiles) * 100; PercentageClass.UpdatePercentage("Splitting " + header, perc); DebugLog.logConsole("File splitting: " + perc.ToString("#.##") + "% total"); } //Since the stack is empty, we are done }
/// <summary> /// args0 = file name not path /// args1 = number of divisions /// args2+= /// </summary> /// <param name="args"></param> public static void Main(string[] args) { DebugLog.resetLog(); DebugLog.setDebug(true); DateTime now = DateTime.Now; if (args.Length < 1) { Console.Out.WriteLine(numArgs); Console.In.ReadLine(); return; } if (args.Length == 1 && (args[0].ToLower() == "--help" || args[0].ToLower() == "help" || args[0].ToLower() == "?" || args[0].ToLower() == "h")) { Console.Out.WriteLine(help); Console.In.ReadLine(); return; } if (!Int32.TryParse(args[1], out int divNum)) { DebugLog.logConsole("divisionNumber was not a number"); throw new Exception("divisionNumber was not a number"); } if (divNum < 1) { DebugLog.logConsole("divisionNumber must be a positive number"); throw new Exception("divisionNumber must be a positive number"); } if (args.Length < 2) { FieldSplitter.splitFileAll(args[0], divNum); } else { string[] headers = new string[args.Length - 2]; for (int i = 2; i < args.Length; i++) { headers[i - 2] = args[i]; } FieldSplitter.splitFileGiven(args[0], headers, divNum); } DateTime fin = DateTime.Now; TimeSpan span = (fin - now); DebugLog.logConsole("Minutes to divide all = " + span.TotalMinutes); }