From d4f46b4fb6dfd2672a5205ec9de12050a940f56c Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sun, 18 Jun 2023 07:03:47 +0200 Subject: Partial refactor --- .gitignore | 1 + MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj | 27 ++++++++++++++++++++++ MatrixRoomUtils.Bot/Program.cs | 2 ++ MatrixRoomUtils.Core/Attributes/TraceAttribute.cs | 10 ++++++++ .../Interfaces/IStorageProvider.cs | 15 ------------ .../Interfaces/Services/IStorageProvider.cs | 17 ++++++++++++++ .../Responses/StateEventResponse.cs | 2 +- MatrixRoomUtils.Core/Room.cs | 1 + MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs | 1 + MatrixRoomUtils.Core/Services/HomeserverService.cs | 8 +++++++ .../Services/TieredStorageService.cs | 9 ++++++++ .../Classes/LocalStorageProviderService.cs | 7 +++++- MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj | 1 + .../Pages/KnownHomeserverList.razor | 1 + .../Pages/PolicyList/PolicyListEditorPage.razor | 1 + .../Pages/RoomManager/RoomManagerSpace.razor | 1 + .../Pages/RoomManager/RoomManagerTimeline.razor | 1 + .../Pages/RoomState/RoomStateEditorPage.razor | 1 + MatrixRoomUtils.Web/Program.cs | 20 ++++++++++++++-- .../SessionStorageProviderService.cs | 6 ++++- .../TimelineComponents/TimelineMessageItem.razor | 1 + MatrixRoomUtils.sln | 6 +++++ MatrixRoomUtils.sln.DotSettings.user | 4 ++++ README.MD | 13 +++++++++++ 24 files changed, 136 insertions(+), 20 deletions(-) create mode 100644 MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj create mode 100644 MatrixRoomUtils.Bot/Program.cs create mode 100644 MatrixRoomUtils.Core/Attributes/TraceAttribute.cs delete mode 100644 MatrixRoomUtils.Core/Interfaces/IStorageProvider.cs create mode 100644 MatrixRoomUtils.Core/Interfaces/Services/IStorageProvider.cs create mode 100644 MatrixRoomUtils.Core/Services/HomeserverService.cs create mode 100644 MatrixRoomUtils.Core/Services/TieredStorageService.cs create mode 100644 README.MD diff --git a/.gitignore b/.gitignore index 340c3ab..47d212e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ MatrixRoomUtils.Web/wwwroot/MRU.tar.xz /src/ *.tar.xz matrix-sync.json +/patches/ diff --git a/MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj b/MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj new file mode 100644 index 0000000..8ff14c4 --- /dev/null +++ b/MatrixRoomUtils.Bot/MatrixRoomUtils.Bot.csproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + preview + enable + enable + true + true + true + true + true + true + true + true + + + + + + + + + + + diff --git a/MatrixRoomUtils.Bot/Program.cs b/MatrixRoomUtils.Bot/Program.cs new file mode 100644 index 0000000..83fa4f4 --- /dev/null +++ b/MatrixRoomUtils.Bot/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/MatrixRoomUtils.Core/Attributes/TraceAttribute.cs b/MatrixRoomUtils.Core/Attributes/TraceAttribute.cs new file mode 100644 index 0000000..34a0b67 --- /dev/null +++ b/MatrixRoomUtils.Core/Attributes/TraceAttribute.cs @@ -0,0 +1,10 @@ +using System.Runtime.CompilerServices; + +namespace MatrixRoomUtils.Core.Attributes; + +[AttributeUsage(AttributeTargets.All)] +public class TraceAttribute : Attribute { + public TraceAttribute([CallerMemberName] string callerName = "") { + Console.WriteLine($"{callerName} called!"); + } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/Interfaces/IStorageProvider.cs b/MatrixRoomUtils.Core/Interfaces/IStorageProvider.cs deleted file mode 100644 index e1a066e..0000000 --- a/MatrixRoomUtils.Core/Interfaces/IStorageProvider.cs +++ /dev/null @@ -1,15 +0,0 @@ -public interface IStorageProvider { - // save - public async Task SaveAll() { - Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement Save()!"); - } - - public async Task SaveObject(string key, T value) { - Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObject(key, value)!"); - } - - // delete - public async Task DeleteObject(string key) { - Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement DeleteObject(key)!"); - } -} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/Interfaces/Services/IStorageProvider.cs b/MatrixRoomUtils.Core/Interfaces/Services/IStorageProvider.cs new file mode 100644 index 0000000..2540ad7 --- /dev/null +++ b/MatrixRoomUtils.Core/Interfaces/Services/IStorageProvider.cs @@ -0,0 +1,17 @@ +namespace MatrixRoomUtils.Core.Interfaces.Services; + +public interface IStorageProvider { + // save + public async Task SaveAll() { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement Save()!"); + } + + public async Task SaveObject(string key, T value) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObject(key, value)!"); + } + + // delete + public async Task DeleteObject(string key) { + Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement DeleteObject(key)!"); + } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/Responses/StateEventResponse.cs b/MatrixRoomUtils.Core/Responses/StateEventResponse.cs index 36f0a36..7b138e0 100644 --- a/MatrixRoomUtils.Core/Responses/StateEventResponse.cs +++ b/MatrixRoomUtils.Core/Responses/StateEventResponse.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -namespace MatrixRoomUtils.Core; +namespace MatrixRoomUtils.Core.Responses; public class StateEventResponse : StateEvent { [JsonPropertyName("origin_server_ts")] diff --git a/MatrixRoomUtils.Core/Room.cs b/MatrixRoomUtils.Core/Room.cs index 2d6dc46..4f6bbca 100644 --- a/MatrixRoomUtils.Core/Room.cs +++ b/MatrixRoomUtils.Core/Room.cs @@ -3,6 +3,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using System.Web; using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.Responses; using MatrixRoomUtils.Core.RoomTypes; namespace MatrixRoomUtils.Core; diff --git a/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs b/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs index e8d4823..7f634dc 100644 --- a/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs +++ b/MatrixRoomUtils.Core/RoomTypes/SpaceRoom.cs @@ -1,5 +1,6 @@ using System.Text.Json; using MatrixRoomUtils.Core.Extensions; +using MatrixRoomUtils.Core.Responses; namespace MatrixRoomUtils.Core.RoomTypes; diff --git a/MatrixRoomUtils.Core/Services/HomeserverService.cs b/MatrixRoomUtils.Core/Services/HomeserverService.cs new file mode 100644 index 0000000..ba48e6c --- /dev/null +++ b/MatrixRoomUtils.Core/Services/HomeserverService.cs @@ -0,0 +1,8 @@ +using MatrixRoomUtils.Core.Attributes; + +namespace MatrixRoomUtils.Core.Services; + +[Trace] +public class HomeserverService { + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/Services/TieredStorageService.cs b/MatrixRoomUtils.Core/Services/TieredStorageService.cs new file mode 100644 index 0000000..f6beddd --- /dev/null +++ b/MatrixRoomUtils.Core/Services/TieredStorageService.cs @@ -0,0 +1,9 @@ +using MatrixRoomUtils.Core.Interfaces.Services; + +namespace MatrixRoomUtils.Core.Services; + +public class TieredStorageService { + public TieredStorageService(IStorageProvider cacheStorageProvider, IStorageProvider dataStorageProvider) { + + } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs b/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs index 0c3deec..2a9082d 100644 --- a/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs +++ b/MatrixRoomUtils.Web/Classes/LocalStorageProviderService.cs @@ -1,5 +1,10 @@ +using Blazored.LocalStorage; +using MatrixRoomUtils.Core.Interfaces.Services; + namespace MatrixRoomUtils.Web.Classes; public class LocalStorageProviderService : IStorageProvider { - + public LocalStorageProviderService(ILocalStorageService localStorageService) { + + } } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj index e1511c4..33fb062 100644 --- a/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj +++ b/MatrixRoomUtils.Web/MatrixRoomUtils.Web.csproj @@ -8,6 +8,7 @@ + diff --git a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor index 92a8445..8031146 100644 --- a/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor +++ b/MatrixRoomUtils.Web/Pages/KnownHomeserverList.razor @@ -2,6 +2,7 @@ @using System.Text.Json @using MatrixRoomUtils.Core.Extensions @using System.Diagnostics +@using MatrixRoomUtils.Core.Responses

Known Homeserver List


diff --git a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor index b15928a..76b4384 100644 --- a/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor +++ b/MatrixRoomUtils.Web/Pages/PolicyList/PolicyListEditorPage.razor @@ -2,6 +2,7 @@ @using MatrixRoomUtils.Core.Extensions @using MatrixRoomUtils.Core.StateEventTypes @using System.Text.Json +@using MatrixRoomUtils.Core.Responses @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

Policy list editor - Editing @RoomId

diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor index c5e1569..ab650d1 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerSpace.razor @@ -1,6 +1,7 @@ @page "/RoomManager/Space/{RoomId}" @using MatrixRoomUtils.Core.Extensions @using System.Text.Json +@using MatrixRoomUtils.Core.Responses

Room manager - Viewing Space

diff --git a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor index b90cc09..9513a8a 100644 --- a/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor +++ b/MatrixRoomUtils.Web/Pages/RoomManager/RoomManagerTimeline.razor @@ -1,5 +1,6 @@ @page "/Rooms/{RoomId}/Timeline" @using MatrixRoomUtils.Web.Shared.TimelineComponents +@using MatrixRoomUtils.Core.Responses

RoomManagerTimeline


Loaded @Events.Count events...

diff --git a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor index 74f4f92..fa5b6a8 100644 --- a/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor +++ b/MatrixRoomUtils.Web/Pages/RoomState/RoomStateEditorPage.razor @@ -1,6 +1,7 @@ @page "/RoomStateViewer/{RoomId}/Edit" @using System.Net.Http.Headers @using System.Text.Json +@using MatrixRoomUtils.Core.Responses @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager

Room state editor - Editing @RoomId

diff --git a/MatrixRoomUtils.Web/Program.cs b/MatrixRoomUtils.Web/Program.cs index 8ea8742..11e7f19 100644 --- a/MatrixRoomUtils.Web/Program.cs +++ b/MatrixRoomUtils.Web/Program.cs @@ -1,6 +1,8 @@ using System.Text.Json; using System.Text.Json.Serialization; using Blazored.LocalStorage; +using Blazored.SessionStorage; +using MatrixRoomUtils.Core.Services; using MatrixRoomUtils.Web; using MatrixRoomUtils.Web.Classes; using Microsoft.AspNetCore.Components.Web; @@ -20,9 +22,23 @@ builder.Services.AddBlazoredLocalStorage(config => { config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip; config.JsonSerializerOptions.WriteIndented = false; }); +builder.Services.AddBlazoredSessionStorage(config => { + config.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase; + config.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; + config.JsonSerializerOptions.IgnoreReadOnlyProperties = true; + config.JsonSerializerOptions.PropertyNameCaseInsensitive = true; + config.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip; + config.JsonSerializerOptions.WriteIndented = false; +}); -builder.Services.AddSingleton(); +builder.Services.AddScoped(); builder.Services.AddSingleton(); -builder.Services.AddSingleton>(); +builder.Services.AddSingleton(x => + new( + x.GetRequiredService(), + x.GetRequiredService() + ) +); await builder.Build().RunAsync(); \ No newline at end of file diff --git a/MatrixRoomUtils.Web/SessionStorageProviderService.cs b/MatrixRoomUtils.Web/SessionStorageProviderService.cs index 82372ff..d6bffe6 100644 --- a/MatrixRoomUtils.Web/SessionStorageProviderService.cs +++ b/MatrixRoomUtils.Web/SessionStorageProviderService.cs @@ -1 +1,5 @@ -public class SessionStorageProviderService { } \ No newline at end of file +using MatrixRoomUtils.Core.Interfaces.Services; + +namespace MatrixRoomUtils.Web; + +public class SessionStorageProviderService : IStorageProvider { } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor index 8d688ea..80a432b 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor @@ -1,4 +1,5 @@ @using MatrixRoomUtils.Core.Extensions +@using MatrixRoomUtils.Core.Responses
     @ObjectExtensions.ToJson(Event.Content, indent: false)
 
diff --git a/MatrixRoomUtils.sln b/MatrixRoomUtils.sln index e658c6d..a29cf89 100644 --- a/MatrixRoomUtils.sln +++ b/MatrixRoomUtils.sln @@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixRoomUtils.Core", "Mat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixRoomUtils.Web.Server", "MatrixRoomUtils.Web.Server\MatrixRoomUtils.Web.Server.csproj", "{F997F26F-2EC1-4D18-B3DD-C46FB2AD65C0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixRoomUtils.Bot", "MatrixRoomUtils.Bot\MatrixRoomUtils.Bot.csproj", "{B397700A-4ABB-4CAF-8DB8-06E01F44514B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,5 +32,9 @@ Global {F997F26F-2EC1-4D18-B3DD-C46FB2AD65C0}.Debug|Any CPU.Build.0 = Debug|Any CPU {F997F26F-2EC1-4D18-B3DD-C46FB2AD65C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {F997F26F-2EC1-4D18-B3DD-C46FB2AD65C0}.Release|Any CPU.Build.0 = Release|Any CPU + {B397700A-4ABB-4CAF-8DB8-06E01F44514B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B397700A-4ABB-4CAF-8DB8-06E01F44514B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B397700A-4ABB-4CAF-8DB8-06E01F44514B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B397700A-4ABB-4CAF-8DB8-06E01F44514B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/MatrixRoomUtils.sln.DotSettings.user b/MatrixRoomUtils.sln.DotSettings.user index 07d0701..dcd4e3e 100644 --- a/MatrixRoomUtils.sln.DotSettings.user +++ b/MatrixRoomUtils.sln.DotSettings.user @@ -3,4 +3,8 @@ + + + + \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..7bf6942 --- /dev/null +++ b/README.MD @@ -0,0 +1,13 @@ +# Project Name + +# Installation + +# Contributing + +```sh +# Prepare patch set +mkdir patches +git format-patch --output-directory "./patches" @{u}.. + +# Send patches +``` -- cgit 1.4.1