Ejemplo n.º 1
0
 /// <summary>
 /// Prompt the user if no number of files exists.
 /// </summary>
 private static void EnsureGoodNumFilesArg(SplitJob job)
 {
     if (job.NumFilesToCreate == 0)
     {
         string numFiles = PromptUserForAnswer(UserMessages.AskHowManyFiles);
         job.NumFilesToCreate = NumberOrAppDefault(numFiles);
         Console.WriteLine(UserMessages.MsgAttemptingToSplit.FormatWith(job.NumFilesToCreate));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// If the file to split is missing, prompt the user. Clean the arg of delimiters. Ensure that the file exists.
        /// </summary>
        /// <param name="job">The job to analyze</param>
        private static void EnsureGoodFileArg(SplitJob job)
        {
            if (job.FileToSplit.IsNullOrEmpty())
            {
                job.FileToSplit = PromptUserForAnswer(UserMessages.AskWhichFile);
            }
            job.FileToSplit = job.FileToSplit.Trim(FilePathDelimiters);

            if (File.Exists(job.FileToSplit) == false)
            {
                ShowMsgAndQuit(UserMessages.CannotFindFile);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// If the file to split is missing, prompt the user. Clean the arg of delimiters. Ensure that the file exists.
        /// </summary>
        /// <param name="job">The job to analyze</param>
        private static void EnsureGoodFileArg(SplitJob job)
        {
            if (job.FileToSplit.IsNullOrEmpty())
            {
                job.FileToSplit = PromptUserForAnswer(UserMessages.AskWhichFile);
            }
            job.FileToSplit = job.FileToSplit.Trim(FilePathDelimiters);

            if (File.Exists(job.FileToSplit) == false)
            {
                ShowMsgAndQuit(UserMessages.CannotFindFile);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Analyze the input from the user. Ensure all args are valid to continue. If any args are invalid, then show a message to the user and cause the app to exit.
        /// </summary>
        /// <param name="args">All the args given by the user</param>
        /// <returns>An object populated with the file to split, and the number of files to split to.</returns>
        static SplitJob BuildSplitJob(string[] args)
        {
            var job = new SplitJob();

            if (args.FirstOrDefault() != null)
            {
                job.FileToSplit = args.First();
            }
            if (args.LastOrDefault() != null)
            {
                job.NumFilesToCreate = NumberOrAppDefault(args.LastOrDefault());
            }

            EnsureGoodFileArg(job);
            EnsureGoodNumFilesArg(job);
            return(job);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Analyze the input from the user. Ensure all args are valid to continue. If any args are invalid, then show a message to the user and cause the app to exit.
        /// </summary>
        /// <param name="args">All the args given by the user</param>
        /// <returns>An object populated with the file to split, and the number of files to split to.</returns>
        static SplitJob BuildSplitJob(string[] args)
        {
            var job = new SplitJob();

            if (args.FirstOrDefault() != null)
            {
                job.FileToSplit = args.First();

            }
            if (args.LastOrDefault() != null)
            {
                job.NumFilesToCreate = NumberOrAppDefault(args.LastOrDefault());
            }

            EnsureGoodFileArg(job);
            EnsureGoodNumFilesArg(job);
            return job;
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            HandleHelp(args);
            SplitJob job = BuildSplitJob(args);
            var      sw  = Stopwatch.StartNew();

            var fileOps = new FileOps(job);

            try
            {
                fileOps.SplitSourceFileToMultiples();
                sw.Stop();

                Console.WriteLine(UserMessages.TimeSpent.FormatWith(sw.Elapsed.TotalSeconds));
            }
            catch (IOException ioe)
            {
                ShowMsgAndQuit(ioe.ToString());
            }
            ShowMsgAndQuit(UserMessages.CompletedFileCreation.FormatWith(fileOps.NumFilesCreated));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Read the source file and split into a files.
 /// </summary>
 /// <param name="job"></param>
 public FileOps(SplitJob job)
 {
     this.Job = job;
     AllLinesToWrite = ReadFile(Job.FileToSplit);
     Job.TotalLines = AllLinesToWrite.Count();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Read the source file and split into a files.
 /// </summary>
 /// <param name="job"></param>
 public FileOps(SplitJob job)
 {
     this.Job        = job;
     AllLinesToWrite = ReadFile(Job.FileToSplit);
     Job.TotalLines  = AllLinesToWrite.Count();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Prompt the user if no number of files exists.
 /// </summary>
 private static void EnsureGoodNumFilesArg(SplitJob job)
 {
     if (job.NumFilesToCreate == 0)
     {
         string numFiles = PromptUserForAnswer(UserMessages.AskHowManyFiles);
         job.NumFilesToCreate = NumberOrAppDefault(numFiles);
         Console.WriteLine(UserMessages.MsgAttemptingToSplit.FormatWith(job.NumFilesToCreate));
     }
 }