Alper Ebicoglu 7 years ago
parent
commit
7a7fd33efb
  1. 127
      modules/docs/app/Volo.DocsTestApp/Controllers/ErrorController.cs
  2. 3
      modules/docs/app/Volo.DocsTestApp/Controllers/HomeController.cs
  3. 5
      modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs
  4. 4
      modules/docs/app/Volo.DocsTestApp/Pages/Index.cshtml
  5. 2
      modules/docs/src/Volo.Docs.Web/DocsWebModule.cs
  6. 10
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

127
modules/docs/app/Volo.DocsTestApp/Controllers/ErrorController.cs

@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Net;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Serilog;
using Volo.Abp.AspNetCore.Mvc;
namespace Volo.DocsTestApp.Controllers
{
public class ErrorController : AbpController
{
[Route("error/{statusCode}")]
[HttpGet]
public IActionResult Index(int statusCode = 0)
{
var statusFeature = HttpContext.Features.Get<IStatusCodeReExecuteFeature>();
if (statusFeature != null)
{
Log.Warning("Handled {0} error for URL: {1}", statusCode, statusFeature.OriginalPath);
}
var isValidStatusCode = Enum.IsDefined(typeof(HttpStatusCode), statusCode);
if (!isValidStatusCode)
{
statusCode = (int)HttpStatusCode.BadRequest;
}
return new ContentResult
{
ContentType = System.Net.Mime.MediaTypeNames.Text.Html,
StatusCode = statusCode,
Content = string.Format(HtmlBody, _errorMessages.ContainsKey(statusCode)
? _errorMessages[statusCode]
: "Looks like something went wrong!")
};
}
private const string HtmlBody = "<html><body><div style='text-align:center'><pre>{0}</pre><a href='/'>Go to home page</a></div></body></html>";
/*For more ASCII arts http://patorjk.com/software/taag/#p=display&h=0&f=Big&t=400*/
private readonly Dictionary<int, string> _errorMessages = new Dictionary<int, string>
{
{
400, @"
_ _ ___ ___
| || | / _ \ / _ \
| || |_ | | | | | | | |
|__ _| | | | | | | | |
| | | |_| | | |_| |
|_| \___/ \___/
You've sent a bad request!"
},
{
401, @"
_ _ ___ __
| || | / _ \ /_ |
| || |_ | | | | | |
|__ _| | | | | | |
| | | |_| | | |
|_| \___/ |_|
Authorization required!"
},
{
403,
@"
_ _ ___ ____
| || | / _ \ |___ \
| || |_ | | | | __) |
|__ _| | | | | |__ <
| | | |_| | ___) |
|_| \___/ |____/
This is a forbidden area!"
},
{
404, @"
_ _ ___ _ _
| || | / _ \ | || |
| || |_ | | | | | || |_
|__ _| | | | | |__ _|
| | | |_| | | |
|_| \___/ |_|
We can't find the page you're looking for..."
},
{
500,
@"
_____ ___ ___
| ____| / _ \ / _ \
| |__ | | | | | | | |
|___ \ | | | | | | | |
___) | | |_| | | |_| |
|____/ \___/ \___/
Houston, we have a problem. Internal server error!"
},
{
502,
@"
_____ ___ ___
| ____| / _ \ |__ \
| |__ | | | | ) |
|___ \ | | | | / /
___) | | |_| | / /_
|____/ \___/ |____|
Ooops! Our server is experiencing a mild case of the hiccups."
},
{
503,
@"
_____ ___ ____
| ____| / _ \ |___ \
| |__ | | | | __) |
|___ \ | | | | |__ <
___) | | |_| | ___) |
|____/ \___/ |____/
Looks like we're having some server issues."
}
};
}
}

3
modules/docs/app/Volo.DocsTestApp/Controllers/HomeController.cs

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
namespace Volo.DocsTestApp.Controllers
{

5
modules/docs/app/Volo.DocsTestApp/DocsTestAppModule.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using Microsoft.AspNetCore.Builder;
@ -108,7 +109,7 @@ namespace Volo.DocsTestApp
app.UseDeveloperExceptionPage();
app.UseVirtualFiles();
app.UseSwagger();
app.UseSwaggerUI(options =>
{
@ -118,6 +119,8 @@ namespace Volo.DocsTestApp
app.UseAuthentication();
app.UseRequestLocalization(app.ApplicationServices.GetRequiredService<IOptions<RequestLocalizationOptions>>().Value);
app.UseStatusCodePagesWithReExecute("/error/{0}");
app.UseMvc(routes =>
{

4
modules/docs/app/Volo.DocsTestApp/Pages/Index.cshtml

@ -1,4 +1,4 @@
@page
@model Volo.DocsTestApp.Pages.IndexModel
<h3>Welcome to the Docs demo application.</h3>
<a href="/Documents/">Go to Docs</a>
<h3>Welcome to the Docs Demo!</h3>
<a href="/documents/">Go to documents...</a>

2
modules/docs/src/Volo.Docs.Web/DocsWebModule.cs

@ -38,6 +38,8 @@ namespace Volo.Docs
Configure<RazorPagesOptions>(options =>
{
//TODO: Make configurable!
options.Conventions.AddPageRoute("/Documents/Project/Index", "documents/{projectName}");
options.Conventions.AddPageRoute("/Documents/Project/Index", "documents/{projectName}/{version}/{*documentName}");
});

10
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

@ -42,8 +42,8 @@ namespace Volo.Docs.Pages.Documents.Project
private readonly IProjectAppService _projectAppService;
public IndexModel(
IDocumentAppService documentAppService,
IDocumentToHtmlConverterFactory documentToHtmlConverterFactory,
IDocumentAppService documentAppService,
IDocumentToHtmlConverterFactory documentToHtmlConverterFactory,
IProjectAppService projectAppService)
{
_documentAppService = documentAppService;
@ -80,6 +80,10 @@ namespace Volo.Docs.Pages.Documents.Project
private async Task SetVersionAsync()
{
//TODO: Needs refactoring
if (string.IsNullOrWhiteSpace(Version))
{
Version = DocsAppConsts.Latest;
}
var output = await _projectAppService.GetVersionsAsync(Project.ShortName);
var versions = output.Items
@ -142,7 +146,7 @@ namespace Volo.Docs.Pages.Documents.Project
Navigation.ConvertItems();
}
public string CreateVersionLink(VersionInfoViewModel latestVersion, string version, string documentName = null)
{
if (latestVersion == null || latestVersion.Version == version)

Loading…
Cancel
Save