public void StartAsyncTask(object workItemState) { IKernel kernel = KernelManager.GetKernel(); IConfig config = kernel.Get <IConfig>(); IPathHelper pathHelper = kernel.Get <IPathHelper>(); FullPathCleaner cleaner = new FullPathCleaner(s => Context.Server.MapPath(s)); string localPath = cleaner.CleanPath(Context.Request.Url.AbsolutePath); string repoFilePath = pathHelper.ConvertMdUriToLocalPath(Context.Request.Url.AbsolutePath, s => cleaner.CleanPath(s)); string fileToReturn = File.Exists(localPath) ? localPath : repoFilePath; // see if the file exists, if so we need to write it to the response if (File.Exists(fileToReturn)) { var objImage = System.Drawing.Bitmap.FromFile(fileToReturn); MemoryStream objMemoryStream = new MemoryStream(); objImage.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Png); byte[] imageContent = new byte[objMemoryStream.Length]; objMemoryStream.Position = 0; objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length); Context.Response.ContentType = "image/png"; Context.Response.BinaryWrite(imageContent); } else { Context.Response.StatusCode = 404; } Completed = true; Callback(this); }
public string UpdateRepo() { FullPathCleaner cleaner = new FullPathCleaner(s => Server.MapPath(s)); string repoFolder = cleaner.CleanPath(Config.GetConfigValue(CommonConsts.AppSettings.MarkdownSourceFolder)); new FaintingGoat(this.Config, repoFolder).Update(); return "Updating"; }
private MarkdownPageModel MakeMarkDownViewModel(string mdroute) { FullPathCleaner cleaner = new FullPathCleaner(s => Server.MapPath(s)); string localPath = this.PathHelper.ConvertMdUriToLocalPath(mdroute, s => cleaner.CleanPath(s)); if (!System.IO.File.Exists(localPath)) { throw new FileNotFoundException(string.Format("Markdown file not found at [{0}]", localPath)); } string md = this.ContentRepo.GetContentFor(new Uri(localPath)); MarkdownPageModel pm = new MarkdownPageModel { FaintingGoatWebTitle = this.GetTitle(), HtmlToRender = this.MarkdownToHtml.ConvertToHtml(md), HeaderHtml = this.GetHeaderHtml(), FooterHtml = this.GetFooterHtml() }; return pm; }
private void UpdateGitRepo(IKernel kernel) { if (kernel == null) { throw new ArgumentNullException("kernel"); } IConfig config = kernel.Get<IConfig>(); // first check to see if we should automaticall update or not bool autoUpadate = bool.Parse(config.GetConfigValue(CommonConsts.AppSettings.GitAutoUpdateOnAppStart, false, "true")); if (autoUpadate) { FullPathCleaner cleaner = new FullPathCleaner(s => Server.MapPath(s)); string repoPath = cleaner.CleanPath( config.GetConfigValue( CommonConsts.AppSettings.MarkdownSourceFolder)); new FaintingGoat(kernel.Get<IConfig>(), repoPath).Update(); } }
protected string GetDefaultDocumentFullLocalPath() { IList<string> defaultDocListConfig = this.Config.GetList(CommonConsts.AppSettings.DefaultDocList, defaultValue: CommonConsts.AppSettings.DefaultValues.DefaultDocList); string result = null; FullPathCleaner cleaner = new FullPathCleaner(s => Server.MapPath(s)); for (int i = 0; i < defaultDocListConfig.Count; i++) { string fileName = defaultDocListConfig[i]; string fileNameLocalpath = this.PathHelper.ConvertMdUriToLocalPath( fileName, s => cleaner.CleanPath(s)); if (System.IO.File.Exists(fileNameLocalpath)) { result = fileNameLocalpath; break; } } return result; }
protected string GetHtmlFromFirstFound(IEnumerable<string> filesToCheck) { if (filesToCheck == null) { throw new ArgumentNullException("filesToCheck"); } string result = null; List<string> filesToTryRelative = new List<string>(filesToCheck); List<string>filesToTryAbsolute = new List<string>(); FullPathCleaner cleaner = new FullPathCleaner(s => Server.MapPath(s)); filesToTryRelative.ForEach(file=>{ filesToTryAbsolute.Add(this.PathHelper.ConvertMdUriToLocalPath(file,(s)=>cleaner.CleanPath(s))); }); string currentFile = null; foreach (var nf in filesToTryAbsolute) { if (System.IO.File.Exists(nf)) { currentFile = nf; break; } } if (currentFile != null) { string md = this.ContentRepo.GetContentFor(new Uri(currentFile)); result = this.MarkdownToHtml.ConvertToHtml(md); } return result; }
public void StartAsyncTask(object workItemState) { IKernel kernel = KernelManager.GetKernel(); IConfig config = kernel.Get<IConfig>(); IPathHelper pathHelper = kernel.Get<IPathHelper>(); FullPathCleaner cleaner = new FullPathCleaner(s => Context.Server.MapPath(s)); string localPath = cleaner.CleanPath(Context.Request.Url.AbsolutePath); string repoFilePath = pathHelper.ConvertMdUriToLocalPath(Context.Request.Url.AbsolutePath, s => cleaner.CleanPath(s)); string fileToReturn = File.Exists(localPath) ? localPath : repoFilePath; // see if the file exists, if so we need to write it to the response if (File.Exists(fileToReturn)) { var objImage = System.Drawing.Bitmap.FromFile(fileToReturn); MemoryStream objMemoryStream = new MemoryStream(); objImage.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Png); byte[] imageContent = new byte[objMemoryStream.Length]; objMemoryStream.Position = 0; objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length); Context.Response.ContentType = "image/png"; Context.Response.BinaryWrite(imageContent); } else { Context.Response.StatusCode = 404; } Completed = true; Callback(this); }