Пример #1
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);
        }
Пример #2
0
 public ShareTreeEntry(string folderName)
 {
     this.folderName = folderName;
     this.children   = new Dictionary <string, ShareTreeEntry>();
     this.share      = null;
 }