Skip to content

Commit

Permalink
Add more logging
Browse files Browse the repository at this point in the history
Reorganize samples
  • Loading branch information
WilStead committed Nov 6, 2024
1 parent 6347a39 commit 29c5e8c
Show file tree
Hide file tree
Showing 52 changed files with 110 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: publish
env:
VERSION: '0.9.2-preview'
VERSION: '0.9.3-preview'
PRERELEASE: true
on:
push:
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.3-preview
### Added
- Additional logging

## 0.9.1-2-preview
### Updated
- Update dependencies
Expand Down
5 changes: 5 additions & 0 deletions sample/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<UseArtifactsOutput>true</UseArtifactsOutput>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Client\Tavenem.Wiki.Blazor.Client.csproj" />
<ProjectReference Include="..\..\..\src\Client\Tavenem.Wiki.Blazor.Client.csproj" />
</ItemGroup>

</Project>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Server\Tavenem.Wiki.Blazor.Server.csproj" />
<ProjectReference Include="..\..\..\src\Server\Tavenem.Wiki.Blazor.Server.csproj" />
<ProjectReference Include="..\Tavenem.Wiki.Blazor.Example.Client\Tavenem.Wiki.Blazor.Example.Client.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.10" />
</ItemGroup>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Client\Tavenem.Wiki.Blazor.Client.csproj" />
<ProjectReference Include="..\..\src\Client\Tavenem.Wiki.Blazor.Client.csproj" />
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions src/Client/Internal/WikiState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public string DisplayTitle
/// </summary>
public bool LoadError { get; internal set; }

private bool _notAuthorized;
/// <summary>
/// <para>
/// Whether the current user is not authorized to complete the current action (e.g. view or edit
Expand All @@ -58,8 +57,8 @@ public string DisplayTitle
/// </summary>
public bool NotAuthorized
{
get => _notAuthorized;
set => _notAuthorized |= value;
get;

Check failure on line 60 in src/Client/Internal/WikiState.cs

View workflow job for this annotation

GitHub Actions / build, pack, publish, and release

'WikiState.NotAuthorized.get' must declare a body because it is not marked abstract, extern, or partial

Check failure on line 60 in src/Client/Internal/WikiState.cs

View workflow job for this annotation

GitHub Actions / build, pack, publish, and release

'WikiState.NotAuthorized.get' must declare a body because it is not marked abstract, extern, or partial
set => field |= value;
}

