public static void ValidateFile(string file) { if (!File.Exists(file)) { throw new Exception(string.Concat("Bar data file '", file, "' does not exist!")); } else { BinaryNavigator binaryNavigator = null; try { binaryNavigator = new BinaryNavigator(file, binaryFields); } catch (Exception ex) { throw new Exception(string.Concat("Error reading data file '", file, "'!'"), ex); } object[] record = binaryNavigator.Read(); //time must be valid try { DateTime time = new DateTime((long)record[0]); } catch (Exception ex) { throw new Exception(string.Concat("Invalid time format of data file '", file, "'!'"), ex); } finally { binaryNavigator.Close(); } binaryNavigator.Close(); //prices must not be less than or equal to zero //open and closing prices must be anywhere between high and low prices if ((double)record[1] <= 0 || (double)record[2] <= 0 || (double)record[3] <= 0 || (double)record[4] <= 0 || (double)record[1] > (double)record[3] || (double)record[1] < (double)record[4] || (double)record[2] > (double)record[3] || (double)record[2] < (double)record[4]) { throw new Exception(string.Concat("Invalid price format of data file '", file, "'!'")); } } }