Esempio n. 1
0
        /// <summary>
        /// Sorts a delimited file given a alphanumeric key.
        /// </summary>
        /// <param name="sourcefilePath">Full path and file name of file to be sorted</param>
        /// <param name="dataFilter">Function to filter out a data line (true to include data or false to exclude data)</param>
        /// <param name="dataTransportation">Define the data transportation method.</param>
        /// <param name="destinationFolder">Folder path where sorted and/or duplicate files will be place. (Uses folder of sourcefilePath when null)</param>
        /// <param name="delimiter">Character delimiter</param>
        /// <param name="hasHeader">Does the file have a header row</param>
        /// <param name="keyColumn">The zero based column number to be used as the key to sort</param>
        /// <param name="keyLength">The length of the key right justified with zeros if less than length specified</param>
        /// <param name="isUniqueKey">If true duplicates will not be included in the sorted file.</param>
        /// <param name="returnDuplicates">If true duplicates will be written out to file only if isUniqueKey is true.</param>
        /// <param name="sortDir">The sort direction of the key.</param>
        /// <param name="progress">A method to report progress</param>
        /// <param name="maxBatchSize">Control the max insert batch size</param>
        public static SortResults SortDelimitedByAlphaNumKey(string sourcefilePath,
                                   Func<string[], string, bool> dataFilter = null,
                                   DataTransportation dataTransportation = null,
                                   string destinationFolder = null,
                                   string delimiter = Constants.Delimiters.Comma,
                                   bool hasHeader = true,
                                   int keyColumn = 0,
                                   int keyLength = 15,
                                   bool isUniqueKey = false,
                                   bool returnDuplicates = false,
                                   SortDirection sortDir = SortDirection.Ascending,
                                   Action<SortProgress> progress = null,
                                   int maxBatchSize = 250000)

        {
            SortDefinitions sortDefs = new SortDefinitions();
            sortDefs.Add(new SortDefinition { DataType = KeyType.AlphaNumeric, Direction = sortDir, IsUniqueKey = isUniqueKey });

            return SortDelimitedByKeyDefCore(sourcefilePath: sourcefilePath,
                                            sortDefinitions: sortDefs,
                                            setKeys: (fields, line, keyValues) => keyValues[0] = fields[keyColumn].PadKeyWithZero(keyLength),
                                            dataFilter: dataFilter,
                                            destinationFolder: destinationFolder,
                                            delimiter: delimiter,
                                            hasHeader: hasHeader,
                                            returnDuplicates: returnDuplicates,
                                            dataTransportation: dataTransportation,
                                            progress: progress,
                                            maxBatchSize: maxBatchSize);
        }
Esempio n. 2
0
        /// <summary>
        /// Sorts a fixed width file given a alphanumeric key.
        /// </summary>
        /// <param name="sourcefilePath">Full path and file name of file to be sorted</param>
        /// <param name="getKey">Function to construct the key</param>
        /// <param name="dataFilter">Function to filter out a data line (true to include data or false to exclude data)</param>
        /// <param name="dataTransportation">Define the data transportation method.</param>
        /// <param name="destinationFolder">Folder path where sorted and/or duplicate files will be place. (Uses folder of sourcefilePath when null)</param>
        /// <param name="hasHeader">Does the file have a header row</param>
        /// <param name="isUniqueKey">If true duplicates will not be included in the sorted file.</param>
        /// <param name="returnDuplicates">If true duplicates will be written out to file only if isUniqueKey is true.</param>
        /// <param name="sortDir">The sort direction of the key.</param>
        /// <param name="progress">A method to report progress</param>
        /// <param name="maxBatchSize">Control the max insert batch size</param>
        public static SortResults SortFixedWidthByAlphaNumKey(string sourcefilePath,
                                   Func<string, string> getKey,
                                   Func<string, bool> dataFilter = null,
                                   DataTransportation dataTransportation = null,
                                   string destinationFolder = null,
                                   bool hasHeader = true,
                                   bool isUniqueKey = false,
                                   bool returnDuplicates = false,
                                   SortDirection sortDir = SortDirection.Ascending,
                                   Action<SortProgress> progress = null,
                                   int maxBatchSize = 250000)

        {
            SortDefinitions sortDefs = new SortDefinitions();
            sortDefs.Add(new SortDefinition { DataType = KeyType.AlphaNumeric, Direction = sortDir, IsUniqueKey = isUniqueKey });

            return SortFile.SortFixedWidthByKeyDefinitions(
                                   sourcefilePath: sourcefilePath,
                                   sortDefinitions: sortDefs,
                                   dataFilter: dataFilter,
                                   setKeys: (line, keyValues) => keyValues[0] = getKey(line),
                                   dataTransportation: dataTransportation,
                                   destinationFolder: destinationFolder,
                                   hasHeader: hasHeader,
                                   returnDuplicates: returnDuplicates,
                                   progress: progress,
                                   maxBatchSize: maxBatchSize);


        }