public ActionResult CodeOnly(string id) { ShowSnippetViewModel model = new ShowSnippetViewModel(this); model.AppUserState = this.AppUserState; // Since this is our default handler anything invalid will // run through here. No path - go to new if (string.IsNullOrEmpty(id) || id == "0") { return(this.New()); } using (busCodeSnippet busSnippet = new busCodeSnippet()) { if (busSnippet.Load(id) == null) { ErrorDisplay.ShowError("Invalid snippet id specified."); model.Snippet = new CodeSnippet(); return(View(model)); } model.Snippet = busSnippet.Entity; // Update the code so it's formatted model.FormattedCode = busSnippet.Entity.FormattedCode; if (!string.IsNullOrEmpty(AppUserState.UserId) && AppUserState.UserId == busSnippet.Entity.UserId || AppUserState.IsAdmin) { model.AllowEdit = true; } ActionResult result = View(model); string output = result.ToString(); return(result); } }
public ActionResult Show(string id) { ShowSnippetViewModel model = new ShowSnippetViewModel(this); model.AppUserState = AppUserState; // Since this is our default handler anything invalid will // run through here. No path - go to new if (string.IsNullOrEmpty(id) || id == "0") return this.New(); using (busCodeSnippet busSnippet = new busCodeSnippet()) { var snippet = busSnippet.Load(id); if (snippet == null) { return this.DisplayErrorPage("Invalid Snippet Id specified", "You specified a snippet id or link that is invalid and cannot be displayed. " + "Please using the <a href='./recent' class='hoverbutton'>Recent Snippets</a> or " + "<a href='mysnippets' class='hoverbutton'>My Snippets</a> buttons to look up valid snippets.", null); } bool allowWordWrap = false; bool showLineNumbers = busSnippet.Entity.ShowLineNumbers; string ua = Request.UserAgent.ToLower(); if (ua.Contains("iphone") || ua.Contains("blackberry") || ua.Contains("mobile")) { allowWordWrap = true; showLineNumbers = false; } // Update the code so it's formatted model.FormattedCode = busSnippet.Entity.FormattedCode; if (!AppUserState.IsEmpty()) model.IsFavoritedByUser = busSnippet.IsFavorite(busSnippet.Entity.Id, AppUserState.UserId); if (!string.IsNullOrEmpty(AppUserState.UserId) && AppUserState.UserId == busSnippet.Entity.UserId || AppUserState.IsAdmin) model.AllowEdit = true; // explicitly load up comments busSnippet.Entity.Comments = busSnippet.GetComments(); // For API result we have to make sure email and password are not included if (!string.IsNullOrEmpty(Format) && snippet.User != null) { busSnippet.StripSensitiveUserInformation(); } if (snippet.User != null) { if (!string.IsNullOrEmpty(snippet.User.Theme)) model.Theme = snippet.User.Theme; } ActionResult actionResult = this.ApiResult(busSnippet.Entity); if (actionResult != null) return actionResult; model.Snippet = busSnippet.Entity; // Fix up for Ace Editor model.Snippet.Language = busSnippet.FixUpLanguage(model.Snippet.Language).ToLower(); // Log views for all but poster if (model.Snippet.User == null || model.Snippet.User.Id != AppUserState.UserId) busSnippet.LogSnippetView(busSnippet.Entity.Id, Request.UserHostAddress, Request.UserAgent); return View("Show",model); } }
public ActionResult ShowUrl() { string url = Request.QueryString["url"]; string lang = Request.QueryString["language"]; if (string.IsNullOrEmpty(lang)) lang = Request.QueryString["lang"] ?? string.Empty; if (lang.ToLower() == "csharp") lang = "C#"; ShowSnippetViewModel model = new ShowSnippetViewModel(this); model.AppUserState = this.AppUserState; ViewData["originalUrl"] = url; ViewData["fileName"] = Path.GetFileName(url); ViewData["language"] = lang; if (string.IsNullOrEmpty(url)) { ViewData["languageList"] = this.GetLanguageList(lang); return View(model); } HttpClient client = new HttpClient(); client.Timeout = 4000; string result = client.DownloadString(url); if (result == null) return this.DisplayErrorPage("Unable to retrieve Code Url", client.ErrorMessage, null); if (result.Length > App.Configuration.MaxCodeLength) return this.DisplayErrorPage("Snippet is too large", "Your code snippet to display is too long. Snippets can be no larger than " + App.Configuration.MaxCodeLength.ToString("n0") + " bytes.",null); busCodeSnippet snippetBusiness = new busCodeSnippet(); if (string.IsNullOrEmpty(lang)) { string extension = Path.GetExtension(url).ToLower(); if (extension.StartsWith(".")) lang = extension.Substring(1); } model.FormattedCode = snippetBusiness.GetFormattedCode(result, lang, false, false); snippetBusiness.Dispose(); return this.View(model); }
public ActionResult CodeOnly(string id) { ShowSnippetViewModel model = new ShowSnippetViewModel(this); model.AppUserState = this.AppUserState; // Since this is our default handler anything invalid will // run through here. No path - go to new if (string.IsNullOrEmpty(id) || id == "0") return this.New(); using (busCodeSnippet busSnippet = new busCodeSnippet()) { if (busSnippet.Load(id) == null) { ErrorDisplay.ShowError("Invalid snippet id specified."); model.Snippet = new CodeSnippet(); return View(model); } model.Snippet = busSnippet.Entity; // Update the code so it's formatted model.FormattedCode = busSnippet.Entity.FormattedCode; if (!string.IsNullOrEmpty(AppUserState.UserId) && AppUserState.UserId == busSnippet.Entity.UserId || AppUserState.IsAdmin) model.AllowEdit = true; ActionResult result = View(model); string output = result.ToString(); return result; } }
public ActionResult Show(string id) { ShowSnippetViewModel model = new ShowSnippetViewModel(this); model.AppUserState = AppUserState; // Since this is our default handler anything invalid will // run through here. No path - go to new if (string.IsNullOrEmpty(id) || id == "0") { return(this.New()); } using (busCodeSnippet busSnippet = new busCodeSnippet()) { var snippet = busSnippet.Load(id); if (snippet == null) { return(this.DisplayErrorPage("Invalid Snippet Id specified", "You specified a snippet id or link that is invalid and cannot be displayed. " + "Please using the <a href='./recent' class='hoverbutton'>Recent Snippets</a> or " + "<a href='mysnippets' class='hoverbutton'>My Snippets</a> buttons to look up valid snippets.", null)); } bool allowWordWrap = false; bool showLineNumbers = busSnippet.Entity.ShowLineNumbers; string ua = Request.UserAgent.ToLower(); if (ua.Contains("iphone") || ua.Contains("blackberry") || ua.Contains("mobile")) { allowWordWrap = true; showLineNumbers = false; } // Update the code so it's formatted model.FormattedCode = busSnippet.Entity.FormattedCode; if (!AppUserState.IsEmpty()) { model.IsFavoritedByUser = busSnippet.IsFavorite(busSnippet.Entity.Id, AppUserState.UserId); } if (!string.IsNullOrEmpty(AppUserState.UserId) && AppUserState.UserId == busSnippet.Entity.UserId || AppUserState.IsAdmin) { model.AllowEdit = true; } // explicitly load up comments busSnippet.Entity.Comments = busSnippet.GetComments(); // For API result we have to make sure email and password are not included if (!string.IsNullOrEmpty(Format) && snippet.User != null) { busSnippet.StripSensitiveUserInformation(); } if (snippet.User != null) { if (!string.IsNullOrEmpty(snippet.User.Theme)) { model.Theme = snippet.User.Theme; } } ActionResult actionResult = this.ApiResult(busSnippet.Entity); if (actionResult != null) { return(actionResult); } model.Snippet = busSnippet.Entity; // Fix up for Ace Editor model.Snippet.Language = busSnippet.FixUpLanguage(model.Snippet.Language).ToLower(); // Log views for all but poster if (model.Snippet.User == null || model.Snippet.User.Id != AppUserState.UserId) { busSnippet.LogSnippetView(busSnippet.Entity.Id, Request.UserHostAddress, Request.UserAgent); } return(View("Show", model)); } }
public ActionResult ShowUrl() { string url = Request.QueryString["url"]; string lang = Request.QueryString["language"]; if (string.IsNullOrEmpty(lang)) { lang = Request.QueryString["lang"] ?? string.Empty; } if (lang.ToLower() == "csharp") { lang = "C#"; } ShowSnippetViewModel model = new ShowSnippetViewModel(this); model.AppUserState = this.AppUserState; ViewData["originalUrl"] = url; ViewData["fileName"] = Path.GetFileName(url); ViewData["language"] = lang; if (string.IsNullOrEmpty(url)) { ViewData["languageList"] = this.GetLanguageList(lang); return(View(model)); } HttpClient client = new HttpClient(); client.Timeout = 4000; string result = client.DownloadString(url); if (result == null) { return (this.DisplayErrorPage("Unable to retrieve Code Url", client.ErrorMessage, null)); } if (result.Length > App.Configuration.MaxCodeLength) { return(this.DisplayErrorPage("Snippet is too large", "Your code snippet to display is too long. Snippets can be no larger than " + App.Configuration.MaxCodeLength.ToString("n0") + " bytes.", null)); } busCodeSnippet snippetBusiness = new busCodeSnippet(); if (string.IsNullOrEmpty(lang)) { string extension = Path.GetExtension(url).ToLower(); if (extension.StartsWith(".")) { lang = extension.Substring(1); } } model.FormattedCode = snippetBusiness.GetFormattedCode(result, lang, false, false); snippetBusiness.Dispose(); return(this.View(model)); }