Skip to content

Commit

Permalink
Update to .NET 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila committed Jul 8, 2021
1 parent dd2da2c commit 04fe419
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 43 deletions.
14 changes: 8 additions & 6 deletions Console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Assembly -->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>RedditQuoteBot.Console</AssemblyName>
<RootNamespace>RedditQuoteBot.Console</RootNamespace>
<StartupObject>RedditQuoteBot.Console.Program</StartupObject>
Expand All @@ -11,20 +11,22 @@

<!-- C# compiler -->
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Features>strict</Features>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>nullable</WarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>

<ItemGroup>
<None Remove="Config.ini" />
<None Remove="IgnoredUserNames.txt" />
<None Remove="Quotes.txt" />
<None Remove="Subreddits.txt" />
<None Remove="TriggerPhrases.txt" />
</ItemGroup>

<ItemGroup>
<Content Include="Config.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -47,7 +49,7 @@
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="ini-parser-netstandard" Version="2.5.2" />
</ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using RedditQuoteBot.Core;
using System;
using System.Reflection;
using System.Threading;

Expand Down Expand Up @@ -42,4 +41,4 @@ public static void Main()
}
}
}
}
}
3 changes: 1 addition & 2 deletions Console/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace RedditQuoteBot.Console
{
Expand Down Expand Up @@ -70,4 +69,4 @@ private static IList<string> GetFileContent(string value)

public static readonly IList<string> Quotes;
}
}
}
4 changes: 1 addition & 3 deletions Core/Converters/MicrosecondEpochConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand All @@ -20,4 +18,4 @@ public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializer
writer.WriteStringValue(((value - _epoch).TotalMilliseconds / 1000).ToString());
}
}
}
}
12 changes: 7 additions & 5 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<RootNamespace>RedditQuoteBot.Core</RootNamespace>
<EmbedAllSources>true</EmbedAllSources>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>RedditQuoteBot.pfx</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>RedditQuoteBot.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<!-- NuGet -->
<PropertyGroup>
<PackageId>RedditQuoteBot</PackageId>
<Product>RedditQuoteBot</Product>
<Version>1.0.0</Version>
<Version>1.1.0</Version>
<Authors>David Sungaila</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -31,10 +31,12 @@

<!-- C# compiler -->
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Features>strict</Features>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>nullable</WarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>

<!-- Release builds -->
Expand All @@ -58,7 +60,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="System.Text.Json" Version="5.0.2" />
</ItemGroup>

</Project>
4 changes: 1 addition & 3 deletions Core/Models/AccessTokenResponse.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.Json.Serialization;

namespace RedditQuoteBot.Core.Models
Expand Down Expand Up @@ -36,4 +34,4 @@ public long ExpiresIn

public override string? ToString() => Token;
}
}
}
7 changes: 2 additions & 5 deletions Core/Models/ChildData.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Diagnostics;
using System.Text.Json.Serialization;

namespace RedditQuoteBot.Core.Models
Expand All @@ -15,4 +12,4 @@ internal class ChildData
[JsonPropertyName("data")]
public CommentData? Data { get; set; }
}
}
}
4 changes: 1 addition & 3 deletions Core/Models/CommentData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using RedditQuoteBot.Core.Converters;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.Json.Serialization;

namespace RedditQuoteBot.Core.Models
Expand Down Expand Up @@ -56,4 +54,4 @@ internal class CommentData
[JsonPropertyName("body")]
public string? Body { get; set; }
}
}
}
6 changes: 2 additions & 4 deletions Core/Models/ListingData.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.Json.Serialization;

namespace RedditQuoteBot.Core.Models
Expand All @@ -24,4 +22,4 @@ internal class ListingData
[JsonPropertyName("children")]
public IList<ChildData>? Children { get; set; }
}
}
}
8 changes: 2 additions & 6 deletions Core/Models/ListingResponse.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace RedditQuoteBot.Core.Models
{
Expand All @@ -14,4 +10,4 @@ internal class ListingResponse
[JsonPropertyName("data")]
public ListingData? Data { get; set; }
}
}
}
14 changes: 10 additions & 4 deletions Core/RedditClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public RedditClient(
Subreddits = subreddits;
TriggerPhrases = triggerPhrases;
Quotes = quotes;
IgnoredUserNames = ignoredUserNames ?? IgnoredUserNames;
IgnoredUserNames = ignoredUserNames ?? new List<string>();

ApplicationName = (!string.IsNullOrEmpty(applicationName) ? applicationName : Assembly.GetEntryAssembly().GetName().Name)!;
ApplicationVersion = (!string.IsNullOrEmpty(applicationVersion) ? applicationVersion : Assembly.GetEntryAssembly().GetName().Version.ToString())!;
Expand Down Expand Up @@ -215,7 +215,7 @@ private async Task ThrottleRequestsAsync(CancellationToken cancellationToken)
Console.WriteLine();
var ratelimit = TimeSpan.FromTicks(Math.Max(Ratelimit.Ticks, _minRatelimit.Ticks));
var availableAt = LastRequest.Add(ratelimit);

if (DateTime.UtcNow < availableAt)
{
var availableIn = availableAt.Subtract(DateTime.UtcNow);
Expand Down Expand Up @@ -256,6 +256,9 @@ private async Task AuthenticateAsync(CancellationToken cancellationToken)
string responseContent = await response.Content.ReadAsStringAsync();
AccessTokenResponse = JsonSerializer.Deserialize<AccessTokenResponse>(responseContent);

if (AccessTokenResponse?.Token == null)
throw new InvalidOperationException("Failed to receive access token.");

_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Bearer",
AccessTokenResponse.Token);
Expand Down Expand Up @@ -298,6 +301,9 @@ private async Task<IEnumerable<CommentData>> GetCommentsAsync(string subreddit,
var responseContent = await response.Content.ReadAsStreamAsync();
result = await JsonSerializer.DeserializeAsync<ListingResponse>(responseContent, null, cancellationToken);

if (result == null)
throw new InvalidOperationException("Failed to receive listing response.");

Console.WriteLine("succeeded.");
}
catch (TaskCanceledException)
Expand All @@ -310,7 +316,7 @@ private async Task<IEnumerable<CommentData>> GetCommentsAsync(string subreddit,
Console.WriteLine("failed.");
Console.WriteLine(ex);
throw;
}
}

if (result.Data == null)
return new List<CommentData>();
Expand Down Expand Up @@ -454,4 +460,4 @@ public HistoryEntry(CommentData comment, int quoteId)
public DateTime CreatedLocal { get => CreatedUtc.ToLocalTime(); }
}
}
}
}
Binary file removed Core/RedditQuoteBot.pfx
Binary file not shown.
Binary file added Core/RedditQuoteBot.snk
Binary file not shown.

0 comments on commit 04fe419

Please sign in to comment.