Exemplo n.º 1
0
        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);
        }
        private int CoreTransformAsync(TextReader sourceFile, StreamWriter destFile)
        {
            var sourceEngine = new FileHelperAsyncEngine <TSource>();
            var destEngine   = new FileHelperAsyncEngine <TDestination>();

            sourceEngine.ErrorMode = this.ErrorMode;
            destEngine.ErrorMode   = this.ErrorMode;

            mSourceErrorManager      = sourceEngine.ErrorManager;
            mDestinationErrorManager = destEngine.ErrorManager;

            sourceEngine.Encoding = mSourceEncoding;
            destEngine.Encoding   = mDestinationEncoding;

            sourceEngine.BeginReadStream(sourceFile);
            destEngine.BeginWriteStream(destFile);

            foreach (var record in sourceEngine)
            {
                destEngine.WriteNext(record.TransformTo());
            }

            sourceEngine.Close();
            destEngine.Close();

            return(sourceEngine.TotalRecords);
        }
Exemplo n.º 3
0
        /// <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();
                }
            }
        }
Exemplo n.º 4
0
        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);
        }