Exemple #1
0
        public FoldersWidget(jQueryObject parent, FolderJson[] folders, string folderPath)
        {
            string separator = Environment.ServerType == ServerType.AspNet ? "\\" : "/";
            attachedObject = Template.Get("client", "folders-table", true).AppendTo(parent).Attribute("data-path", folderPath);

            ((List<FolderJson>)(object)folders).Sort(delegate(FolderJson a, FolderJson b)
            {
                return Utility.NaturalCompare(a.name, b.name);
            });

            foreach (FolderJson folder in folders)
            {
                string subfolderPath = folderPath + separator + folder.name;
                jQueryObject row = Template.Get("client", "folders-trow", true).AppendTo(attachedObject.Children());
                jQueryObject btn = jQuery.Select(".folders-btn", row).Click(FolderButtonClick).Attribute("data-path", subfolderPath).Text(folder.count == 0 ? folder.name : String.Format("{0} ({1})", folder.name, folder.count)).Attribute("data-count", folder.count.ToString());
                jQueryObject expandBtn = jQuery.Select(".folders-expand-btn", row).Click(ExpandButtonClick);

                if (folder.subfolders != null && folder.subfolders.Length > 0)
                {
                    expandBtn.Attribute("data-path", subfolderPath).Children().AddClass("icon-plus");
                    new FoldersWidget(jQuery.Select(".folders-tcell", row), folder.subfolders, subfolderPath);
                }
            }

            if (folderPath != "")
            {
                attachedObject.Hide();
                if (Settings.UseAnimation)
                {
                    attachedObject.AddClass("fade");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Process folder cache and save it in database
        /// </summary>
        public void ProcessFolderCache()
        {
            if (CacheStatus == 0 || CacheStatus == 2)
            {
                return;
            }

            CacheStatus = 2;
            Save();

            FolderJson folder = new FolderJson();
            folder.name = Name;
            folder.subfolders = new FolderJson[] { };
            int collectionPathLength = Path.Length;
            string separator = "\\";

            Dictionary<string, FolderJson> folderDictionary = new Dictionary<string, FolderJson>();
            Dictionary<string, object>[] resultSet = Database.Select("manga", "`cid`=" + Database.Quote(Id.ToString()), null, null, "`path`");
            folderDictionary[""] = folder;

            foreach (Dictionary<string, object> result in resultSet)
            {
                string path = Convert.ToString(result["path"]).Substring(collectionPathLength);
                string lastFolderPath = null;
                int i = 0, j = 0;

                while ((i = path.IndexOf(separator, j)) != -1)
                {
                    string relativePath = lastFolderPath = path.Substring(0, i);
                    if (!folderDictionary.ContainsKey(relativePath.ToLowerInvariant()))
                    {
                        FolderJson subfolder = new FolderJson();
                        subfolder.name = path.Substring(j, i - j);
                        subfolder.subfolders = new FolderJson[] { };
                        folderDictionary[relativePath.ToLowerInvariant()] = subfolder;

                        int k;
                        FolderJson parentFolder = folderDictionary[(k = relativePath.LastIndexOf(separator)) == -1 ? "" : relativePath.Substring(0, k).ToLowerInvariant()];
                        FolderJson[] newSubfolders = new FolderJson[parentFolder.subfolders.Length + 1];
                        Array.Copy(parentFolder.subfolders, newSubfolders, parentFolder.subfolders.Length);
                        newSubfolders[parentFolder.subfolders.Length] = subfolder;
                        parentFolder.subfolders = newSubfolders;
                    }

                    j = i + 1;
                }

                if (lastFolderPath != null)
                {
                    folderDictionary[lastFolderPath.ToLowerInvariant()].count++;
                }
            }

            Dictionary<string, object> cacheData = new Dictionary<string, object>();
            cacheData.Add("id", Id);
            cacheData.Add("content", _folderCache = JsonConvert.SerializeObject(folder));
            Database.Replace("foldercache", cacheData);

            CacheStatus = 0;
            Save();
        }