public static void CopyFile(FileInfo source, FileInfo destination,
                                    Statements.FileCopyOptions options, CopyFileHandler callback, object state)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            new FileIOPermission(FileIOPermissionAccess.Read, source.FullName).Demand();
            new FileIOPermission(FileIOPermissionAccess.Write, destination.FullName).Demand();

            CopyProgressRoutine cpr = (callback == null) ? null : new CopyProgressRoutine(
                new CopyProgressData(source, destination, callback, state).CallbackHandler);

            bool cancel = false;

            if (!NativeMethod.CopyFileEx(source.FullName, destination.FullName, cpr, IntPtr.Zero, ref cancel, (int)options))
            {
                throw new IOException(new Win32Exception().Message);
            }
        }
        public bool Resume(Bookmark bookmark, FileInfo source, FileInfo destination, Statements.FileCopyOptions options, int stepIncrement)
        {
            var context = new CopyFileContext(stepIncrement)
            {
                Instance = this,
                Bookmark = bookmark,
                Action   = CopyFileAction.Continue
            };

            if (contexts.TryAdd(bookmark.Name, context))
            {
                var action = new Action(() => ExecuteCopyFile(context, source, destination, options));
                action.BeginInvoke((a) =>
                {
                    try { action.EndInvoke(a); }
                    catch (Exception ex) { ((CopyFileContext)a.AsyncState).Exception = ex; }
                    finally { ((CopyFileContext)a.AsyncState).NotifyCompletion(); }
                }, context);
                return(true);
            }
            return(false);
        }
 public static void CopyFile(FileInfo source, FileInfo destination,
                             Statements.FileCopyOptions options, CopyFileHandler callback)
 {
     CopyFile(source, destination, options, callback, null);
 }
 public static void CopyFile(FileInfo source, FileInfo destination, Statements.FileCopyOptions options)
 {
     CopyFile(source, destination, options, null);
 }
 private void ExecuteCopyFile(CopyFileContext context, FileInfo source, FileInfo destination, Statements.FileCopyOptions options)
 {
     FileCopyHelper.CopyFile(source, destination, options,
                             new CopyFileHandler((s, t, st, sz, tr) => ((CopyFileContext)st).HandleProgress(s, t, sz, tr)), context);
 }