Esempio n. 1
0
        /// <summary>
        /// Performs cleanup for shorten folders which referenced link items were already deleted.
        /// </summary>
        protected virtual void CleanupObsoleteShortens()
        {
            foreach (string directory in Directory.GetDirectories(_rootPath))
            {
                string path = FileUtil.MakePath(directory, "link");
                if (File.Exists(path))
                {
                    string linkContents = File.ReadAllText(path);

                    ItemReference itemReference = ItemReference.Parse(linkContents.Replace('\\', '/'));
                    if (itemReference != null && itemReference.GetItem() == null)
                    {
                        FileUtil.DeleteDirectory(directory, true);
                    }
                    else
                    {
                        // clean directories with only the link file, even if the link is valid (no items exist under the link)
                        // (if the children length is 1 and we got here we know the link file exists and thus it MUST be the 1 item)
                        if (Directory.GetFileSystemEntries(directory).Length == 1)
                        {
                            Directory.Delete(directory, true);
                        }
                    }
                }
                else
                {
                    // clean empty directories
                    if (Directory.GetFileSystemEntries(directory).Length == 0)
                    {
                        Directory.Delete(directory);
                    }
                }
            }
        }
Esempio n. 2
0
        protected internal virtual bool TryGetItem(out TItem item)
        {
            item = ItemReference.GetItem();

            return(item != null);
        }