Exemplo n.º 1
0
        public static int GetAllChildrenCount(string currentFolder = null)
        {
            int Count = 0;

            try
            {
                List <KeyValuePair <string, string> > folders = new List <KeyValuePair <string, string> >();
                List <KeyValuePair <string, string> > files   = new List <KeyValuePair <string, string> >();
                HttpServerUtility server = HttpContext.Current.Server;

                if (string.IsNullOrEmpty(currentFolder))
                {
                    folders.AddRange(new[]
                    {
                        "Admin",
                        "Controls",
                        "DesktopModules",
                        "Install",
                        "Providers"
                    }.Select(s => new KeyValuePair <string, string>(s, "_/" + s)));
                }
                else
                {
                    string foldername = currentFolder;
                    if (currentFolder.IndexOf("_/", StringComparison.Ordinal) == 0)
                    {
                        foldername = foldername.Substring(2);
                    }
                    IEnumerable <KeyValuePair <string, string> > directories    = LanguagesManager.GetResxDirectories(server.MapPath("~/" + foldername));
                    IEnumerable <KeyValuePair <string, string> > directoryFiles = LanguagesManager.GetResxFiles(server.MapPath("~/" + foldername));
                    if (currentFolder.IndexOf("_/", StringComparison.Ordinal) == 0)
                    {
                        folders.AddRange(directories.Select(
                                             s => new KeyValuePair <string, string>(s.Key, currentFolder + "/" + s.Key)));
                        files.AddRange(directoryFiles.Select(
                                           f => new KeyValuePair <string, string>(f.Key, currentFolder + "/" + f.Key)));
                    }
                    else
                    {
                        folders.AddRange(directories);
                        files.AddRange(directoryFiles);
                    }
                }
                Count = folders.Count + files.Count;
            }
            catch (Exception ex)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
            }
            return(Count);
        }
Exemplo n.º 2
0
        public static ActionResult GetSubRootResources(string currentFolder)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                List <KeyValuePair <string, string> > folders = new List <KeyValuePair <string, string> >();
                List <KeyValuePair <string, string> > files   = new List <KeyValuePair <string, string> >();
                HttpServerUtility server = HttpContext.Current.Server;

                if (string.IsNullOrEmpty(currentFolder))
                {
                    folders.AddRange(new[]
                    {
                        "Admin",
                        "Controls",
                        "DesktopModules",
                        "Install",
                        "Providers"
                    }.Select(s => new KeyValuePair <string, string>(s, "_/" + s)));
                }
                else
                {
                    string foldername = currentFolder;
                    if (currentFolder.IndexOf("_/", StringComparison.Ordinal) == 0)
                    {
                        foldername = foldername.Substring(2);
                    }
                    IEnumerable <KeyValuePair <string, string> > directories    = LanguagesManager.GetResxDirectories(server.MapPath("~/" + foldername));
                    IEnumerable <KeyValuePair <string, string> > directoryFiles = LanguagesManager.GetResxFiles(server.MapPath("~/" + foldername));
                    if (currentFolder.IndexOf("_/", StringComparison.Ordinal) == 0)
                    {
                        folders.AddRange(directories.Select(
                                             s => new KeyValuePair <string, string>(s.Key, currentFolder + "/" + s.Key)));
                        files.AddRange(directoryFiles.Select(
                                           f => new KeyValuePair <string, string>(f.Key, currentFolder + "/" + f.Key)));
                    }
                    else
                    {
                        folders.AddRange(directories);
                        files.AddRange(directoryFiles);
                    }
                }
                List <TreeView> TreeViews = new List <TreeView>();
                foreach (KeyValuePair <string, string> item in folders)
                {
                    TreeViews.Add(new TreeView {
                        Name = item.Key, Value = item.Value, Type = "folder", childrenCount = GetAllChildrenCount(item.Value)
                    });
                }

                foreach (KeyValuePair <string, string> item in files)
                {
                    TreeViews.Add(new TreeView {
                        Name = item.Key, Value = item.Value, Type = "file"
                    });
                }

                actionResult.IsSuccess = true;
                actionResult.Data      = TreeViews;
            }
            catch (Exception ex)
            {
                actionResult.AddError("", "", ex);
            }
            return(actionResult);
        }