Skip to content

Commit

Permalink
.Net 8.0 Upgrade (#383)
Browse files Browse the repository at this point in the history
* .Net 8.0 upgrade

* Updated HtmlAgilityPack, updated list of blocked translations
  • Loading branch information
pmachapman authored Feb 15, 2024
1 parent d9221dc commit ef521ed
Show file tree
Hide file tree
Showing 114 changed files with 3,730 additions and 1,740 deletions.
7 changes: 6 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:si
csharp_style_prefer_pattern_matching = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand Down Expand Up @@ -251,4 +255,5 @@ dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
dotnet_style_qualification_for_field = true:suggestion
dotnet_style_qualification_for_property = true:suggestion
dotnet_style_qualification_for_method = true:suggestion
dotnet_style_qualification_for_event = true:suggestion
dotnet_style_qualification_for_event = true:suggestion
dotnet_style_prefer_collection_expression = true:suggestion
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Set up dotnet
uses: actions/[email protected]
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'
dotnet-quality: 'preview'


Expand Down
106 changes: 79 additions & 27 deletions GoToBible.Engine/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="ExtensionMethods.cs" company="Conglomo">
// Copyright 2020-2023 Conglomo Limited. Please see LICENSE.md for license details.
// Copyright 2020-2024 Conglomo Limited. Please see LICENSE.md for license details.
// </copyright>
// -----------------------------------------------------------------------

Expand Down Expand Up @@ -62,7 +62,11 @@ public static CompareOptions AsCompareOptions(this RenderingParameters parameter
/// <param name="value">The substring to count.</param>
/// <param name="stringComparison">The string comparison type.</param>
/// <returns>The number of occurrences of the substring within the string.</returns>
public static int CountOccurrences(this string text, string value, StringComparison stringComparison)
public static int CountOccurrences(
this string text,
string value,
StringComparison stringComparison
)
{
// Clean up the text and value
text = $" {text.Trim()} ";
Expand Down Expand Up @@ -94,7 +98,8 @@ public static string EncodeCsvField(this string field, char separator = ',')
StringBuilder sb = new StringBuilder(field);

// Fields with leading/trailing whitespace must be embedded in double quotes
bool embedInQuotes = sb.Length > 0 && (sb[0] == ' ' || sb[0] == '\t' || sb[^1] == ' ' || sb[^1] == '\t');
bool embedInQuotes =
sb.Length > 0 && (sb[0] == ' ' || sb[0] == '\t' || sb[^1] == ' ' || sb[^1] == '\t');

// If we have not yet found a reason to embed in quotes
if (!embedInQuotes)
Expand Down Expand Up @@ -122,7 +127,12 @@ public static string EncodeCsvField(this string field, char separator = ',')
/// <param name="approximatePosition">The approximate position of this occurrence. This should be an underestimate at worst.</param>
/// <param name="stringComparison">The string comparison type.</param>
/// <returns>The occurrence number of the substring within the string.</returns>
public static int GetOccurrence(this string text, string value, int approximatePosition, StringComparison stringComparison)
public static int GetOccurrence(
this string text,
string value,
int approximatePosition,
StringComparison stringComparison
)
{
// Clean up the text and value
text = $" {text.Trim()} ";
Expand Down Expand Up @@ -157,7 +167,8 @@ public static int GetOccurrence(this string text, string value, int approximateP
/// - brackets, see https://goto.bible/Acts.19_41/SBLGNT (SBL Greek New Testament)
/// NOTE: The input must be directly from a translation.
/// </returns>
public static string GetVerseNumber(this string line) => line.Contains(' ') ? line[..line.IndexOf(' ')].Trim() : string.Empty;
public static string GetVerseNumber(this string line) =>
line.Contains(' ') ? line[..line.IndexOf(' ')].Trim() : string.Empty;

/// <summary>
/// Determines whether this is a valid verse number.
Expand All @@ -183,7 +194,11 @@ public static bool IsValidVerseNumber(this string verseNumber)
public static bool MatchesHighlightedVerses(this string verseNumber, string[] highlightedVerses)
{
// Ensure that the verse number is valid, and there are highlighted verses
if (string.IsNullOrWhiteSpace(verseNumber) || !highlightedVerses.Any() || !verseNumber.IsValidVerseNumber())
if (
string.IsNullOrWhiteSpace(verseNumber)
|| highlightedVerses is []
|| !verseNumber.IsValidVerseNumber()
)
{
return false;
}
Expand All @@ -196,7 +211,7 @@ public static bool MatchesHighlightedVerses(this string verseNumber, string[] hi
{
string[] verseNumbers = verseNumber.Split('-', StringSplitOptions.RemoveEmptyEntries);
return verseNumbers.First().MatchesHighlightedVerses(highlightedVerses)
|| verseNumbers.Last().MatchesHighlightedVerses(highlightedVerses);
|| verseNumbers.Last().MatchesHighlightedVerses(highlightedVerses);
}

// We need to pad the numbers to account for letters
Expand Down Expand Up @@ -233,7 +248,9 @@ public static bool MatchesHighlightedVerses(this string verseNumber, string[] hi
else if (highlightedVerses[i] == "-" && i > 0 && i < highlightedVerses.Length - 1)
{
// Check inside this range
bool matches = string.CompareOrdinal(verseNumber, highlightedVerses[i - 1]) > 0 && string.CompareOrdinal(verseNumber, highlightedVerses[i + 1]) < 0;
bool matches =
string.CompareOrdinal(verseNumber, highlightedVerses[i - 1]) > 0
&& string.CompareOrdinal(verseNumber, highlightedVerses[i + 1]) < 0;
if (matches)
{
return matches;
Expand Down Expand Up @@ -261,19 +278,23 @@ public static bool MatchesHighlightedVerses(this string verseNumber, string[] hi
/// <remarks>
/// Full-width square brackets are replaced with regular square brackets.
/// </remarks>
public static string RenderItalics(this string line, string italicsTag = "em")
=> line.Replace("[[", "<pre>").Replace("]]", "</pre>")
.Replace("[", $"<{italicsTag}>").Replace("]", $"</{italicsTag}>")
.Replace("<pre>", "[[").Replace("</pre>", "]]")
.Replace("", "[").Replace("", "]");
public static string RenderItalics(this string line, string italicsTag = "em") =>
line.Replace("[[", "<pre>")
.Replace("]]", "</pre>")
.Replace("[", $"<{italicsTag}>")
.Replace("]", $"</{italicsTag}>")
.Replace("<pre>", "[[")
.Replace("</pre>", "]]")
.Replace("", "[")
.Replace("", "]");

/// <summary>
/// Strips the HTML tags from the string.
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The input string without HTML tags.</returns>
public static string StripHtml(this string input)
=> HtmlTagRegex().Replace(input, string.Empty);
public static string StripHtml(this string input) =>
HtmlTagRegex().Replace(input, string.Empty);

/// <summary>
/// Renders the supplied words in normal type.
Expand All @@ -285,9 +306,11 @@ public static string StripHtml(this string input)
/// <remarks>
/// Full-width square brackets are replaced with regular square brackets.
/// </remarks>
public static string StripItalics(this string line)
=> line.Replace("[", string.Empty).Replace("]", string.Empty)
.Replace("", "[").Replace("", "]");
public static string StripItalics(this string line) =>
line.Replace("[", string.Empty)
.Replace("]", string.Empty)
.Replace("", "[")
.Replace("", "]");

/// <summary>
/// Gets a unique name for the translation.
Expand All @@ -297,24 +320,50 @@ public static string StripItalics(this string line)
/// <returns>
/// The unique name.
/// </returns>
public static string UniqueName(this Translation translation, IEnumerable<Translation> translations)
public static string UniqueName(
this Translation translation,
IEnumerable<Translation> translations
)
{
IEnumerable<Translation> enumerable = translations as Translation[] ?? translations.ToArray();
if (enumerable.Count(t => string.Equals(t.Name, translation.Name, StringComparison.OrdinalIgnoreCase)) <= 1)
IEnumerable<Translation> enumerable =
translations as Translation[] ?? translations.ToArray();
if (
enumerable.Count(t =>
string.Equals(t.Name, translation.Name, StringComparison.OrdinalIgnoreCase)
) <= 1
)
{
return translation.Name;
}
else if (enumerable.Count(t => string.Equals(t.Name, translation.Name, StringComparison.OrdinalIgnoreCase) && t.Year == translation.Year && t.Year > 0) == 1)
else if (
enumerable.Count(t =>
string.Equals(t.Name, translation.Name, StringComparison.OrdinalIgnoreCase)
&& t.Year == translation.Year
&& t.Year > 0
) == 1
)
{
return $"{translation.Name} ({translation.Year})";
}
else if (enumerable.Count(t => string.Equals(t.Name, translation.Name, StringComparison.OrdinalIgnoreCase) && t.Language == translation.Language) == 1)
else if (
enumerable.Count(t =>
string.Equals(t.Name, translation.Name, StringComparison.OrdinalIgnoreCase)
&& t.Language == translation.Language
) == 1
)
{
// English translation names (i.e. King James Version) have priority
return translation.Language == "English" ? translation.Name : $"{translation.Language} {translation.Name}";
return translation.Language == "English"
? translation.Name
: $"{translation.Language} {translation.Name}";
}
else if (enumerable.Count(t => string.Equals(t.Name, translation.Name, StringComparison.OrdinalIgnoreCase)
&& t.Dialect == translation.Dialect && !string.IsNullOrWhiteSpace(t.Dialect)) == 1)
else if (
enumerable.Count(t =>
string.Equals(t.Name, translation.Name, StringComparison.OrdinalIgnoreCase)
&& t.Dialect == translation.Dialect
&& !string.IsNullOrWhiteSpace(t.Dialect)
) == 1
)
{
return $"{translation.Name} ({translation.Dialect})";
}
Expand All @@ -338,6 +387,9 @@ public static string UniqueName(this Translation translation, IEnumerable<Transl
/// <remarks>
/// This includes support for verses with letters, hypenated verses, and verses enclosed in brackets.
/// </remarks>
[GeneratedRegex(@"([\[]((([0-9]+[a-z]?)-([0-9]+[a-z]?))|([0-9]+[a-z]?))[\]])|((([0-9]+[a-z]?)-([0-9]+[a-z]?))|([0-9]+[a-z]?))", RegexOptions.Compiled)]
[GeneratedRegex(
@"([\[]((([0-9]+[a-z]?)-([0-9]+[a-z]?))|([0-9]+[a-z]?))[\]])|((([0-9]+[a-z]?)-([0-9]+[a-z]?))|([0-9]+[a-z]?))",
RegexOptions.Compiled
)]
private static partial Regex VerseNumberRegex();
}
2 changes: 1 addition & 1 deletion GoToBible.Engine/GoToBible.Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>GoToBible.Engine.snk</AssemblyOriginatorKeyFile>
<Nullable>enable</Nullable>
Expand Down
18 changes: 14 additions & 4 deletions GoToBible.Engine/GotoBibleApiRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="GotoBibleApiRenderer.cs" company="Conglomo">
// Copyright 2020-2023 Conglomo Limited. Please see LICENSE.md for license details.
// Copyright 2020-2024 Conglomo Limited. Please see LICENSE.md for license details.
// </copyright>
// -----------------------------------------------------------------------

Expand Down Expand Up @@ -60,12 +60,22 @@ public void Dispose()
}

/// <inheritdoc/>
public async Task<RenderedPassage> RenderAsync(RenderingParameters parameters, bool renderCompleteHtmlPage, CancellationToken cancellationToken = default)
public async Task<RenderedPassage> RenderAsync(
RenderingParameters parameters,
bool renderCompleteHtmlPage,
CancellationToken cancellationToken = default
)
{
string url = $"RenderPassage?renderCompleteHtmlPage={renderCompleteHtmlPage}";
HttpResponseMessage response = await this.httpClient.PostAsJsonAsync(url, parameters, cancellationToken);
HttpResponseMessage response = await this.httpClient.PostAsJsonAsync(
url,
parameters,
cancellationToken
);
return response.IsSuccessStatusCode
? await response.Content.ReadFromJsonAsync<RenderedPassage>(cancellationToken: cancellationToken) ?? new RenderedPassage()
? await response.Content.ReadFromJsonAsync<RenderedPassage>(
cancellationToken: cancellationToken
) ?? new RenderedPassage()
: new RenderedPassage();
}

Expand Down
2 changes: 1 addition & 1 deletion GoToBible.Engine/RenderedVerse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// -----------------------------------------------------------------------
// <copyright file="RenderedVerse.cs" company="Conglomo">
// Copyright 2020-2023 Conglomo Limited. Please see LICENSE.md for license details.
// Copyright 2020-2024 Conglomo Limited. Please see LICENSE.md for license details.
// </copyright>
// -----------------------------------------------------------------------

Expand Down
Loading

0 comments on commit ef521ed

Please sign in to comment.