public void Open(string filepath) { string[] lines = new StreamReader(_fileSystem.OpenFileForRead(filepath)).ReadToEnd().Split(new string[] {"\r\n", "\n"}, StringSplitOptions.None); _records = new Queue<Record>(lines.Where(line => !string.IsNullOrWhiteSpace(line)).Select(ParseRecord)); _current = null; }
public PresidentRecordReader(Record record) { if (record == null) { throw new ArgumentNullException("record"); } if (record.Fields.Length != 9) { throw new FormatException( string.Format("President record must contain exactly 9 fields, but given record contains {0}.", record.Fields.Length)); } Presidency = ValidateAndGetNumber(record.Fields[0], "presidency"); Name = ValidateAndGetPersonFullName(record.Fields[1], "name"); Uri wikiUrl; if (!Uri.TryCreate(record.Fields[2], UriKind.RelativeOrAbsolute, out wikiUrl)) { throw new FormatException("Wiki link is not a valid URL."); } WikipediaEntryUrl = wikiUrl; TookOffice = ValidateAndGetDateTime(record.Fields[3], "took office date"); LeftOffice = ValidateAndGetDateTime(record.Fields[4], "left office date"); Party = ValidateAndGetString(record.Fields[5], "party"); PortraitImageFilename = ValidateAndGetString(record.Fields[6], "portrait image"); ThumbnailImageFilename = ValidateAndGetString(record.Fields[7], "thumbnail image"); HomeState = ValidateAndGetString(record.Fields[8], "home state"); }
public bool MoveNext() { if (_records.Any()) { _current = _records.Dequeue(); return true; } return false; }
public bool ShouldPass(Record record) { return new PresidentRecordReader(record).HomeState.Equals(_state); }
public bool ShouldPass(Record record) { return _predicate(record); }
protected bool Equals(Record other) { return this.Fields.SequenceEqual(other.Fields); }