/// <summary>
Expand Down
129 changes: 92 additions & 37 deletions src/Client/Services/WikiDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Net.Http.Json;
using System.Security.Claims;
using System.Text;
Expand All @@ -20,13 +21,16 @@ namespace Tavenem.Wiki.Blazor.Client.Services;
/// </summary>
public class WikiDataService(
LocalWikiDataService localWikiDataService,
ILoggerFactory loggerFactory,
NavigationManager navigationManager,
IServiceProvider serviceProvider,
SnackbarService snackbarService,
WikiBlazorClientOptions wikiBlazorClientOptions,
WikiOptions wikiOptions,
WikiState wikiState)
{
private readonly ILogger _logger = loggerFactory.CreateLogger("Wiki");

private AuthenticationStateProvider? _authenticationStateProvider;
private HttpClient? _httpClient;

Expand Down Expand Up @@ -373,7 +377,11 @@ public Task<bool> EditAsync(EditRequest request, string? failMessage = null) =>
}
catch (Exception ex)
{
Console.WriteLine(ex);
_logger.Log(
LogLevel.Error,
ex,
"Error getting talk messages for wiki item with title {Title}.",
title);
snackbarService.Add("An error occurred", ThemeColor.Danger);
}
return messages;
Expand Down Expand Up @@ -578,6 +586,9 @@ public Task RestoreArchiveAsync(Archive archive) => PostAsync(
}
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
_logger.LogWarning(
"Bad request when fetching data from url {URL}.",
url);
snackbarService.Add(response.ReasonPhrase ?? "Invalid operation", ThemeColor.Warning);
return default;
}
Expand All @@ -595,7 +606,11 @@ public Task RestoreArchiveAsync(Archive archive) => PostAsync(
catch (HttpRequestException) { }
catch (Exception ex)
{
Console.WriteLine(ex);
_logger.Log(
LogLevel.Error,
ex,
"Error fetching data from url {URL}.",
url);
snackbarService.Add("An error occurred", ThemeColor.Danger);
return default;
}
Expand All @@ -614,6 +629,11 @@ public Task RestoreArchiveAsync(Archive archive) => PostAsync(
}
catch (Exception ex)
{
_logger.Log(
LogLevel.Error,
ex,
"Error fetching data locally for url {URL}.",
url);
wikiState.LoadError = true;
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return default;
Expand Down Expand Up @@ -661,6 +681,9 @@ private async Task<int> FetchIntAsync(
}
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
_logger.LogWarning(
"Bad request when fetching data from url {URL}.",
url);
snackbarService.Add(response.ReasonPhrase ?? "Invalid operation", ThemeColor.Warning);
return 0;
}
Expand All @@ -681,7 +704,11 @@ private async Task<int> FetchIntAsync(
catch (HttpRequestException) { }
catch (Exception ex)
{
Console.WriteLine(ex);
_logger.Log(
LogLevel.Error,
ex,
"Error fetching data from url {URL}.",
url);
snackbarService.Add("An error occurred", ThemeColor.Danger);
return 0;
}
Expand All @@ -698,13 +725,13 @@ private async Task<int> FetchIntAsync(
HandleUnauthorized(state);
return 0;
}
catch (InvalidOperationException ex)
{
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return 0;
}
catch (ArgumentException ex)
catch (Exception ex)
{
_logger.Log(
LogLevel.Error,
ex,
"Error fetching data locally for url {URL}.",
url);
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return 0;
}
Expand Down Expand Up @@ -751,6 +778,9 @@ private async Task<int> FetchIntAsync(
}
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
_logger.LogWarning(
"Bad request when fetching data from url {URL}.",
url);
snackbarService.Add(response.ReasonPhrase ?? "Invalid operation", ThemeColor.Warning);
return null;
}
Expand All @@ -771,7 +801,11 @@ private async Task<int> FetchIntAsync(
catch (HttpRequestException) { }
catch (Exception ex)
{
Console.WriteLine(ex);
_logger.Log(
LogLevel.Error,
ex,
"Error fetching data from url {URL}.",
url);
snackbarService.Add("An error occurred", ThemeColor.Danger);
return null;
}
Expand All @@ -788,13 +822,13 @@ private async Task<int> FetchIntAsync(
HandleUnauthorized(state);
return null;
}
catch (InvalidOperationException ex)
{
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return null;
}
catch (ArgumentException ex)
catch (Exception ex)
{
_logger.Log(
LogLevel.Error,
ex,
"Error fetching data locally for url {URL}.",
url);
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return null;
}
Expand Down Expand Up @@ -854,6 +888,9 @@ private async Task<int> FetchIntAsync(
}
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
_logger.LogWarning(
"Bad request when posting data to url {URL}.",
url);
snackbarService.Add(response.ReasonPhrase ?? "Invalid operation", ThemeColor.Warning);
return default;
}
Expand All @@ -871,7 +908,11 @@ private async Task<int> FetchIntAsync(
catch (HttpRequestException) { }
catch (Exception ex)
{
Console.WriteLine(ex);
_logger.Log(
LogLevel.Error,
ex,
"Error posting data to url {URL}.",
url);
snackbarService.Add("An error occurred", ThemeColor.Danger);
return default;
}
Expand All @@ -890,13 +931,13 @@ private async Task<int> FetchIntAsync(
HandleUnauthorized(state);
return default;
}
catch (InvalidOperationException ex)
{
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return default;
}
catch (ArgumentException ex)
catch (Exception ex)
{
_logger.Log(
LogLevel.Error,
ex,
"Error posting data locally for url {URL}.",
url);
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return default;
}
Expand Down Expand Up @@ -959,6 +1000,9 @@ private async Task<bool> PostAsync<T>(
}
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
_logger.LogWarning(
"Bad request when posting data to url {URL}.",
url);
snackbarService.Add(response.ReasonPhrase ?? "Invalid operation", ThemeColor.Warning);
return false;
}
Expand All @@ -975,7 +1019,11 @@ private async Task<bool> PostAsync<T>(
catch (HttpRequestException) { }
catch (Exception ex)
{
Console.WriteLine(ex);
_logger.Log(
LogLevel.Error,
ex,
"Error posting data to url {URL}.",
url);
snackbarService.Add("An error occurred", ThemeColor.Danger);
return false;
}
Expand All @@ -997,13 +1045,13 @@ private async Task<bool> PostAsync<T>(
HandleUnauthorized(state);
return false;
}
catch (InvalidOperationException ex)
{
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return false;
}
catch (ArgumentException ex)
catch (Exception ex)
{
_logger.Log(
LogLevel.Error,
ex,
"Error posting data locally for url {URL}.",
url);
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return false;
}
Expand Down Expand Up @@ -1058,6 +1106,9 @@ private async Task<bool> PostAsync<T>(
}
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
_logger.LogWarning(
"Bad request when posting data to url {URL}.",
url);
snackbarService.Add(response.ReasonPhrase ?? "Invalid operation", ThemeColor.Warning);
return default;
}
Expand All @@ -1075,7 +1126,11 @@ private async Task<bool> PostAsync<T>(
catch (HttpRequestException) { }
catch (Exception ex)
{
Console.WriteLine(ex);
_logger.Log(
LogLevel.Error,
ex,
"Error posting data to url {URL}.",
url);
snackbarService.Add("An error occurred", ThemeColor.Danger);
return default;
}
Expand All @@ -1093,13 +1148,13 @@ private async Task<bool> PostAsync<T>(
HandleUnauthorized(state);
return default;
}
catch (InvalidOperationException ex)
{
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return default;
}
catch (ArgumentException ex)
catch (Exception ex)
{
_logger.Log(
LogLevel.Error,
ex,
"Error posting data locally for url {URL}.",
url);
snackbarService.Add(ex.Message ?? "Invalid operation", ThemeColor.Warning);
return default;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tavenem.Wiki.Blazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tavenem.Wiki.Blazor.Server"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tavenem.Wiki.Blazor.Client", "Client\Tavenem.Wiki.Blazor.Client.csproj", "{236B5D43-2022-408E-BBFD-20D516FA6EE3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tavenem.Wiki.Blazor.Sample", "..\sample\Tavenem.Wiki.Blazor.Sample.csproj", "{6EE499B5-A0BD-4B46-83B6-762F98E84FAF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tavenem.Wiki.Blazor.Sample", "..\sample\WebAssembly Example\Tavenem.Wiki.Blazor.Sample.csproj", "{6EE499B5-A0BD-4B46-83B6-762F98E84FAF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tavenem.Wiki.Blazor.Example", "Tavenem.Wiki.Blazor.Example\Tavenem.Wiki.Blazor.Example\Tavenem.Wiki.Blazor.Example.csproj", "{1E3B3151-F952-4631-9131-DCCE67EB9CDA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tavenem.Wiki.Blazor.Example", "..\sample\Web App Example\Tavenem.Wiki.Blazor.Example\Tavenem.Wiki.Blazor.Example.csproj", "{1E3B3151-F952-4631-9131-DCCE67EB9CDA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tavenem.Wiki.Blazor.Example.Client", "Tavenem.Wiki.Blazor.Example\Tavenem.Wiki.Blazor.Example.Client\Tavenem.Wiki.Blazor.Example.Client.csproj", "{952E9D86-1472-4533-B825-8EB1FAA9EF82}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tavenem.Wiki.Blazor.Example.Client", "..\sample\Web App Example\Tavenem.Wiki.Blazor.Example.Client\Tavenem.Wiki.Blazor.Example.Client.csproj", "{952E9D86-1472-4533-B825-8EB1FAA9EF82}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit 29c5e8c

Please sign in to comment.