示例#1
0
        public static SyncPath Parse(string path)
        {
            SyncPath syncPath;

            // replace \ to /
            path = FsEntry.NormalizePath(path);

            // [UserName@]Host:Path (host 2+ symbols)
            var userHostPathRegex = new Regex("^([^@:/]+@)?([^:/]{2,}:)?(/.*)$");
            var userHostPathMatch = userHostPathRegex.Match(path);

            if (userHostPathMatch.Success)
            {
                syncPath = new SyncPath
                {
                    UserName = userHostPathMatch.Groups[1].Value.TrimEnd('@'),
                    Host     = userHostPathMatch.Groups[2].Value.TrimEnd(':'),
                    Path     = userHostPathMatch.Groups[3].Value
                };
            }
            else
            {
                // [drive:]/path (drive 1 symbol)
                var windowsPathRegex = new Regex("^([^:/]:)?(/.*)$");
                var windowsPathMatch = windowsPathRegex.Match(path);
                if (windowsPathMatch.Success)
                {
                    syncPath = new SyncPath
                    {
                        UserName = "",
                        Host     = "",
                        Path     = windowsPathMatch.Value
                    };
                }
                else
                {
                    return(null);
                }
            }


            if (!string.IsNullOrEmpty(syncPath.Host) && string.IsNullOrEmpty(syncPath.UserName))
            {
                syncPath.UserName = Environment.UserName;
            }

            return(syncPath);
        }
示例#2
0
        public static SyncOptions CreateFromSourceAndDestination(string sourcePath, string destinationPath)
        {
            if (string.IsNullOrWhiteSpace(sourcePath))
            {
                throw new SyncException($"Invalid source path: {sourcePath}");
            }

            var syncPath = SyncPath.Parse(destinationPath);

            if (syncPath == null)
            {
                throw new SyncException($"Invalid destination path: {destinationPath}");
            }

            return(new SyncOptions
            {
                Host = syncPath.Host,
                UserName = syncPath.UserName,
                DestinationPath = syncPath.Path,
                SourcePath = sourcePath
            });
        }