Пример #1
0
        public virtual IEnumerable <ModuleItemPath> AllThemeFiles(string moduleName, string themeName, out string themeRuleBody)
        {
            ModuleItemPath        themePath  = GetThemePath(moduleName, themeName);
            List <ModuleItemPath> themeFiles = new List <ModuleItemPath>();

            themeRuleBody = "";
            if (Directory.Exists(themePath.PhysicalPath))
            {
                var files         = Directory.EnumerateFiles(themePath.PhysicalPath, "*.css").Select(it => Path.GetFileName(it));
                var orderFilePath = Path.Combine(themePath.PhysicalPath, FileOrderHelper.OrderFileName);
                if (File.Exists(orderFilePath))
                {
                    files = FileOrderHelper.OrderFiles(orderFilePath, files);
                }

                foreach (var file in files)
                {
                    themeFiles.Add(new ModuleItemPath(themePath, file));
                }

                string themeBaseUrl = Kooboo.Web.Url.UrlUtility.ResolveUrl(themePath.VirtualPath);

                var themeRuleFiles = ThemeRuleParser.Parser.Parse(ThemeRuleBody(moduleName, themeName),
                                                                  (fileVirtualPath) => Kooboo.Web.Url.UrlUtility.Combine(themeBaseUrl, fileVirtualPath), out themeRuleBody);

                return(themeFiles.Where(it => !themeRuleFiles.Any(cf => cf.EqualsOrNullEmpty(it.EntryName, StringComparison.CurrentCultureIgnoreCase))));
            }
            return(new ModuleItemPath[0]);
        }
Пример #2
0
        public virtual void SaveFileOrders(Site site, string dirRelativePath, IEnumerable <string> filesOrder)
        {
            var baseDir = GetDirectory(site, dirRelativePath);

            FileOrderHelper.SaveFilesOrder(baseDir.PhysicalPath, filesOrder);
            FlushWebResourceCache(site, null);
        }
Пример #3
0
        public virtual IEnumerable <StyleFile> AllStylesEnumerable(Site site, string themeName)
        {
            var theme = new Theme(site, themeName);

            var fileNames = EnumerateCssFilesWithPath(site, themeName);

            fileNames = FileOrderHelper.OrderFiles(GetOrderFile(site, themeName), fileNames);

            return(fileNames.Select(it => new StyleFile(theme, it).LastVersion()));
        }
Пример #4
0
 private string GetOrderFile(Site site, string themeName)
 {
     while (site != null)
     {
         var orderFile = FileOrderHelper.GetOrderFile(new Theme(site, themeName).PhysicalPath);
         if (File.Exists(orderFile))
         {
             return(orderFile);
         }
         site = site.Parent;
     }
     return(null);
 }
Пример #5
0
        public virtual IEnumerable <FileEntry> GetFiles(Site site, string dirRelativePath)
        {
            IComparer <FileResource> comparer = null;
            Site recursiveSite = site;

            while (comparer == null && recursiveSite != null)
            {
                var dir = GetDirectory(recursiveSite, dirRelativePath);
                comparer      = FileOrderHelper.GetComparer(FileOrderHelper.GetOrderFile(dir.PhysicalPath));
                recursiveSite = recursiveSite.Parent;
            }

            ICollection <FileEntry> list;

            if (comparer == null)
            {
                list = new List <FileEntry>();
            }
            else
            {
                list = new SortedSet <FileEntry>(comparer);
            }
            recursiveSite = site;
            while (recursiveSite != null)
            {
                var dir = GetDirectory(recursiveSite, dirRelativePath);
                if (dir.Exists())
                {
                    var files       = EnumerateFiles(dir.PhysicalPath);
                    var fileEntries = files.Select(it => new FileInfo(Path.Combine(dir.PhysicalPath, it)))
                                      .Where(it => !Path.GetFileName(it.FullName).Equals(FileOrderHelper.OrderFileName, StringComparison.OrdinalIgnoreCase))
                                      .Select(it => new FileEntry(GetRootDir(recursiveSite), GetRelativePath(dirRelativePath, it.Name))
                    {
                        FileSize      = it.Length,
                        Name          = it.Name,
                        FileExtension = it.Extension,
                        FileName      = Path.GetFileName(it.FullName),
                        CreateDate    = it.LastWriteTimeUtc
                    });
                    foreach (var fileEntry in fileEntries)
                    {
                        if (!list.Contains(fileEntry, new FileEntry.FileNameEqualityComparer()))
                        {
                            list.Add(fileEntry);
                        }
                    }
                }
                recursiveSite = recursiveSite.Parent;
            }
            return(list);
        }
Пример #6
0
        public virtual IEnumerable <ModuleItemPath> AllScripts(string moduleName)
        {
            ModuleItemPath scriptsPath = new ModuleItemPath(moduleName, "Scripts");

            if (Directory.Exists(scriptsPath.PhysicalPath))
            {
                var files         = Directory.EnumerateFiles(scriptsPath.PhysicalPath, "*.js").Select(it => Path.GetFileName(it));
                var orderFilePath = Path.Combine(scriptsPath.PhysicalPath, FileOrderHelper.OrderFileName);
                if (File.Exists(orderFilePath))
                {
                    files = FileOrderHelper.OrderFiles(orderFilePath, files);
                }
                foreach (var file in files)
                {
                    yield return(new ModuleItemPath(scriptsPath, file));
                }
            }
        }
Пример #7
0
        public virtual IEnumerable <FileEntry> GetFiles(Site site, string dirRelativePath)
        {
            var dir = GetDirectory(site, dirRelativePath);

            if (dir.Exists())
            {
                var files = EnumerateFiles(dir.PhysicalPath);
                files = FileOrderHelper.OrderFiles(FileOrderHelper.GetOrderFile(dir.PhysicalPath), files);
                return(files.Select(it => new FileInfo(Path.Combine(dir.PhysicalPath, it)))
                       .Select(it => new FileEntry(GetRootDir(site), GetRelativePath(dirRelativePath, it.Name))
                {
                    FileSize = it.Length,
                    Name = it.Name,
                    FileExtension = it.Extension,
                    FileName = it.FullName,
                    CreateDate = it.LastWriteTimeUtc
                }));
            }
            return(new FileEntry[0]);
        }