/// <summary> /// Builds the sorter. /// </summary> /// <returns>a <see cref="Sorter{T}"/></returns> private Sorter<byte[]> BuildSorter() { Logger.Debug("Building sorter"); var sorter = new Sorter<byte[]>(); var formatterParser = new FormatterParser { Encoding = Encoding }; sorter.InputFiles = Input.Select(r => r.GetFileInfo()).ToList(); if (Output.Count == 1) { var outputFiles = new List<IOutputFile<byte[]>>(); var outputFile = new LegacyOutputFile { Output = Output[0].GetFileInfo() }; if (!string.IsNullOrWhiteSpace(Outrec)) { outputFile.Formatter = formatterParser.GetFormatter(Outrec); } outputFiles.Add(outputFile); sorter.OutputFiles = outputFiles; } if (Output.Count > 1) { var outfilParser = new OutfilParser { Encoding = Encoding, SortEncoding = SortEncoding }; var outputFiles = outfilParser.GetOutputFiles(Outfils); if (Output.Count != outputFiles.Count) { throw new SortException("The number of output files must match the number of outfil configurations."); } for (var i = 0; i < Output.Count; i++) { outputFiles[i].Output = Output[i].GetFileInfo(); } sorter.OutputFiles = outputFiles; } if (RecordLength > 0 || Separator == null) { sorter.RecordAccessorFactory = new BlockAccessorFactory { RecordLength = RecordLength }; } else { sorter.RecordAccessorFactory = new SeparatorAccessorFactory { Separator = Encoding.GetBytes(Separator) }; } if (!string.IsNullOrWhiteSpace(SortCard)) { var comparerParser = new ComparerParser { Encoding = Encoding, SortEncoding = SortEncoding }; sorter.Comparer = comparerParser.GetComparer(SortCard); } if (!string.IsNullOrWhiteSpace(Include) || !string.IsNullOrWhiteSpace(Omit)) { var filterParser = new FilterParser { Encoding = Encoding, SortEncoding = SortEncoding }; sorter.Filter = filterParser.GetFilter(Include, Omit); } if (SkipDuplicates) { sorter.Sum = new SkipSum<byte[]>(); } if (!string.IsNullOrWhiteSpace(Sum)) { var sumParser = new SumParser { Encoding = Encoding }; sorter.Sum = sumParser.GetSum(Sum); } if (!string.IsNullOrWhiteSpace(Inrec)) { sorter.InputFormatter = formatterParser.GetFormatter(Inrec); } if (MaxInMemorySize > 0) { sorter.MaxInMemorySize = MaxInMemorySize; } sorter.HeaderSize = HeaderSize; return sorter; }
/// <summary> /// Builds the sorter. /// </summary> /// <returns>a <see cref="Sorter{T}"/></returns> private Sorter<byte[]> BuildSorter() { Logger.Debug("Building sorter"); var sorter = new Sorter<byte[]>(); if (RecordLength > 0 || Separator == null) { sorter.RecordAccessorFactory = new BlockAccessorFactory { RecordLength = RecordLength }; } else { sorter.RecordAccessorFactory = new SeparatorAccessorFactory { Separator = Encoding.GetBytes(Separator) }; } if (!string.IsNullOrWhiteSpace(SortCard)) { var comparerParser = new ComparerParser { Encoding = Encoding, SortEncoding = SortEncoding }; sorter.Comparer = comparerParser.GetComparer(SortCard); } if (!string.IsNullOrWhiteSpace(Include) || !string.IsNullOrWhiteSpace(Omit)) { var filterParser = new FilterParser { Encoding = Encoding, SortEncoding = SortEncoding }; sorter.Filter = filterParser.GetFilter(Include, Omit); } if (SkipDuplicates) { sorter.Sum = new SkipSum<byte[]>(); } if (!string.IsNullOrWhiteSpace(Sum)) { var sumParser = new SumParser { Encoding = Encoding }; sorter.Sum = sumParser.GetSum(Sum); } var formatterParser = new FormatterParser { Encoding = Encoding }; if (!string.IsNullOrWhiteSpace(Inrec)) { sorter.InputFormatter = formatterParser.GetFormatter(Inrec); } if (!string.IsNullOrWhiteSpace(Outrec)) { sorter.OutputFormatter = formatterParser.GetFormatter(Outrec); } if (MaxInMemorySize > 0) { sorter.MaxInMemorySize = MaxInMemorySize; } sorter.HeaderSize = HeaderSize; return sorter; }
/// <summary> /// Builds the sorter. /// </summary> /// <returns>a <see cref="Sorter{T}"/></returns> public SplitSorter<byte[]> BuildSorter() { Logger.Debug("Building sorter for ExtendedSort"); var sorter = new SplitSorter<byte[]>(); if (RecordLength > 0 || Separator == null) { sorter.RecordAccessorFactory = new BlockAccessorFactory { RecordLength = RecordLength }; } else { sorter.RecordAccessorFactory = new SeparatorAccessorFactory { Separator = Encoding.GetBytes(Separator) }; } if (!string.IsNullOrWhiteSpace(SortCard)) { var comparerParser = new ComparerParser { Encoding = Encoding, SortEncoding = SortEncoding }; sorter.Comparer = comparerParser.GetComparer(SortCard); } if (SkipDuplicates) { sorter.Sum = new SkipSum<byte[]>(); } if (!string.IsNullOrWhiteSpace(Sum)) { var sumParser = new SumParser { Encoding = Encoding }; sorter.Sum = sumParser.GetSum(Sum); } var formatterParser = new FormatterParser { Encoding = Encoding }; if (!string.IsNullOrWhiteSpace(Inrec)) { sorter.InputFormatter = formatterParser.GetFormatter(Inrec); } if (!string.IsNullOrWhiteSpace(Outrec)) { sorter.OutputFormatter = formatterParser.GetFormatter(Outrec); } if (!string.IsNullOrWhiteSpace(Include) || !string.IsNullOrWhiteSpace(Omit)) { var filterParser = new FilterParser { Encoding = Encoding, SortEncoding = SortEncoding }; sorter.Filter = filterParser.GetFilter(Include, Omit); } sorter._outputWriters = new List<OutputFileFormat<byte[]>>(); int count = 0; foreach (var file in OutputFiles) { Logger.Debug("Building sorter - fileformat " + ++count); OutputFileFormat<byte[]> writer = new OutputFileFormat<byte[]>(); if (!string.IsNullOrWhiteSpace(file.Outrec)) { Logger.Debug("Building sorter - fileformat outrec = " + file.Outrec); writer.OutputFormatter = formatterParser.GetFormatter(file.Outrec); } if (!string.IsNullOrWhiteSpace(file.Include) || !string.IsNullOrWhiteSpace(file.Omit)) { Logger.Debug("Building sorter - fileformat Include = " + file.Include); var filterParser = new FilterParser { Encoding = Encoding, SortEncoding = SortEncoding }; writer.Filter = filterParser.GetFilter(file.Include, file.Omit); } SectionFormatter<string> format = new SectionFormatter<string> { Encoding = Encoding }; if (!string.IsNullOrWhiteSpace(file.Section)) { Logger.Debug("Building sorter - fileformat Section = " + file.Section); writer.Section = format.ParseSection(file.Section, Encoding, file.OutputFileRecordLength); } if (!string.IsNullOrWhiteSpace(file.Header1)) { Logger.Debug("Building sorter - fileformat header1 = " + file.Header1); writer.Header1 = format.ParseElement(file.Header1, Encoding, file.OutputFileRecordLength); } if (!string.IsNullOrWhiteSpace(file.Header2)) { Logger.Debug("Building sorter - fileformat header2 = " + file.Header1); writer.Header2 = format.ParseElement(file.Header2, Encoding, file.OutputFileRecordLength); } if (!string.IsNullOrWhiteSpace(file.Trailer1)) { Logger.Debug("Building sorter - fileformat header1 = " + file.Header1); writer.Trailer1 = format.ParseElement(file.Trailer1, Encoding, file.OutputFileRecordLength); } if (!string.IsNullOrWhiteSpace(file.Trailer2)) { Logger.Debug("Building sorter - fileformat header2 = " + file.Header1); writer.Trailer2 = format.ParseElement(file.Trailer2, Encoding, file.OutputFileRecordLength); } writer.MaxPageLines = (file.Lines == 0) ? 60 : file.Lines; sorter._outputWriters.Add(writer); } if (MaxInMemorySize > 0) { sorter.MaxInMemorySize = MaxInMemorySize; } sorter.HeaderSize = HeaderSize; return sorter; }