public string GetString(RenderContext context, string RelativeUrl) { RelativeUrl = CleanQuestionMark(RelativeUrl); string fullfilename = SearchRoute(context, RelativeUrl); if (!string.IsNullOrEmpty(fullfilename)) { return(GetText(context, option, RelativeUrl, fullfilename)); // return System.IO.File.ReadAllText(fullfilename); } else { // try to render the directory. string root = option.GetDiskRoot(context); if (!string.IsNullOrEmpty(option.StartPath) && !RelativeUrl.ToLower().StartsWith(option.StartPath.ToLower())) { root = RenderHelper.CombinePath(root, option.StartPath); } string localpath = RenderHelper.CombinePath(root, RelativeUrl); return(DirectoryRender.Resolve(localpath, root)); } }
private string SearchRoute(RenderContext context, string RelativeUrl) { string root = option.GetDiskRoot(context); if (!string.IsNullOrEmpty(option.StartPath) && !RelativeUrl.ToLower().StartsWith(option.StartPath.ToLower())) { root = RenderHelper.CombinePath(root, option.StartPath); } string result = null; bool isDirectory = false; if (RelativeUrl.EndsWith("/")) { isDirectory = true; } else { string diskpath = RenderHelper.CombinePath(root, RelativeUrl); isDirectory = System.IO.Directory.Exists(diskpath); } if (isDirectory) { foreach (var item in this.StartPageNames) { string relativeurl = RenderHelper.CombinePath(RelativeUrl, item); string fullpath = RenderHelper.CombinePath(root, relativeurl); result = FindFile(fullpath, option.Extensions); if (string.IsNullOrWhiteSpace(result)) { result = ExtendViewSearch(root, relativeurl, option.ViewFolders, option.Extensions); } if (!string.IsNullOrEmpty(result)) { return(result); } } } else { string fullpath = RenderHelper.CombinePath(root, RelativeUrl); result = FindFile(fullpath, option.Extensions); if (string.IsNullOrWhiteSpace(result)) { result = ExtendViewSearch(root, RelativeUrl, option.ViewFolders, option.Extensions); } } return(result); }
private string ExtendViewSearch(string root, string relative, List <string> searchfolders, List <string> extensions) { foreach (var folder in searchfolders) { string viewrelative = "/" + folder + relative; viewrelative = RenderHelper.CombinePath(root, viewrelative); var result = FindFile(viewrelative, extensions); if (!string.IsNullOrEmpty(result)) { return(result); } } return(null); }
public string GetRoot(RenderContext context) { if (option != null) { string root = this.option.GetDiskRoot(context); if (!string.IsNullOrEmpty(option.StartPath)) { root = RenderHelper.CombinePath(root, option.StartPath); } return(root); } return(null); }
private string FindFileSearch(RenderContext context, string RelativeUrl, List <string> searchfolders, List <string> extensions) { RelativeUrl = CleanQuestionMark(RelativeUrl); string root = GetRoot(context); string route = null; if (RelativeUrl.StartsWith("/") || RelativeUrl.StartsWith("\\")) { RelativeUrl = RelativeUrl.Substring(1); } route = "/" + RelativeUrl; string fullpath = RenderHelper.CombinePath(root, route); string Filename = FindFile(fullpath, extensions); if ((searchfolders == null) || (!string.IsNullOrEmpty(Filename))) { return(Filename); } return(ExtendViewSearch(root, route, searchfolders, extensions)); }