コード例 #1
0
        public static TokenizedLocalPath Combine(TokenizedLocalPath parentPath, TokenizedLocalPath relativePath)
        {
            if (relativePath == null || relativePath.IsEmpty())
            {
                return(parentPath);
            }

            string[] parentElems   = parentPath.pathElements;
            string[] relativeElems = relativePath.pathElements;
            string[] newElems      = new string[parentElems.Length + relativeElems.Length];
            Array.Copy(parentElems, newElems, parentElems.Length);
            Array.Copy(relativeElems, 0, newElems, parentElems.Length, relativeElems.Length);
            return(new TokenizedLocalPath(newElems));
        }
コード例 #2
0
        public static string ComposeLink(LinkFormat linkFormat, string host, Share share, TokenizedLocalPath shareRelativePath, char systemSeparator)
        {
            StringBuilder sb = new StringBuilder();

            if (linkFormat == LinkFormat.Smb)
            {
                sb.Append("smb://");
                sb.Append(Uri.EscapeUriString(host));
                sb.Append('/');
                sb.Append(share.NameEscaped);
                if (shareRelativePath != null && !shareRelativePath.IsEmpty())
                {
                    sb.Append('/');
                    shareRelativePath.Format(sb, true, '/');
                }
            }
            else if (linkFormat == LinkFormat.Unc)
            {
                sb.Append("\\\\");
                sb.Append(host);
                sb.Append('\\');
                sb.Append(share.Name);
                if (shareRelativePath != null && !shareRelativePath.IsEmpty())
                {
                    sb.Append('\\');
                    shareRelativePath.Format(sb, false, '\\');
                }
            }
            else if (linkFormat == LinkFormat.UncEscaped)
            {
                sb.Append("\\\\");
                sb.Append(Uri.EscapeUriString(host));
                sb.Append('\\');
                sb.Append(share.NameEscaped);
                if (shareRelativePath != null && !shareRelativePath.IsEmpty())
                {
                    sb.Append('\\');
                    shareRelativePath.Format(sb, true, '\\');
                }
            }
            else if (linkFormat == LinkFormat.File)
            {
                sb.Append("file://");
                sb.Append(Uri.EscapeUriString(host));
                sb.Append('/');
                sb.Append(share.NameEscaped);
                if (shareRelativePath != null && !shareRelativePath.IsEmpty())
                {
                    sb.Append('/');
                    shareRelativePath.Format(sb, true, '/');
                }
            }
            else if (linkFormat == LinkFormat.LocalFile)
            {
                sb.Append("file://");
                if (share != null)
                {
                    share.LocalPath.Format(sb, true, '/');
                }
                if (shareRelativePath != null && !shareRelativePath.IsEmpty())
                {
                    if (share != null)
                    {
                        sb.Append('/');
                    }
                    shareRelativePath.Format(sb, true, '/');
                }
            }
            else if (linkFormat == LinkFormat.LocalPath)
            {
                if (share != null)
                {
                    share.LocalPath.Format(sb, false, systemSeparator);
                }
                if (shareRelativePath != null && !shareRelativePath.IsEmpty())
                {
                    if (share != null)
                    {
                        sb.Append(systemSeparator);
                    }
                    shareRelativePath.Format(sb, false, systemSeparator);
                }
            }
            else
            {
                throw new Exception("unexpected link format: " + linkFormat);
            }

            string link = sb.ToString();

            return(link);
        }