Beispiel #1
0
        /// <summary>
        /// Merge the contents of 2 files and write them sorted to a
        /// destination file.
        /// </summary>
        /// <param name="recordType">The record Type.</param>
        /// <param name="file1">File with contents to be merged.</param>
        /// <param name="file2">File with contents to be merged.</param>
        /// <param name="destFile">The destination file.</param>
        /// <returns>The merged and sorted records.</returns>
        public static object[] MergeAndSortFile(Type recordType, string file1, string file2, string destFile)
        {
            var engine = new FileHelperEngine(recordType);

#pragma warning disable 618
            var list = engine.ReadFileAsList(file1);
            list.AddRange(engine.ReadFileAsList(file2));
#pragma warning restore 618

            var res = list.ToArray();
            list = null; // <- better performance (memory)

            SortRecords(res);

            engine.WriteFile(destFile, res);
            return(res);
        }
Beispiel #2
0
        /// <summary>
        /// Merge the contents of 2 files and write them sorted to a destination file.
        /// </summary>
        /// <param name="recordType">The record Type.</param>
        /// <param name="file1">File with contents to be merged.</param>
        /// <param name="file2">File with contents to be merged.</param>
        /// <param name="field">The name of the field used to sort the records.</param>
        /// <param name="ascending">Indicate the order of sort.</param>
        /// <param name="destFile">The destination file.</param>
        /// <returns>The merged and sorted records.</returns>
        public static object[] MergeAndSortFile(Type recordType, string file1, string file2, string destFile, string field, bool ascending)
        {
            var engine = new FileHelperEngine(recordType);

            var list = engine.ReadFileAsList(file1);

            list.AddRange(engine.ReadFileAsList(file2));

            var res = list.ToArray();

            list = null; // <- better performance (memory)

            SortRecordsByField(res, field, ascending);

            engine.WriteFile(destFile, res);

            return(res);
        }