forked from xoofx/markdig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebApp] Enable ImplictUsings and use file-scoped namespaces
- Loading branch information
Showing
4 changed files
with
87 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,54 @@ | ||
using System; | ||
using System.Text; | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Markdig.WebApp | ||
namespace Markdig.WebApp; | ||
|
||
public class ApiController : Controller | ||
{ | ||
public class ApiController : Controller | ||
[HttpGet()] | ||
[Route("")] | ||
public string Empty() | ||
{ | ||
[HttpGet()] | ||
[Route("")] | ||
public string Empty() | ||
{ | ||
return string.Empty; | ||
} | ||
return string.Empty; | ||
} | ||
|
||
// GET api/to_html?text=xxx&extension=advanced | ||
[Route("api/to_html")] | ||
[HttpGet()] | ||
public object Get([FromQuery] string text, [FromQuery] string extension) | ||
// GET api/to_html?text=xxx&extension=advanced | ||
[Route("api/to_html")] | ||
[HttpGet()] | ||
public object Get([FromQuery] string text, [FromQuery] string extension) | ||
{ | ||
try | ||
{ | ||
try | ||
if (text == null) | ||
{ | ||
if (text == null) | ||
{ | ||
text = string.Empty; | ||
} | ||
|
||
if (text.Length > 1000) | ||
{ | ||
text = text.Substring(0, 1000); | ||
} | ||
|
||
var pipeline = new MarkdownPipelineBuilder().Configure(extension).Build(); | ||
var result = Markdown.ToHtml(text, pipeline); | ||
|
||
return new {name = "markdig", html = result, version = Markdown.Version}; | ||
text = string.Empty; | ||
} | ||
catch (Exception ex) | ||
|
||
if (text.Length > 1000) | ||
{ | ||
return new { name = "markdig", html = "exception: " + GetPrettyMessageFromException(ex), version = Markdown.Version }; | ||
text = text.Substring(0, 1000); | ||
} | ||
|
||
var pipeline = new MarkdownPipelineBuilder().Configure(extension).Build(); | ||
var result = Markdown.ToHtml(text, pipeline); | ||
|
||
return new {name = "markdig", html = result, version = Markdown.Version}; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return new { name = "markdig", html = "exception: " + GetPrettyMessageFromException(ex), version = Markdown.Version }; | ||
} | ||
} | ||
|
||
private static string GetPrettyMessageFromException(Exception exception) | ||
private static string GetPrettyMessageFromException(Exception exception) | ||
{ | ||
var builder = new StringBuilder(); | ||
while (exception != null) | ||
{ | ||
var builder = new StringBuilder(); | ||
while (exception != null) | ||
{ | ||
builder.Append(exception.Message); | ||
exception = exception.InnerException; | ||
} | ||
return builder.ToString(); | ||
builder.Append(exception.Message); | ||
exception = exception.InnerException; | ||
} | ||
return builder.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
using System.IO; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Hosting; | ||
namespace Markdig.WebApp; | ||
|
||
namespace Markdig.WebApp | ||
public class Program | ||
{ | ||
public class Program | ||
public static void Main(string[] args) | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,52 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Markdig.WebApp | ||
namespace Markdig.WebApp; | ||
|
||
public class Startup | ||
{ | ||
public class Startup | ||
public Startup(IWebHostEnvironment env) | ||
{ | ||
public Startup(IWebHostEnvironment env) | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(env.ContentRootPath) | ||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | ||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); | ||
|
||
if (env.IsEnvironment("Development")) | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.SetBasePath(env.ContentRootPath) | ||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | ||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); | ||
|
||
if (env.IsEnvironment("Development")) | ||
{ | ||
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. | ||
builder.AddApplicationInsightsSettings(developerMode: true); | ||
} | ||
|
||
builder.AddEnvironmentVariables(); | ||
Configuration = builder.Build(); | ||
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. | ||
builder.AddApplicationInsightsSettings(developerMode: true); | ||
} | ||
|
||
public IConfigurationRoot Configuration { get; } | ||
builder.AddEnvironmentVariables(); | ||
Configuration = builder.Build(); | ||
} | ||
|
||
public IConfigurationRoot Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddControllers(); | ||
// Add framework services. | ||
services.AddApplicationInsightsTelemetry(Configuration); | ||
} | ||
// This method gets called by the runtime. Use this method to add services to the container | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddControllers(); | ||
|
||
// Add framework services. | ||
services.AddApplicationInsightsTelemetry(Configuration); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) | ||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseHttpsRedirection(); | ||
|
||
app.UseRouting(); | ||
app.UseRouting(); | ||
|
||
app.UseAuthorization(); | ||
app.UseAuthorization(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
}); | ||
} | ||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
}); | ||
} | ||
} |