style: apply braces style to project
This commit is contained in:
parent
14d73851ea
commit
278c807fa3
@ -45,8 +45,16 @@ internal sealed class BlacklistEntry : IEquatable<BlacklistEntry>, IBlacklistEnt
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool Equals(BlacklistEntry? other)
|
public bool Equals(BlacklistEntry? other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other))
|
||||||
if (ReferenceEquals(this, other)) return true;
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ReferenceEquals(this, other))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return EmailAddress.Equals(other.EmailAddress);
|
return EmailAddress.Equals(other.EmailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,16 @@ internal sealed class ProgrammingLanguage : IEquatable<ProgrammingLanguage>, IPr
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool Equals(ProgrammingLanguage? other)
|
public bool Equals(ProgrammingLanguage? other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other))
|
||||||
if (ReferenceEquals(this, other)) return true;
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ReferenceEquals(this, other))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return Key.Equals(other.Key);
|
return Key.Equals(other.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +74,16 @@ internal sealed class Project : IEquatable<Project>, IProject
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool Equals(Project? other)
|
public bool Equals(Project? other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other))
|
||||||
if (ReferenceEquals(this, other)) return true;
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ReferenceEquals(this, other))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return Id.Equals(other.Id);
|
return Id.Equals(other.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,16 @@ public sealed class SiteConfiguration : IEquatable<SiteConfiguration>
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool Equals(SiteConfiguration? other)
|
public bool Equals(SiteConfiguration? other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other))
|
||||||
if (ReferenceEquals(this, other)) return true;
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ReferenceEquals(this, other))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return Key == other.Key;
|
return Key == other.Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +47,16 @@ public sealed class Template : ITemplate, IEquatable<Template>
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool Equals(Template? other)
|
public bool Equals(Template? other)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(null, other)) return false;
|
if (ReferenceEquals(null, other))
|
||||||
if (ReferenceEquals(this, other)) return true;
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ReferenceEquals(this, other))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return Name == other.Name && Variant == other.Variant;
|
return Name == other.Name && Variant == other.Variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +62,14 @@ internal sealed class User : IUser, IBlogAuthor
|
|||||||
Span<char> hex = stackalloc char[2];
|
Span<char> hex = stackalloc char[2];
|
||||||
for (var index = 0; index < hash.Length; index++)
|
for (var index = 0; index < hash.Length; index++)
|
||||||
{
|
{
|
||||||
if (hash[index].TryFormat(hex, out _, "x2")) builder.Append(hex);
|
if (hash[index].TryFormat(hex, out _, "x2"))
|
||||||
else builder.Append("00");
|
{
|
||||||
|
builder.Append(hex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.Append("00");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Uri($"https://www.gravatar.com/avatar/{builder}?size={size}");
|
return new Uri($"https://www.gravatar.com/avatar/{builder}?size={size}");
|
||||||
|
@ -18,13 +18,17 @@ public sealed class DateFormatter : IFormatter
|
|||||||
public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
|
public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
|
||||||
{
|
{
|
||||||
if (formattingInfo.CurrentValue is not string value)
|
if (formattingInfo.CurrentValue is not string value)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!DateTime.TryParseExact(value, "yyyy-MM-dd",
|
if (!DateTime.TryParseExact(value, "yyyy-MM-dd",
|
||||||
CultureInfo.InvariantCulture,
|
CultureInfo.InvariantCulture,
|
||||||
DateTimeStyles.None,
|
DateTimeStyles.None,
|
||||||
out DateTime date))
|
out DateTime date))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
formattingInfo.Write(date.ToString(formattingInfo.Format?.ToString(), CultureInfo.InvariantCulture));
|
formattingInfo.Write(date.ToString(formattingInfo.Format?.ToString(), CultureInfo.InvariantCulture));
|
||||||
|
@ -29,7 +29,9 @@ public sealed class MarkdownFormatter : IFormatter
|
|||||||
public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
|
public bool TryEvaluateFormat(IFormattingInfo formattingInfo)
|
||||||
{
|
{
|
||||||
if (formattingInfo.CurrentValue is not string value)
|
if (formattingInfo.CurrentValue is not string value)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var pipeline = _serviceProvider.GetService<MarkdownPipeline>();
|
var pipeline = _serviceProvider.GetService<MarkdownPipeline>();
|
||||||
formattingInfo.Write(Markdig.Markdown.ToHtml(value, pipeline));
|
formattingInfo.Write(Markdig.Markdown.ToHtml(value, pipeline));
|
||||||
|
@ -56,7 +56,11 @@ public sealed class TimestampInlineParser : InlineParser
|
|||||||
timestamp = default;
|
timestamp = default;
|
||||||
format = default;
|
format = default;
|
||||||
|
|
||||||
if (!source.StartsWith("<t:")) return false;
|
if (!source.StartsWith("<t:"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
timestamp = source[3..];
|
timestamp = source[3..];
|
||||||
|
|
||||||
if (timestamp.IndexOf('>') == -1)
|
if (timestamp.IndexOf('>') == -1)
|
||||||
|
@ -39,7 +39,9 @@ public class RawArticle : PageModel
|
|||||||
|
|
||||||
builder.AppendLine($"Published: {post.Published:R}");
|
builder.AppendLine($"Published: {post.Published:R}");
|
||||||
if (post.Updated.HasValue)
|
if (post.Updated.HasValue)
|
||||||
|
{
|
||||||
builder.AppendLine($"Updated: {post.Updated:R}");
|
builder.AppendLine($"Updated: {post.Updated:R}");
|
||||||
|
}
|
||||||
|
|
||||||
builder.AppendLine();
|
builder.AppendLine();
|
||||||
builder.AppendLine(post.Body);
|
builder.AppendLine(post.Body);
|
||||||
|
@ -35,8 +35,15 @@ internal sealed class SessionService : ISessionService
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ISession CreateSession(HttpRequest request, IUser user)
|
public ISession CreateSession(HttpRequest request, IUser user)
|
||||||
{
|
{
|
||||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
if (request is null)
|
||||||
if (user is null) throw new ArgumentNullException(nameof(user));
|
{
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(user));
|
||||||
|
}
|
||||||
|
|
||||||
using WebContext context = _webContextFactory.CreateDbContext();
|
using WebContext context = _webContextFactory.CreateDbContext();
|
||||||
var now = DateTimeOffset.UtcNow;
|
var now = DateTimeOffset.UtcNow;
|
||||||
@ -66,11 +73,21 @@ internal sealed class SessionService : ISessionService
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void SaveSessionCookie(HttpResponse response, ISession session)
|
public void SaveSessionCookie(HttpResponse response, ISession session)
|
||||||
{
|
{
|
||||||
if (response is null) throw new ArgumentNullException(nameof(response));
|
if (response is null)
|
||||||
if (session is null) throw new ArgumentNullException(nameof(session));
|
{
|
||||||
|
throw new ArgumentNullException(nameof(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(session));
|
||||||
|
}
|
||||||
|
|
||||||
Span<byte> buffer = stackalloc byte[16];
|
Span<byte> buffer = stackalloc byte[16];
|
||||||
if (!session.Id.TryWriteBytes(buffer)) return;
|
if (!session.Id.TryWriteBytes(buffer))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
IPAddress? remoteIpAddress = response.HttpContext.Connection.RemoteIpAddress;
|
IPAddress? remoteIpAddress = response.HttpContext.Connection.RemoteIpAddress;
|
||||||
_logger.LogDebug("Writing cookie 'sid' to HTTP response for {RemoteAddr}", remoteIpAddress);
|
_logger.LogDebug("Writing cookie 'sid' to HTTP response for {RemoteAddr}", remoteIpAddress);
|
||||||
@ -88,18 +105,28 @@ internal sealed class SessionService : ISessionService
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool TryGetSession(HttpRequest request, [NotNullWhen(true)] out ISession? session)
|
public bool TryGetSession(HttpRequest request, [NotNullWhen(true)] out ISession? session)
|
||||||
{
|
{
|
||||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
if (request is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
}
|
||||||
|
|
||||||
session = null;
|
session = null;
|
||||||
IPAddress? remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;
|
IPAddress? remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;
|
||||||
if (remoteIpAddress is null) return false;
|
if (remoteIpAddress is null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!request.Cookies.TryGetValue("sid", out string? sessionIdCookie))
|
if (!request.Cookies.TryGetValue("sid", out string? sessionIdCookie))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Span<byte> bytes = stackalloc byte[16];
|
Span<byte> bytes = stackalloc byte[16];
|
||||||
if (!Convert.TryFromBase64Chars(sessionIdCookie, bytes, out int bytesWritten) || bytesWritten < 16)
|
if (!Convert.TryFromBase64Chars(sessionIdCookie, bytes, out int bytesWritten) || bytesWritten < 16)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var sessionId = new Guid(bytes);
|
var sessionId = new Guid(bytes);
|
||||||
return TryGetSession(sessionId, out session);
|
return TryGetSession(sessionId, out session);
|
||||||
@ -108,13 +135,18 @@ internal sealed class SessionService : ISessionService
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool ValidateSession(HttpRequest request, ISession session)
|
public bool ValidateSession(HttpRequest request, ISession session)
|
||||||
{
|
{
|
||||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
if (request is null)
|
||||||
if (session is null) throw new ArgumentNullException(nameof(session));
|
{
|
||||||
|
throw new ArgumentNullException(nameof(request));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(session));
|
||||||
|
}
|
||||||
|
|
||||||
IPAddress? remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;
|
IPAddress? remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;
|
||||||
if (remoteIpAddress is null) return false;
|
if (remoteIpAddress is null)
|
||||||
|
|
||||||
if (session.Expires >= DateTimeOffset.UtcNow)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,10 @@ internal sealed class TemplateService : ITemplateService
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string RenderGlobalTemplate(TemplateInline templateInline)
|
public string RenderGlobalTemplate(TemplateInline templateInline)
|
||||||
{
|
{
|
||||||
if (templateInline is null) throw new ArgumentNullException(nameof(templateInline));
|
if (templateInline is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(templateInline));
|
||||||
|
}
|
||||||
|
|
||||||
return TryGetTemplate(templateInline.Name, templateInline.Variant, out ITemplate? template)
|
return TryGetTemplate(templateInline.Name, templateInline.Variant, out ITemplate? template)
|
||||||
? RenderTemplate(templateInline, template)
|
? RenderTemplate(templateInline, template)
|
||||||
|
@ -28,12 +28,19 @@ internal sealed class UserService : IUserService
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool TryGetUser(Guid id, [NotNullWhen(true)] out IUser? user)
|
public bool TryGetUser(Guid id, [NotNullWhen(true)] out IUser? user)
|
||||||
{
|
{
|
||||||
if (_userCache.TryGetValue(id, out user)) return true;
|
if (_userCache.TryGetValue(id, out user))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
using WebContext context = _dbContextFactory.CreateDbContext();
|
using WebContext context = _dbContextFactory.CreateDbContext();
|
||||||
user = context.Users.Find(id);
|
user = context.Users.Find(id);
|
||||||
|
|
||||||
if (user is not null) _userCache.TryAdd(id, user);
|
if (user is not null)
|
||||||
|
{
|
||||||
|
_userCache.TryAdd(id, user);
|
||||||
|
}
|
||||||
|
|
||||||
return user is not null;
|
return user is not null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user