public ContractInfomation ContractOf(string fileName) { int index = fileName.LastIndexOf('\\'); fileName = fileName.Substring(index + 1); if (!fileName.StartsWith(Symbol)) { throw new Exception("Unexpected filename: " + fileName); } if (fileName.EndsWith("da1")) { if (fileName.Contains('.')) { fileName = fileName.Substring(0, fileName.IndexOf('.')); } char code = fileName[fileName.Length - 1]; int month, year = DateTimeOffset.Now.Year; month = MonthCodes.MonthOf(code); return(new ContractInfomation(this, year, month)); } else { if (fileName.Contains('.')) { fileName = fileName.Substring(0, fileName.IndexOf('.')); } char code = fileName[fileName.Length - 1]; if (!MonthCodeString.Contains(code)) { //throw new Exception(string.Format("The commodity contains no contract for month of {0}({1})", code, MonthCodes.MonthCodeOf(code).Name)); MonthCodeString = string.Format("{0}{1}", code, MonthCodeString); Months.Add(MonthCodes.MonthCodeOf(code)); Months.Sort(); } int month, year; month = MonthCodes.MonthOf(code); string yearString = fileName.Substring(Symbol.Length, fileName.Length - Symbol.Length - 1); if (int.TryParse(yearString, out year)) { return(new ContractInfomation(this, year > 30 ? 1900 + year : 2000 + year, month)); } else { throw new Exception("Failed to parse year from " + yearString); } } }
public ContractInfomation Next() { MonthCodes nextCode = Commodity.NextOf(Code); if (Code.Month < nextCode.Month) { return(new ContractInfomation(Commodity, Year, MonthCodes.MonthOf(nextCode.Symbol))); } else { return(new ContractInfomation(Commodity, Year + 1, MonthCodes.MonthOf(nextCode.Symbol))); } }