示例#1
0
 public virtual Task <FileSystemExitCode> GetFileAsync(RemotePath remoteName, string localName, CopyFlags copyFlags, RemoteInfo remoteInfo, Action <int> setProgress, CancellationToken token)
 {
     return(Task.FromResult(FileSystemExitCode.NotSupported));
 }
示例#2
0
 public virtual FileSystemExitCode RenMovFile(RemotePath oldName, RemotePath newName, bool move, bool overwrite, RemoteInfo remoteInfo)
 {
     return(FileSystemExitCode.NotSupported);
 }
示例#3
0
        public virtual FileSystemExitCode GetFile(RemotePath remoteName, string localName, CopyFlags copyFlags, RemoteInfo remoteInfo)
        {
            try {
                // My ThreadKeeper class is needed here because calls to ProgressProc must be made from this thread and not from some random async one.
                using (var exec = new ThreadKeeper()) {
                    void Progress(int percentDone)
                    {
                        exec.RunInMainThread(() => {
                            if (ProgressProc(remoteName, localName, percentDone))
                            {
                                exec.Cancel();
                            }
                        });
                    }

                    var ret = exec.ExecAsync(asyncFunc: (token) => GetFileAsync(remoteName, localName, copyFlags, remoteInfo, Progress, token));

                    return(ret);
                }
            }
            catch (TaskCanceledException) {
                return(FileSystemExitCode.UserAbort);
            }
            catch (OperationCanceledException) {
                return(FileSystemExitCode.UserAbort);
            }
            catch (AggregateException e) {
                if (HasCanceledException(e))
                {
                    return(FileSystemExitCode.UserAbort);
                }

                throw;
            }
        }