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)); }