Ejemplo n.º 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.LoadManifestFileFromCacheOrDisk(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);
                }
            }
        }
Ejemplo n.º 2
0
        public static string GetDefaultTemplate(string physicalFolder)
        {
            string    template = "";
            FolderUri folder   = new FolderUri(FolderUri.ReverseMapPath(physicalFolder));
            var       manifest = ManifestUtils.LoadManifestFileFromCacheOrDisk(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));
        }
Ejemplo n.º 3
0
        public static List <ListItem> ListOfTemplatesFiles(PortalSettings portalSettings, int moduleId, TemplateManifest selectedTemplate, string moduleSubDir, FileUri otherModuleTemplate, bool advanced = true)
        {
            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     = dir.Substring(basePath.Length);
                int    modId       = -1;
                if (Int32.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.LoadManifestFileFromCacheOrDisk(manifestFileUri);
                        if (manifest != null && manifest.HasTemplates)
                        {
                            manifestTemplateFound = true;
                            if (advanced || !manifest.Advanced)
                            {
                                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))
                                    {
                                        if (advanced)
                                        {
                                            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 (!advanced)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                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
            //if (!string.IsNullOrEmpty(portalSettings.ActiveTab.SkinPath))
            {
                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.LoadManifestFileFromCacheOrDisk(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))
                                        {
                                            if (advanced)
                                            {
                                                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 (!advanced)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        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);
        }
        private static string[] GetDirs(TemplateManifest selectedTemplate, FileUri otherModuleTemplate, bool advanced, string basePath, string[] dirs, List <ListItem> lst, string folderType)
        {
            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 = folderType;

                    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.LoadManifestFileFromCacheOrDisk(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))
                                    {
                                        if (advanced)
                                        {
                                            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 (!advanced)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    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(dirs);
        }