Exemple #1
0
        private async Task InternalDirectoryCopy(string source, string destination, CopyBehavior behavior)
        {
            foreach (var file in Directory.GetFiles(source, "*.*", SearchOption.AllDirectories))
            {
                var str = file.PathRelativeTo(source);

                await InternalFileCopy(file, destination.AppendPath(str), behavior).ConfigureAwait(false);
            }
        }
        private void internalDirectoryCopy(string source, string destination, CopyBehavior behavior)
        {
            var files = Directory.GetFiles(source, "*.*", SearchOption.AllDirectories);

            files.Each(file =>
            {
                var relative = file.PathRelativeTo(source);
                internalFileCopy(file, destination.AppendPath(relative), behavior);
            });
        }
 public void Copy(string source, string destination, CopyBehavior behavior)
 {
     if (IsFile(source))
     {
         internalFileCopy(source, destination, behavior);
     }
     else
     {
         internalDirectoryCopy(source, destination, behavior);
     }
 }
 public CopyContextMenu(AsyncDataGridViewModel advModel, CopyBehavior behavior)
 {
     this.advModel = advModel;
     this.behavior = behavior;
     switch (behavior)
     {
     case CopyBehavior.Selection:
         Header           = "Copy Selection";
         InputGestureText = "Ctrl+C";
         return;
     }
 }
        private void internalFileCopy(string source, string destination, CopyBehavior behavior)
        {
            var fileName = Path.GetFileName(source);

            var fullSourcePath = Path.GetFullPath(source);
            var fullDestPath   = Path.GetFullPath(destination);


            var isFile = destinationIsFile(destination);

            var destinationDir = fullDestPath;

            if (isFile)
            {
                destinationDir = Path.GetDirectoryName(fullDestPath);
            }

            CreateDirectory(destinationDir);

            if (!isFile) //aka its a directory
            {
                fullDestPath = Combine(fullDestPath, fileName);
            }

            var overwrite = behavior == CopyBehavior.overwrite;

            if (!overwrite && FileExists(fullDestPath))
            {
                return;
            }

            try
            {
                File.Copy(fullSourcePath, fullDestPath, overwrite);
            }
            catch (Exception ex)
            {
                var msg = "Was trying to copy '{0}' to '{1}' and encountered an error. :(".ToFormat(fullSourcePath,
                                                                                                    fullDestPath);
                throw new Exception(msg, ex);
            }
        }
Exemple #6
0
        private async Task InternalFileCopy(string source, string destination, CopyBehavior behavior)
        {
            var fileName = Path.GetFileName(source);
            var fullPath = Path.GetFullPath(source);
            var str      = Path.GetFullPath(destination);
            var flag     = DestinationIsFile(destination);
            var path     = str;

            if (flag)
            {
                path = Path.GetDirectoryName(str);
            }

            await CreateDirectory(path).ConfigureAwait(false);

            if (!flag)
            {
                str = Combine(str, fileName);
            }

            var overwrite = behavior == CopyBehavior.Overwrite;

            if (!overwrite)
            {
                if (FileExists(str))
                {
                    return;
                }
            }

            try
            {
                File.Copy(fullPath, str, overwrite);
            }
            catch (Exception ex)
            {
                throw new Exception($"Was trying to copy '{fullPath}' to '{str}' and encountered an error. :(", ex);
            }
        }
Exemple #7
0
 public Task Copy(string source, string destination, CopyBehavior behavior)
 {
     return(IsFile(source) ? InternalFileCopy(source, destination, behavior) : InternalDirectoryCopy(source, destination, behavior));
 }