示例#1
0
        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;
        }
示例#2
0
        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;
        }
示例#3
0
        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);
        }
示例#4
0
        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;
        }
示例#5
0
        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);
        }
示例#6
0
        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;
        }
示例#7
0
文件: Engine.cs 项目: toyners/Siftan
 private void WriteNothing(IStreamReader reader, Record record)
 {
 }
示例#8
0
 public void WriteUnmatchedRecord(IStreamReader reader, Record record)
 {
     WriteRecordsToFile(reader, record, "Unmatched_From_");
 }