internal static bool FormExist(FolderUri folder) { if (folder.FolderExists) { return(Directory.GetFiles(folder.PhysicalFullDirectory, "form-schema.json").Length > 0); } return(false); }
internal static bool BuilderExist(FolderUri folder, string prefix = "") { if (folder.FolderExists) { return(File.Exists(folder.PhysicalFullDirectory + "\\" + (string.IsNullOrEmpty(prefix) ? "" : prefix + "-") + "builder.json")); } return(false); }
internal static bool BuildersExist(FolderUri folder) { if (folder.FolderExists) { return(Directory.GetFiles(folder.PhysicalFullDirectory, "*builder.json").Length > 0); } return(false); }
public FileUri(FolderUri path, string filename) : base(path.FolderPath) { if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("filename"); } _fileName = filename; }
public static FieldConfig GetIndexConfig(FolderUri folder, string collection) { try { var fb = new FormBuilder(folder); FieldConfig indexConfig = fb.BuildIndex(collection); return(indexConfig); } catch (Exception ex) { //we should log this App.Services.Logger.Error($"Error while parsing json", ex); Utils.DebuggerBreak(); return(null); } }
public static FieldConfig GetIndexConfig(FolderUri folder, string collection) { try { var fb = new FormBuilder(folder); FieldConfig indexConfig = fb.BuildIndex(collection); return(indexConfig); } catch (Exception ex) { //we should log this Log.Logger.ErrorFormat("Error while parsing json", ex); if (Debugger.IsAttached) { Debugger.Break(); } return(null); } }
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)); }
public static string ReverseMapPath(string path) { return(FolderUri.ReverseMapPath(path)); }
public static List <ListItem> GetTemplates(PortalSettings portalSettings, int moduleId, TemplateManifest selectedTemplate, string moduleSubDir) { string basePath = HostingEnvironment.MapPath(GetSiteTemplateFolder(portalSettings, moduleSubDir)); if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } List <ListItem> lst = new List <ListItem>(); foreach (var dir in Directory.GetDirectories(basePath)) { string templateCat = "Site"; string dirName = Path.GetFileNameWithoutExtension(dir); int modId = -1; if (int.TryParse(dirName, out modId)) { if (modId == moduleId) { templateCat = "Module"; } else { continue; } } string scriptName = dir; if (templateCat == "Module") { scriptName = templateCat; } else { scriptName = templateCat + ":" + scriptName.Substring(scriptName.LastIndexOf("\\") + 1); } string scriptPath = FolderUri.ReverseMapPath(dir); var item = new ListItem(scriptName, scriptPath); if (selectedTemplate != null && scriptPath.ToLowerInvariant() == selectedTemplate.Key.ToString().ToLowerInvariant()) { item.Selected = true; } lst.Add(item); } // skin basePath = HostingEnvironment.MapPath(GetSkinTemplateFolder(portalSettings, moduleSubDir)); if (Directory.Exists(basePath)) { foreach (var dir in Directory.GetDirectories(basePath)) { string templateCat = "Skin"; string scriptName = dir; scriptName = templateCat + ":" + scriptName.Substring(scriptName.LastIndexOf("\\") + 1); string scriptPath = FolderUri.ReverseMapPath(dir); var item = new ListItem(scriptName, scriptPath); if (selectedTemplate != null && scriptPath.ToLowerInvariant() == selectedTemplate.Key.ToString().ToLowerInvariant()) { item.Selected = true; } lst.Add(item); } } return(lst); }
public static List <ListItem> GetTemplatesFiles(PortalSettings portalSettings, int moduleId, TemplateManifest selectedTemplate, string moduleSubDir, FileUri otherModuleTemplate) { 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; dirs = new string[] { selDir }; } List <ListItem> lst = new List <ListItem>(); foreach (var dir in dirs) { string templateCat = "Site"; string dirName = Path.GetFileNameWithoutExtension(dir); 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 = dirName; 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)) { foreach (var dir in Directory.GetDirectories(basePath)) { string templateCat = "Skin"; var files = Directory.EnumerateFiles(dir, "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".cshtml") || s.EndsWith(".vbhtml") || s.EndsWith(".hbs")); foreach (string script in files) { string scriptName = script.Remove(script.LastIndexOf(".")).Replace(basePath, ""); if (scriptName.ToLower().EndsWith("template")) { scriptName = scriptName.Remove(scriptName.LastIndexOf("\\")); } else { scriptName = scriptName.Replace("\\", " - "); } string scriptPath = FolderUri.ReverseMapPath(script); var item = new ListItem(templateCat + " : " + scriptName, scriptPath); if (selectedTemplate != null && scriptPath.ToLowerInvariant() == selectedTemplate.Key.ToString().ToLowerInvariant()) { item.Selected = true; } lst.Add(item); } } } return(lst); }