public void AddHolding(CHolding toAdd) { if (Holdings.Contains(toAdd)) { throw new Exception(String.Format("Duplicate security '{0}' found.", toAdd.SecurityName)); } Holdings.Add(toAdd); }
/// <summary> /// Processes a line from the input file, entering the data into the holdingdate objects passed. /// </summary> /// <param name="toProcess">String to process</param> /// <param name="holdingDate">CHoldingDate for the data</param> static void ProcessLine(String toProcess, CHoldingDate holdingDate) { if (_reportParser == null) { // Using a regex, as the data seems to move vs the headings. (Normally its better to parse the headings to find the data.) _reportParser = new Regex(@"^ (?<securityName>.{28})\s (?<securityType>.{16})\s* (?<cusip>[A-Z0-9 ]{11})\s+ (?<mktval>\d+)\s+ (?<amt>\d+)\s+ (?<amtType>\w+)\s+ (?<invDescretion>\w+)\s+ (?<otherManager>\d?)\s+ (?<votingSole>\d+)\s+ (?<votingShared>\d+)\s+ (?<votingNone>\d+)\s? $ ", RegexOptions.IgnorePatternWhitespace); } Match m = _reportParser.Match(toProcess); if (m.Success) { CHolding toAdd = new CHolding( m.Groups["securityName"].Value.Trim(), m.Groups["securityType"].Value.Trim(), m.Groups["cusip"].Value.Trim(), ParseDouble(m.Groups["mktval"].Value), ParseDouble(m.Groups["amt"].Value), m.Groups["amtType"].Value, m.Groups["invDescretion"].Value, ParseInt(m.Groups["otherManager"].Value, true), ParseInt(m.Groups["votingSole"].Value, false), ParseInt(m.Groups["votingShared"].Value, false), ParseInt(m.Groups["votingNone"].Value, false) ); holdingDate.AddHolding(toAdd); } else { throw new Exception("Could not parse the line into holdings data."); } }