CmisSync.Lib.PathMatcher.PathMatcher.GetRelativeLocalPath C# (CSharp) Method

GetRelativeLocalPath() public method

Gets the relative local path.
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;
            }
        }
    }

Usage Example

Esempio n. 1
0
        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);
        }
All Usage Examples Of CmisSync.Lib.PathMatcher.PathMatcher::GetRelativeLocalPath