Example #1
0
        private static void Copy(CopyOptions copyOptions)
        {
            if (false == File.Exists(copyOptions.SourceFilename))
            {
                throw new FileNotFoundException("Copy source was not found", copyOptions.SourceFilename);
            }

            var localCopy = new LocalCopy();
            var stopwatch = new Stopwatch();
            if (copyOptions.MeasureTime)
            {
                stopwatch.Start();
            }

            if (copyOptions.Resumable)
            {
                CopyResumableFile(localCopy, copyOptions);
            }
            else
            {
                CopyFile(localCopy, copyOptions);
            }

            if (copyOptions.MeasureTime)
            {
                stopwatch.Stop();
                Console.WriteLine(string.Format("Copy took {0} minutes ({1} seconds)",
                    stopwatch.Elapsed.TotalMinutes, stopwatch.Elapsed.TotalSeconds));
            }
        }
Example #2
0
 private static CopyOptions ParseArgs(string[] args)
 {
     var copyOptions = new CopyOptions();
     copyOptions.SourceFilename = args[0];
     OptionValidators.ValidatePath("source filename", copyOptions.SourceFilename);
     copyOptions.TargetFilename = args[1];
     OptionValidators.ValidatePath("target filename", copyOptions.TargetFilename);
     Program.CopyOptionDescriptorSet.Apply(copyOptions, args.Skip(2));
     return copyOptions;
 }
Example #3
0
 private static void CopyResumableFile(LocalCopy localCopy, CopyOptions copyOptions)
 {
     FileMode fileMode = FileMode.OpenOrCreate;
     if (copyOptions.Overwrite)
     {
         fileMode = FileMode.Create;
     }
     if (copyOptions.Threaded)
     {
         localCopy.ThreadedCopyResumableFile(copyOptions.SourceFilename, copyOptions.TargetFilename,
             fileMode, copyOptions.BufferCount, copyOptions.BufferSize);
     }
     else
     {
         localCopy.CopyResumableFile(copyOptions.SourceFilename, copyOptions.TargetFilename,
             fileMode, copyOptions.BufferSize);
     }
 }