private int CoreTransformAsync(string sourceFile, string destFile, Type sourceType, Type destType, MethodInfo method) { FileHelperAsyncEngine sourceEngine = new FileHelperAsyncEngine(sourceType); FileHelperAsyncEngine destEngine = new FileHelperAsyncEngine(destType); sourceEngine.Encoding = mSourceEncoding; destEngine.Encoding = mDestinationEncoding; sourceEngine.BeginReadFile(sourceFile); destEngine.BeginWriteFile(destFile); #if !GENERICS foreach (object record in sourceEngine) { destEngine.WriteNext(CoreTransformOneRecord(record, method)); } #else foreach (Source record in sourceEngine) { destEngine.WriteNext(CoreTransformOneRecord(record, method)); } #endif sourceEngine.Close(); destEngine.Close(); return(sourceEngine.TotalRecords); }
/// <summary> /// Reads the file1 and file2 using the recordType and write it to /// destinationFile /// </summary> public static void MergeFiles(Type recordType, string file1, string file2, string destinationFile) { using (var engineRead = new FileHelperAsyncEngine(recordType)) using (var engineWrite = new FileHelperAsyncEngine(recordType)) { engineWrite.BeginWriteFile(destinationFile); object[] readRecords; // Read FILE 1 engineRead.BeginReadFile(file1); readRecords = engineRead.ReadNexts(50); while (readRecords.Length > 0) { engineWrite.WriteNexts(readRecords); readRecords = engineRead.ReadNexts(50); } engineRead.Close(); // Read FILE 2 engineRead.BeginReadFile(file2); readRecords = engineRead.ReadNexts(50); while (readRecords.Length > 0) { engineWrite.WriteNexts(readRecords); readRecords = engineRead.ReadNexts(50); } } }
/// <summary> /// Large files are sorted in chunk then merged together in the final process /// </summary> /// <param name="queues">list of chunks to merge</param> /// <param name="destinationFile">output filename</param> internal void MergeTheChunks(SortQueue <T>[] queues, string destinationFile, string headerText, string footerText) { try { // Merge! using (var sw = new FileHelperAsyncEngine <T>(Encoding)) { sw.HeaderText = headerText; sw.FooterText = footerText; sw.BeginWriteFile(destinationFile, EngineBase.DefaultWriteBufferSize * 4); while (true) { // Find the chunk with the lowest value int lowestIndex = -1; T lowestValue = null; for (int j = 0; j < queues.Length; j++) { var current = queues[j].Current; if (current != null) { if (lowestIndex < 0 || current.CompareTo(lowestValue) < 0) { lowestIndex = j; lowestValue = current; } } } // Was nothing found in any queue? We must be done then. if (lowestIndex == -1) { break; } sw.WriteNext(lowestValue); // Remove from queue queues[lowestIndex].MoveNext(); } } } finally { for (int i = 0; i < queues.Length; i++) { queues[i].Dispose(); } } }
private int TransformAsync(string sourceFile, string destFile, Type sourceType, Type destType, MethodInfo method) { FileHelperAsyncEngine sourceEngine = new FileHelperAsyncEngine(sourceType); FileHelperAsyncEngine destEngine = new FileHelperAsyncEngine(destType); sourceEngine.Encoding = mSourceEncoding; destEngine.Encoding = mDestinationEncoding; sourceEngine.BeginReadFile(sourceFile); destEngine.BeginWriteFile(destFile); while (sourceEngine.ReadNext() != null) { destEngine.WriteNext(method.Invoke(sourceEngine.LastRecord, mEmptyArray)); } sourceEngine.EndsRead(); destEngine.EndsWrite(); return(sourceEngine.TotalRecords); }