예제 #1
0
        /// <summary>
        /// Find a share that allows access to this local path.
        /// Note that it's possible for more than one share to match a specific path.
        /// In such case the most specific share will be chosen.
        /// For example if share A has local path /home/user and share B has local
        /// path /home/user/downloads, for localPath='/home/user/downloads/file.mp4'
        /// the method returns B.
        /// </summary>
        /// <returns>The parent share or null.</returns>
        /// <param name="localPath">Local absolute path of a file or directory.
        /// It doesn't necessarily need to exist, but needs to be a valid path.
        /// It should be a plain path, not an URI or UNC path and shouldn't be
        /// escaped in any way.
        /// </param>
        public Share FindParentShare(TokenizedLocalPath localPath)
        {
            Share result = null;

            ShareTreeEntry treeElem = treeRoot;

            foreach (string elem in localPath)
            {
                string elemCased = caseSensitiveFileSystem ? elem : elem.ToLowerInvariant();

                ShareTreeEntry childElem = null;
                treeElem.children.TryGetValue(elemCased, out childElem);

                if (childElem != null)
                {
                    if (childElem.share != null)
                    {
                        // Found a matching share! But continue searching in case
                        // there's another, more specific share.
                        result = childElem.share;
                    }

                    // Continue diving into the tree.
                    treeElem = childElem;
                }
                else
                {
                    // No more children.
                    break;
                }
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Add the share to this list. If for any reason there's already another
        /// share for this local path, the new share replaces it.
        /// </summary>
        /// <param name="share">The share to add.</param>
        public void AddOrReplace(Share share)
        {
            if (!sharesByName.ContainsKey(share.Name))
            {
                sharesByName.Remove(share.Name);
            }
            sharesByName.Add(share.Name, share);

            TokenizedLocalPath path     = share.LocalPath;
            ShareTreeEntry     treeElem = treeRoot;

            foreach (string elem in share.LocalPath)
            {
                string elemCased = caseSensitiveFileSystem ? elem : elem.ToLowerInvariant();

                ShareTreeEntry childElem = null;
                treeElem.children.TryGetValue(elemCased, out childElem);

                if (childElem == null)
                {
                    childElem = new ShareTreeEntry(elem);
                    treeElem.children.Add(elemCased, childElem);
                }

                treeElem = childElem;
            }
            treeElem.share = share;
        }