示例#1
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            var      settings = ModuleContext.OpenContentSettings();
            Manifest manifest = settings.Manifest;

            if (settings.TemplateKey.Extention != ".manifest")
            {
                manifest = ManifestUtils.GetFileManifest(settings.TemplateKey.TemplateDir);
            }

            if (manifest != null)
            {
                string addEditControl = manifest.AdditionalEditControl;
                if (!string.IsNullOrEmpty(addEditControl))
                {
                    var contr            = LoadControl(addEditControl);
                    PortalModuleBase mod = contr as PortalModuleBase;
                    if (mod != null)
                    {
                        mod.ModuleConfiguration = this.ModuleConfiguration;
                        mod.ModuleId            = this.ModuleId;
                        mod.LocalResourceFile   = this.LocalResourceFile;
                    }
                    this.Controls.Add(contr);
                }
            }
        }
示例#2
0
        public static string GetDefaultTemplate(string physicalFolder)
        {
            string    template = "";
            FolderUri folder   = new FolderUri(FolderUri.ReverseMapPath(physicalFolder));
            var       manifest = ManifestUtils.GetFileManifest(folder);

            if (manifest != null && manifest.HasTemplates)
            {
                //get the requested template key
                //var templateManifest = manifest.Templates.First().Value;
                //var templateUri = new FileUri(folder, templateManifest.Main.Template);
                template = folder.FolderPath + "/" + manifest.Templates.First().Key;
            }
            else
            {
                foreach (var item in Directory.GetFiles(physicalFolder))
                {
                    string fileName = Path.GetFileName(item).ToLower();
                    if (fileName == "template.hbs")
                    {
                        template = item;
                        break;
                    }
                    else if (fileName == "template.cshtml")
                    {
                        template = item;
                        break;
                    }
                    if (fileName.EndsWith(".hbs"))
                    {
                        template = item;
                    }
                    if (fileName.EndsWith(".cshtml"))
                    {
                        template = item;
                    }
                }
            }
            return(FileUri.ReverseMapPath(template));
        }
