예제 #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)
        {
            FileHelperEngine engine = new FileHelperEngine(recordType);

            ArrayList arr = new ArrayList();

            arr.AddRange(engine.ReadFile(file1));
            arr.AddRange(engine.ReadFile(file2));

            object[] res = (object[])arr.ToArray(recordType);
            arr = null; // <- better performance (allow the GC to collect it)

            CommonEngine.SortRecords(res);

            engine.WriteFile(destFile, res);
            return(res);
        }
        /// <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)
        {
            FileHelperEngine engine = new FileHelperEngine(recordType);

            var list = engine.ReadFileAsList(file1);

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

            var res = list.ToArray();

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

            CommonEngine.SortRecords(res);

            engine.WriteFile(destFile, res);
            return(res);
        }
예제 #3
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)
        {
            FileHelperEngine engine = new FileHelperEngine(recordType);

            ArrayList arr = new ArrayList();

            arr.AddRange(engine.ReadFile(file1));
            arr.AddRange(engine.ReadFile(file2));

            object[] res = (object[])arr.ToArray(recordType);
            arr = null; // <- better performance (memory)

            CommonEngine.SortRecordsByField(res, field, ascending);

            engine.WriteFile(destFile, res);

            return(res);
        }