public Boolean IsMatch(Record record) { Boolean found = false; for (Int32 index = 0; index < this.values.Length; index++) { if (this.values[index].Value == record.Term) { this.values[index].MatchedCount++; found = true; break; } } if (!found) { return false; } if (this.matchQuota == MatchQuotas.FirstMatchInList) { this.HasReachedMatchQuota = true; } if (this.matchQuota == MatchQuotas.FirstMatchOfEachTermInList && !this.values.Any(x => x.MatchedCount == 0)) { this.HasReachedMatchQuota = true; } return true; }
public static void WriteRecordToStream(StreamWriter writer, IStreamReader reader, Record record) { Int64 position = reader.Position; reader.Position = record.Start; while (reader.Position < record.End) { writer.WriteLine(reader.ReadLine()); } reader.Position = position; }
public void WriteMatchedRecord(IStreamReader reader, Record record) { reader.VerifyThatObjectIsNotNull("Cannot write matched record. Parameter 'reader' is null."); record.VerifyThatObjectIsNotNull("Cannot write matched record. Parameter 'record' is null."); if (!this.DoWriteMatchedRecords) { throw new InvalidOperationException("Writer not set to write out matched record."); } if (this.matchedWriter == null) { this.matchedWriter = new StreamWriter(this.matchedFilePath); } this.statisticsCollector.RecordWrittenToOutputFile(this.matchedFilePath); StreamWriteOperations.WriteRecordToStream(this.matchedWriter, reader, record); }
public Record ReadRecord(IStreamReader reader) { Record record = null; var lineIDStart = (Int32)this.descriptor.LineIDStart; var lineIDLength = (Int32)this.descriptor.LineIDLength; var termStart = (Int32)this.descriptor.Term.Start; var termLength = (Int32)this.descriptor.Term.Length; while (!reader.EndOfStream) { Int64 position = reader.Position; var line = reader.ReadLine(); var lineID = line.Substring(lineIDStart, lineIDLength); if (lineID == descriptor.HeaderID) { if (record == null) { record = new Record { Start = position }; } else { record.End = position; reader.Position = position; return record; } } if (lineID == descriptor.Term.LineID) { record.Term = line.Substring(termStart, termLength); } } if (record != null) { record.End = reader.Position; } return record; }
private void WriteRecordsToFile(IStreamReader reader, Record record, String outputPrefix) { reader.VerifyThatObjectIsNotNull("Cannot write record. Parameter 'reader' is null."); record.VerifyThatObjectIsNotNull("Cannot write record. Parameter 'record' is null."); StreamWriter writer; String outputName = Path.GetDirectoryName(reader.Name) + @"\" + outputPrefix + Path.GetFileName(reader.Name); if (!writers.ContainsKey(outputName)) { writer = new StreamWriter(outputName); writers.Add(outputName, writer); } else { writer = writers[outputName]; } this.statisticsCollector.RecordWrittenToOutputFile(outputName); StreamWriteOperations.WriteRecordToStream(writer, reader, record); }
public Record ReadRecord(IStreamReader streamReader) { Record record = null; while (!streamReader.EndOfStream) { Int64 position = streamReader.Position; var line = streamReader.ReadLine(); var lineIDTerm = line.ExtractField(this.descriptor.Delimiter, this.descriptor.Qualifier, this.descriptor.LineIDIndex); if (lineIDTerm == this.descriptor.HeaderID) { if (record == null) { record = new Record { Start = position }; } else { record.End = position; streamReader.Position = position; return record; } } if (lineIDTerm != this.descriptor.Term.LineID) { continue; } record.Term = line.ExtractField(this.descriptor.Delimiter, this.descriptor.Qualifier, this.descriptor.Term.Index); } if (record != null) { record.End = streamReader.Position; } return record; }
private void WriteNothing(IStreamReader reader, Record record) { }
public void WriteUnmatchedRecord(IStreamReader reader, Record record) { WriteRecordsToFile(reader, record, "Unmatched_From_"); }