Example #1
0
        public override string ToString()
        {
            string buf;

            switch (Action)
            {
            case SynchronizationAction.UploadNew:
                buf = RemotePath.Combine(TranslateLocalPathToRemote(), "*");
                return($"{GetLocalPathString()} ==> {buf}");

            case SynchronizationAction.DownloadNew:
                buf = Path.Combine(TranslateRemotePathToLocal(), "*");
                return($"{buf} <== {GetRemotePathString()}");

            case SynchronizationAction.UploadUpdate:
                return($"{GetLocalPathString()} ==> {GetRemotePathString()}");

            case SynchronizationAction.DownloadUpdate:
                return($"{GetLocalPathString()} <== {GetRemotePathString()}");

            case SynchronizationAction.DeleteRemote:
                return($"× {GetRemotePathString()}");

            case SynchronizationAction.DeleteLocal:
                return($"× {GetLocalPathString()}");

            default:
                throw new InvalidOperationException();
            }
        }
Example #2
0
        public FileOperationEventArgs Resolve(Session session, TransferOptions options = null)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            switch (Action)
            {
            case SynchronizationAction.UploadNew:
            case SynchronizationAction.UploadUpdate:
            {
                string remoteDirectory =
                    RemotePath.TranslateLocalPathToRemote(Path.GetDirectoryName(Local.FileName), _localPath, _remotePath);
                if (!IsDirectory)
                {
                    return(session.PutFileToDirectory(Local.FileName, remoteDirectory, options: options));
                }
                else
                {
                    session.PutEntryToDirectory(Local.FileName, remoteDirectory, options: options);
                    return(null);
                }
            }

            case SynchronizationAction.DownloadNew:
            case SynchronizationAction.DownloadUpdate:
            {
                string localDirectory =
                    RemotePath.TranslateRemotePathToLocal(RemotePath.GetDirectoryName(Remote.FileName), _remotePath, _localPath);
                if (!IsDirectory)
                {
                    return(session.GetFileToDirectory(Remote.FileName, localDirectory, options: options));
                }
                else
                {
                    session.GetEntryToDirectory(Remote.FileName, localDirectory, options: options);
                    return(null);
                }
            }

            case SynchronizationAction.DeleteRemote:
                if (!IsDirectory)
                {
                    return(session.RemoveFile(Remote.FileName));
                }
                else
                {
                    session.RemoveEntry(Remote.FileName);
                    return(null);
                }

            case SynchronizationAction.DeleteLocal:
                if (!IsDirectory)
                {
                    File.Delete(Local.FileName);
                }
                else
                {
                    Directory.Delete(Local.FileName, true);
                }
                return(null);

            default:
                throw session.Logger.WriteException(new InvalidOperationException());
            }
        }
Example #3
0
 private string TranslateLocalPathToRemote()
 {
     return(RemotePath.TranslateLocalPathToRemote(Path.GetDirectoryName(Local.FileName), _localPath, _remotePath));
 }
Example #4
0
 private string TranslateRemotePathToLocal()
 {
     return(RemotePath.TranslateRemotePathToLocal(RemotePath.GetDirectoryName(Remote.FileName), _remotePath, _localPath));
 }