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 bool HasContractOn(int month) { if (month < 1 || month > 12) { return(false); } char symbol = MonthCodes.MonthCodeOf(month).Symbol; return(MonthCodeString.Contains(symbol)); }