public GetRelativeLocalPath ( string localPath ) : string | ||
localPath | string | Local path. |
return | string |
public string GetRelativeLocalPath(string localPath)
{
if (!this.CanCreateRemotePath(localPath)) {
throw new ArgumentOutOfRangeException(string.Format("Given local path \"{0}\" does not start with the correct path \"{1}\"", localPath, this.LocalTargetRootPath));
}
if (this.LocalTargetRootPath.Equals(localPath + Path.DirectorySeparatorChar.ToString())) {
return ".";
}
string relativePath = localPath.Substring(this.LocalTargetRootPath.Length);
if (relativePath.StartsWith(Path.DirectorySeparatorChar.ToString())) {
relativePath = relativePath.Substring(1);
}
if (relativePath.Length == 0) {
return ".";
} else {
return relativePath;
}
}
}
public void GetRelativePathDoesNotStartWithSlash() { this.localpath = this.localpath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? this.localpath.Substring(0, this.localpath.Length - 1) : this.localpath; var matcher = new PathMatcher(this.localpath, "/"); string folderName = "new"; Assert.That(matcher.GetRelativeLocalPath(Path.Combine(this.localpath, folderName)).StartsWith(Path.DirectorySeparatorChar.ToString()), Is.False); }