/// <summary> /// /list/recent /// /list/tag/C# /// </summary> /// <param name="listAction"></param> /// <param name="listFilter"></param> /// <returns></returns> public ActionResult List(string listAction, string listFilter) { if (listAction == "MySnippets") { return(MySnippets()); } else if (listAction == "MyFavorites") { return(MyFavorites()); } using (busCodeSnippet busSnippet = new busCodeSnippet()) { var snippetList = busSnippet.GetSnippetList(listAction, listFilter); busSnippet.Dispose(); //if (listAction == "recent") //{ // // keep the snippetlist short // if (snippetList != null) // snippetList = snippetList.Take(20).ToList(); //} this.ViewData["busSnippet"] = busSnippet; this.ViewData["SnippetList"] = snippetList; if (listAction == "tag") { this.ViewData["PageTitle"] = "Recent snippets matching tags of " + listFilter; if (snippetList.Count < 1) { Response.StatusCode = 404; ErrorController.ShowErrorPage("Invalid tag", "You've entered a tag that is not valid or has no related entries."); } } else if (listAction == "language") { this.ViewData["PageTitle"] = "Recent snippets matching language of " + listFilter; } else if (listAction == "user") { if (snippetList.Count > 0) { this.ViewData["PageTitle"] = "Recent snippets for: " + snippetList.First().Author; } else { this.ViewData["PageTitle"] = "Recent snippets for user: "******"List")); } }
/// <summary> /// /list/recent /// /list/tag/C# /// </summary> /// <param name="listAction"></param> /// <param name="listFilter"></param> /// <returns></returns> public ActionResult List(string listAction, string listFilter) { if (listAction == "MySnippets") return MySnippets(); else if (listAction == "MyFavorites") return MyFavorites(); using (busCodeSnippet busSnippet = new busCodeSnippet()) { var snippetList = busSnippet.GetSnippetList(listAction, listFilter); busSnippet.Dispose(); this.ViewData["busSnippet"] = busSnippet; this.ViewData["SnippetList"] = snippetList; if (listAction == "tag") { this.ViewData["PageTitle"] = "Recent snippets matching tags of " + listFilter; if (snippetList.Count < 1) { Response.StatusCode = 404; ErrorController.ShowErrorPage("Invalid tag", "You've entered a tag that is not valid or has no related entries."); } } else if (listAction == "language") this.ViewData["PageTitle"] = "Recent snippets matching language of " + listFilter; else if (listAction == "user") { if (snippetList.Count > 0) this.ViewData["PageTitle"] = "Recent snippets for: " + snippetList.First().Author; else this.ViewData["PageTitle"] = "Recent snippets for user: "******"List"); } }
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 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)); }