示例#3
0
        public static List <ListItem> GetTemplatesFiles(PortalSettings portalSettings, int moduleId, TemplateManifest selectedTemplate, string moduleSubDir, FileUri otherModuleTemplate)
        {
            //bool otherModuleSkinTemplate = otherModuleTemplate != null && otherModuleTemplate.PhysicalFilePath.Contains(HostingEnvironment.MapPath(GetSkinTemplateFolder(portalSettings, moduleSubDir)));
            string basePath = HostingEnvironment.MapPath(GetSiteTemplateFolder(portalSettings, moduleSubDir));

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }
            var dirs = Directory.GetDirectories(basePath);

            if (otherModuleTemplate != null)
            {
                var selDir = otherModuleTemplate.PhysicalFullDirectory;
                if (!dirs.Contains(selDir))
                {
                    selDir = Path.GetDirectoryName(selDir);
                }
                if (dirs.Contains(selDir))
                {
                    dirs = new string[] { selDir }
                }
                ;
                else
                {
                    dirs = new string[] { }
                };
            }
            List <ListItem> lst = new List <ListItem>();

            foreach (var dir in dirs)
            {
                string templateCat = "Site";
                //string dirName = Path.GetFileNameWithoutExtension(dir);
                string dirName = dir.Substring(basePath.Length);
                int    modId   = -1;
                if (int.TryParse(dirName, out modId))
                {
                    // if numeric directory name --> module template
                    if (modId == moduleId)
                    {
                        // this module -> show
                        templateCat = "Module";
                    }
                    else
                    {
                        // if it's from an other module -> don't show
                        continue;
                    }
                }

                IEnumerable <string> files         = Directory.EnumerateFiles(dir, "*.*", SearchOption.AllDirectories);
                IEnumerable <string> manifestfiles = files.Where(s => s.EndsWith("manifest.json"));
                var manifestTemplateFound          = false;
                if (manifestfiles.Any())
                {
                    foreach (string manifestFile in manifestfiles)
                    {
                        FileUri manifestFileUri = FileUri.FromPath(manifestFile);
                        var     manifest        = ManifestUtils.GetFileManifest(manifestFileUri);
                        if (manifest != null && manifest.HasTemplates)
                        {
                            manifestTemplateFound = true;
                            foreach (var template in manifest.Templates)
                            {
                                FileUri templateUri  = new FileUri(manifestFileUri.FolderPath, template.Key);
                                string  templateName = Path.GetDirectoryName(manifestFile).Substring(basePath.Length).Replace("\\", " / ");
                                if (!string.IsNullOrEmpty(template.Value.Title))
                                {
                                    templateName = templateName + " - " + template.Value.Title;
                                }
                                var item = new ListItem((templateCat == "Site" ? "" : templateCat + " : ") + templateName, templateUri.FilePath);
                                if (selectedTemplate != null && templateUri.FilePath.ToLowerInvariant() == selectedTemplate.Key.ToString().ToLowerInvariant())
                                {
                                    item.Selected = true;
                                }
                                lst.Add(item);
                            }
                        }
                    }
                }
                if (!manifestTemplateFound)
                {
                    IEnumerable <string> scriptfiles = files.Where(s => s.EndsWith(".cshtml") || s.EndsWith(".vbhtml") || s.EndsWith(".hbs"));
                    foreach (string script in scriptfiles)
                    {
                        FileUri templateUri = FileUri.FromPath(script);

                        string scriptName = script.Remove(script.LastIndexOf(".")).Replace(basePath, "");
                        if (templateCat == "Module")
                        {
                            if (scriptName.ToLower().EndsWith("template"))
                            {
                                scriptName = "";
                            }
                            else
                            {
                                scriptName = scriptName.Substring(scriptName.LastIndexOf("\\") + 1);
                            }
                        }
                        else if (scriptName.ToLower().EndsWith("template"))
                        {
                            scriptName = scriptName.Remove(scriptName.LastIndexOf("\\"));
                        }
                        else
                        {
                            scriptName = scriptName.Replace("\\", " - ");
                        }

                        var item = new ListItem((templateCat == "Site" ? "" : templateCat + " : ") + scriptName, templateUri.FilePath);
                        if (selectedTemplate != null && templateUri.FilePath.ToLowerInvariant() == selectedTemplate.Key.ToString().ToLowerInvariant())
                        {
                            item.Selected = true;
                        }
                        lst.Add(item);
                    }
                }
            }
            // skin
            basePath = HostingEnvironment.MapPath(GetSkinTemplateFolder(portalSettings, moduleSubDir));
            if (Directory.Exists(basePath))
            {
                dirs = Directory.GetDirectories(basePath);
                if (otherModuleTemplate != null /*&& */)
                {
                    var selDir = otherModuleTemplate.PhysicalFullDirectory;
                    if (!dirs.Contains(selDir))
                    {
                        selDir = Path.GetDirectoryName(selDir);
                    }
                    if (dirs.Contains(selDir))
                    {
                        dirs = new string[] { selDir }
                    }
                    ;
                    else
                    {
                        dirs = new string[] { }
                    };
                }

                foreach (var dir in dirs)
                {
                    string templateCat = "Skin";

                    IEnumerable <string> files         = Directory.EnumerateFiles(dir, "*.*", SearchOption.AllDirectories);
                    IEnumerable <string> manifestfiles = files.Where(s => s.EndsWith("manifest.json"));
                    var manifestTemplateFound          = false;

                    if (manifestfiles.Any())
                    {
                        foreach (string manifestFile in manifestfiles)
                        {
                            FileUri manifestFileUri = FileUri.FromPath(manifestFile);
                            var     manifest        = ManifestUtils.GetFileManifest(manifestFileUri);
                            if (manifest != null && manifest.HasTemplates)
                            {
                                manifestTemplateFound = true;
                                foreach (var template in manifest.Templates)
                                {
                                    FileUri templateUri  = new FileUri(manifestFileUri.FolderPath, template.Key);
                                    string  templateName = Path.GetDirectoryName(manifestFile).Substring(basePath.Length).Replace("\\", " / ");
                                    if (!string.IsNullOrEmpty(template.Value.Title))
                                    {
                                        templateName = templateName + " - " + template.Value.Title;
                                    }
                                    var item = new ListItem((templateCat == "Site" ? "" : templateCat + " : ") + templateName, templateUri.FilePath);
                                    if (selectedTemplate != null && templateUri.FilePath.ToLowerInvariant() == selectedTemplate.Key.ToString().ToLowerInvariant())
                                    {
                                        item.Selected = true;
                                    }
                                    lst.Add(item);
                                }
                            }
                        }
                    }
                    if (!manifestTemplateFound)
                    {
                        var scriptfiles =
                            Directory.EnumerateFiles(dir, "*.*", SearchOption.AllDirectories)
                            .Where(s => s.EndsWith(".cshtml") || s.EndsWith(".vbhtml") || s.EndsWith(".hbs"));
                        foreach (string script in scriptfiles)
                        {
                            string scriptName = script.Remove(script.LastIndexOf(".")).Replace(basePath, "");
                            if (scriptName.ToLower().EndsWith("template"))
                            {
                                scriptName = scriptName.Remove(scriptName.LastIndexOf("\\"));
                            }
                            else
                            {
                                scriptName = scriptName.Replace("\\", " - ");
                            }

                            FileUri templateUri = FileUri.FromPath(script);
                            var     item        = new ListItem(templateCat + " : " + scriptName, templateUri.FilePath);
                            if (selectedTemplate != null &&
                                templateUri.FilePath.ToLowerInvariant() == selectedTemplate.Key.ToString().ToLowerInvariant())
                            {
                                item.Selected = true;
                            }
                            lst.Add(item);
                        }
                    }
                }
            }
            return(lst);
        }