예제 #1
0
        private void CheckTemplateForRefresh(ThemedTemplate template)
        {
            FileInfo fi = new FileInfo(template.Path);

            if (fi.LastWriteTime > template.FileLastModified)
            {
                template.Html             = LoadHtml(template.Path);
                template.FileLastModified = fi.LastWriteTime;
            }
            foreach (string theme in template.Themes.Keys)
            {
                CheckThemeForRefresh(template.Themes[theme]);
            }
        }
예제 #2
0
        private string GetTemplateHtml(TemplateFolder folder, ThemedTemplate template, string theme)
        {
            string body = "{content}";

            if (template.MasterTemplateName != "")
            {
                ThemedTemplate master = (from m in folder.Masters where m.Name.ToLower() == template.MasterTemplateName.ToLower() select m).SingleOrDefault();
                if (master != null)
                {
                    body = GetTemplateHtml(folder, master, theme);
                }
            }
            return(body.Replace("{content}", template.GetHtml(theme)));
        }
예제 #3
0
        private TemplateFolder LoadTemplateFolder(XElement el, string path)
        {
            TemplateFolder  tf         = new TemplateFolder(el.Attribute("name").Value, path);
            XNamespace      ns         = el.GetDefaultNamespace();
            List <XElement> subFolders = el.Elements(ns + "templateFolder").ToList();

            foreach (XElement f in subFolders)
            {
                string name = f.Attribute("name").Value;
                tf.Folders.Add(LoadTemplateFolder(f, string.Format("{0}/{1}", path, name)));
            }
            //load themes
            XElement elThemes = el.Element(ns + "themes");

            if (elThemes != null)
            {
                List <XElement> themes = elThemes.Elements(ns + "theme").ToList();
                foreach (XElement th in themes)
                {
                    tf.Themes.Add(th.Attribute("name").Value);
                }
            }
            List <XElement> masters = el.Elements(ns + "master").ToList();

            foreach (XElement m in masters)
            {
                ThemedTemplate template = LoadTemplate(tf.Path, m, tf.Themes);
                if (template != null)
                {
                    tf.Masters.Add(template);
                }
            }

            List <XElement> templates = el.Elements(ns + "template").ToList();

            foreach (XElement t in templates)
            {
                ThemedTemplate template = LoadTemplate(tf.Path, t, tf.Themes);
                if (template != null)
                {
                    tf.Templates.Add(template);
                }
            }
            return(tf);
        }
예제 #4
0
        private ThemedTemplate LoadTemplate(string folderPath, XElement el, List <string> themes)
        {
            ThemedTemplate template = new ThemedTemplate(el.Attribute("name").Value,
                                                         el.Attribute("path").Value,
                                                         "",
                                                         el.Attribute("themesEnabled") == null ? true : bool.Parse(el.Attribute("themesEnabled").Value),
                                                         el.Attribute("master") == null ? "" : el.Attribute("master").Value,
                                                         el.Attribute("path").Value);

            string filename = Path.Combine(_templateFolderDir.FullName, template.Path);
            //Path.Combine(filename, template.Path);
            FileInfo tempFile = new FileInfo(filename);

            if (tempFile.Exists)
            {
                template.FileLastModified = tempFile.LastWriteTime;
                template.FilePath         = tempFile.FullName;
                //template.Path = folderPath + template.Path;
                template.Html = LoadHtml(template.FilePath);

                //load themes
                foreach (string theme in themes)
                {
                    string        themeDirPath = Path.Combine(tempFile.Directory.FullName, "_themes\\" + theme);
                    DirectoryInfo themeDir     = new DirectoryInfo(themeDirPath);
                    if (themeDir.Exists)
                    {
                        FileInfo themeFile = new FileInfo(Path.Combine(themeDir.FullName, template.Name + ".htm"));
                        if (themeFile.Exists)
                        {
                            Template themedTemplate = new Template(template.Name, template.Path, LoadHtml(themeFile.FullName), template.MasterTemplateName, filename);
                            themedTemplate.FileLastModified = themeFile.LastWriteTime;
                            themedTemplate.FilePath         = themeFile.FullName;
                            template.Themes.Add(theme, themedTemplate);
                        }
                    }
                }
                return(template);
            }
            return(null);
        }
예제 #5
0
        private string GetTemplateHtml(string path, string theme)
        {
            if (path.EndsWith("/"))
            {
                throw new ArgumentException(string.Format("Invalid path - ends with /.  path=[{0}]", path));
            }
            TemplateFolder folder       = FindFolder(path, Root);
            string         templateName = path;

            if (templateName.IndexOf("/") > 0)
            {
                templateName = templateName.Substring(templateName.LastIndexOf("/") + 1);
            }
            ThemedTemplate template = (from t in folder.Templates where t.Name.ToLower() == templateName.ToLower() select t).SingleOrDefault();

            if (template == null)
            {
                throw new ArgumentException(string.Format("Could not find template. name=[{0}] path=[{1}]", templateName, path));
            }
            CheckTemplateForRefresh(template);
            return(GetTemplateHtml(folder, template, theme));
        }