public TextImporter(string formatString) { string[] subStrings = null; for (int i = 0; i < seperators.Length; i++) { subStrings = formatString.Split(new char[] { seperators[i] }, StringSplitOptions.None); if (subStrings.Length < 4) { continue; } Splitter = new char[] { seperators[i] }; break; } if (Splitter.Length != 1) { throw new Exception("Splitter is missing or not detected!"); } if (findIndicator(subStrings, KeywordsDictionary[0]) == -1) { subStrings = DefaultLineFormat; } foreach (KeyValuePair <int, string[]> kvp in KeywordsDictionary) { IndexPositions[kvp.Key] = findIndicator(subStrings, kvp.Value); } dateTimeParser = new DateTimeParseDelegate(tryParseAsUtc); }
public Quote FromFirstString(string line) { DateTimeOffset time; String[] subStr = line.Split(Splitter); if (IndexPositions[0] == -1 || subStr[0] == "") { throw new ArgumentException("Fail to get date from: " + line); } else if (!dateTimeParser(subStr[IndexPositions[0]], out time)) { string dateStr = subStr[IndexPositions[0]]; switch (dateStr.Length) { case 6: dateTimeFormat = "yyMMdd"; break; case 8: dateTimeFormat = "yyyyMMdd"; break; default: break; } if (dateTimeFormat != null && dateTimeFormat.Length != 0 && parseDateTime(dateStr, out time)) { dateTimeParser = new DateTimeParseDelegate(parseDateTime); } else if (parseWithPredefinedFormat(dateStr, out time)) { dateTimeParser = new DateTimeParseDelegate(parseDateTime); } else { throw new ArgumentException("Fail to get date from: " + line); } } List <Double> values = getValues(subStr); return(new Quote(time, values)); }