예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }