Exemple #1
0
        /// <summary>
        /// Given the large collection of strings read from disk, split into the appropriate number of files. If the source file is empty, tilt immediately.
        /// </summary>
        public void SplitSourceFileToMultiples()
        {
            if (AllLinesToWrite.Any() == false)
            {
                return;
            }
            string header = AllLinesToWrite.First();

            foreach (int i in Enumerable.Range(1, Job.NumFilesToCreate))
            {
                FileInfo baseFile = new FileInfo(Job.FileToSplit);
                string   newFile  = Path.Combine(baseFile.DirectoryName, "{0}-{1}".FormatWith(i, baseFile.Name));

                //always skip the header, the batches previously taken + 1 for the header.
                //First iteration, skip none.
                int skip = ((i - 1) * Job.LinesPerFile + 1);

                List <string> newFileContents = AllLinesToWrite.Skip(skip).Take(Job.LinesPerFile).ToList();

                //write the file when there are new contents to be written. we may have the case where we don't need to create empty files if the user
                //has specified more files than we need.
                if (newFileContents.Any())
                {
                    newFileContents.Insert(0, header);
                    File.WriteAllLines(newFile, newFileContents);
                    NumFilesCreated++;
                }
            }
        }
        /// <summary>
        /// Given the large collection of strings read from disk, split into the appropriate number of files. If the source file is empty, tilt immediately.
        /// </summary>
        public void SplitSourceFileToMultiples()
        {
            if (AllLinesToWrite.Any() == false)
            {
                return;
            }
            string header = AllLinesToWrite.First();

            foreach (int fileNumber in Enumerable.Range(1, Job.NumFilesToCreate))
            {
                WriteItemsToNewFile(header, fileNumber);
            }
        }