Skip to content

Commit

Permalink
more code style update
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed Mar 20, 2022
1 parent 5f9cb70 commit 232f45e
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 85 deletions.
5 changes: 1 addition & 4 deletions src/Moonglade.ImageStorage/GuidFileNameGenerator.cs
Expand Up @@ -24,8 +24,5 @@ public string GetFileName(string fileName, string appendixName = "")
return newFileName;
}

public GuidFileNameGenerator(Guid id)
{
UniqueId = id;
}
public GuidFileNameGenerator(Guid id) => UniqueId = id;
}
Expand Up @@ -4,8 +4,5 @@ public class FileSystemImageConfiguration
{
public string Path { get; set; }

public FileSystemImageConfiguration(string path)
{
Path = path;
}
public FileSystemImageConfiguration(string path) => Path = path;
}
11 changes: 2 additions & 9 deletions src/Moonglade.ImageStorage/Providers/FileSystemImageStorage.cs
@@ -1,21 +1,14 @@
using Microsoft.Extensions.Logging;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

namespace Moonglade.ImageStorage.Providers;

public class FileSystemImageStorage : IBlogImageStorage
{
public string Name => nameof(FileSystemImageStorage);

private readonly ILogger<FileSystemImageStorage> _logger;

private readonly string _path;

public FileSystemImageStorage(ILogger<FileSystemImageStorage> logger, FileSystemImageConfiguration imgConfig)
{
_logger = logger;
_path = imgConfig.Path;
}
public FileSystemImageStorage(FileSystemImageConfiguration imgConfig) => _path = imgConfig.Path;

public async Task<ImageInfo> GetAsync(string fileName)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Attributes/AddXRobotsTagAttribute.cs
Expand Up @@ -6,10 +6,7 @@ public class AddXRobotsTagAttribute : ResultFilterAttribute
{
private readonly string _content;

public AddXRobotsTagAttribute(string content)
{
_content = content;
}
public AddXRobotsTagAttribute(string content) => _content = content;

public override void OnResultExecuting(ResultExecutingContext context)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Filters/ValidateCaptcha.cs
Expand Up @@ -7,10 +7,7 @@ public class ValidateCaptcha : ActionFilterAttribute
{
private readonly ISessionBasedCaptcha _captcha;

public ValidateCaptcha(ISessionBasedCaptcha captcha)
{
_captcha = captcha;
}
public ValidateCaptcha(ISessionBasedCaptcha captcha) => _captcha = captcha;

public override void OnActionExecuting(ActionExecutingContext context)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/CustomCssMiddleware.cs
Expand Up @@ -8,10 +8,7 @@ public class CustomCssMiddleware

public static CustomCssMiddlewareOptions Options { get; set; } = new();

public CustomCssMiddleware(RequestDelegate next)
{
_next = next;
}
public CustomCssMiddleware(RequestDelegate next) => _next = next;

public async Task Invoke(HttpContext context, IBlogConfig blogConfig)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/DNTMiddleware.cs
Expand Up @@ -4,10 +4,7 @@ public class DNTMiddleware
{
private readonly RequestDelegate _next;

public DNTMiddleware(RequestDelegate next)
{
_next = next;
}
public DNTMiddleware(RequestDelegate next) => _next = next;

public Task Invoke(HttpContext httpContext)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/DefaultImageMiddleware.cs
Expand Up @@ -9,10 +9,7 @@ public class DefaultImageMiddleware

public static DefaultImageMiddlewareOptions Options { get; set; } = new();

public DefaultImageMiddleware(RequestDelegate next)
{
_next = next;
}
public DefaultImageMiddleware(RequestDelegate next) => _next = next;

public async Task Invoke(HttpContext context, IBlogConfig blogConfig)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/FoafMiddleware.cs
Expand Up @@ -6,10 +6,7 @@ public class FoafMiddleware
{
private readonly RequestDelegate _next;

public FoafMiddleware(RequestDelegate next)
{
_next = next;
}
public FoafMiddleware(RequestDelegate next) => _next = next;

public async Task Invoke(
HttpContext context,
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/OpenSearchMiddleware.cs
Expand Up @@ -7,10 +7,7 @@ public class OpenSearchMiddleware
private readonly RequestDelegate _next;
public static OpenSearchMiddlewareOptions Options { get; set; } = new();

public OpenSearchMiddleware(RequestDelegate next)
{
_next = next;
}
public OpenSearchMiddleware(RequestDelegate next) => _next = next;

public async Task Invoke(HttpContext httpContext, IBlogConfig blogConfig)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/PoweredByMiddleware.cs
Expand Up @@ -4,10 +4,7 @@ public class PoweredByMiddleware
{
private readonly RequestDelegate _next;

public PoweredByMiddleware(RequestDelegate next)
{
_next = next;
}
public PoweredByMiddleware(RequestDelegate next) => _next = next;

public Task Invoke(HttpContext httpContext)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/RSDMiddleware.cs
Expand Up @@ -6,10 +6,7 @@ public class RSDMiddleware
{
private readonly RequestDelegate _next;

public RSDMiddleware(RequestDelegate next)
{
_next = next;
}
public RSDMiddleware(RequestDelegate next) => _next = next;

public async Task Invoke(HttpContext httpContext, IBlogConfig blogConfig)
{
Expand Down
11 changes: 3 additions & 8 deletions src/Moonglade.Web/Middleware/RobotsTxtMiddleware.cs
Expand Up @@ -4,10 +4,7 @@ public class RobotsTxtMiddleware
{
private readonly RequestDelegate _next;

public RobotsTxtMiddleware(RequestDelegate next)
{
_next = next;
}
public RobotsTxtMiddleware(RequestDelegate next) => _next = next;

public async Task Invoke(HttpContext httpContext, IBlogConfig blogConfig)
{
Expand All @@ -33,10 +30,8 @@ public async Task Invoke(HttpContext httpContext, IBlogConfig blogConfig)

public static partial class ApplicationBuilderExtensions
{
public static IApplicationBuilder UseRobotsTxt(this IApplicationBuilder builder)
{
return builder.MapWhen(
public static IApplicationBuilder UseRobotsTxt(this IApplicationBuilder builder) =>
builder.MapWhen(
context => context.Request.Path == "/robots.txt",
p => p.UseMiddleware<RobotsTxtMiddleware>());
}
}
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/SiteMapMiddleware.cs
Expand Up @@ -10,10 +10,7 @@ public class SiteMapMiddleware
{
private readonly RequestDelegate _next;

public SiteMapMiddleware(RequestDelegate next)
{
_next = next;
}
public SiteMapMiddleware(RequestDelegate next) => _next = next;

public async Task Invoke(
HttpContext httpContext,
Expand Down
5 changes: 1 addition & 4 deletions src/Moonglade.Web/Middleware/WebManifestMiddleware.cs
Expand Up @@ -9,10 +9,7 @@ public class WebManifestMiddleware

public static WebManifestMiddlewareOptions Options { get; set; } = new();

public WebManifestMiddleware(RequestDelegate next)
{
_next = next;
}
public WebManifestMiddleware(RequestDelegate next) => _next = next;

public async Task Invoke(
HttpContext context, IBlogConfig blogConfig, IOptions<List<ManifestIcon>> manifestIcons)
Expand Down
20 changes: 4 additions & 16 deletions src/Moonglade.Web/TimeZoneResolver.cs
Expand Up @@ -14,27 +14,15 @@ public class BlogTimeZoneResolver : ITimeZoneResolver
{
public string UtcOffset { get; }

public BlogTimeZoneResolver(IBlogConfig blogConfig)
{
UtcOffset = blogConfig.GeneralSettings.TimeZoneUtcOffset;
}
public BlogTimeZoneResolver(IBlogConfig blogConfig) => UtcOffset = blogConfig.GeneralSettings.TimeZoneUtcOffset;

public DateTime NowOfTimeZone => UtcToZoneTime(DateTime.UtcNow, UtcOffset);

public DateTime ToTimeZone(DateTime utcDateTime)
{
return UtcToZoneTime(utcDateTime, UtcOffset);
}
public DateTime ToTimeZone(DateTime utcDateTime) => UtcToZoneTime(utcDateTime, UtcOffset);

public DateTime ToUtc(DateTime userDateTime)
{
return ZoneTimeToUtc(userDateTime, UtcOffset);
}
public DateTime ToUtc(DateTime userDateTime) => ZoneTimeToUtc(userDateTime, UtcOffset);

public IEnumerable<TimeZoneInfo> ListTimeZones()
{
return TimeZoneInfo.GetSystemTimeZones();
}
public IEnumerable<TimeZoneInfo> ListTimeZones() => TimeZoneInfo.GetSystemTimeZones();

public TimeSpan GetTimeSpanByZoneId(string timeZoneId)
{
Expand Down

0 comments on commit 232f45e

Please sign in to comment.