about summary refs log tree commit diff
path: root/Tests/TestDataGenerator
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/TestDataGenerator')
-rw-r--r--Tests/TestDataGenerator/Bot/DataFetcher.cs27
-rw-r--r--Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs2
-rw-r--r--Tests/TestDataGenerator/Program.cs8
3 files changed, 12 insertions, 25 deletions
diff --git a/Tests/TestDataGenerator/Bot/DataFetcher.cs b/Tests/TestDataGenerator/Bot/DataFetcher.cs
index b1f8402..5e8c1a1 100644
--- a/Tests/TestDataGenerator/Bot/DataFetcher.cs
+++ b/Tests/TestDataGenerator/Bot/DataFetcher.cs
@@ -1,25 +1,17 @@
-using System.Text;
-using System.Threading.Channels;
 using ArcaneLibs.Extensions;
 using LibMatrix.EventTypes.Spec;
-using LibMatrix.EventTypes.Spec.State;
-using LibMatrix.Helpers;
 using LibMatrix.Homeservers;
-using LibMatrix.Interfaces;
 using LibMatrix.RoomTypes;
-using LibMatrix.Services;
-using LibMatrix.Tests;
 using LibMatrix.Utilities.Bot;
-using LibMatrix.Utilities.Bot.Interfaces;
 using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Logging;
 
-namespace PluralContactBotPoC.Bot;
+#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
 
-public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher> logger, LibMatrixBotConfiguration botConfiguration,
-    // DataFetcherConfiguration configuration,
-    HomeserverResolverService hsResolver) : IHostedService {
-    private Task _listenerTask;
+namespace TestDataGenerator.Bot;
+
+public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher> logger, LibMatrixBotConfiguration botConfiguration) : IHostedService {
+    private Task? _listenerTask;
 
     private GenericRoom? _logRoom;
 
@@ -32,7 +24,7 @@ public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher>
 
     private async Task Run(CancellationToken cancellationToken) {
         Directory.GetFiles("bot_data/cache").ToList().ForEach(File.Delete);
-        _logRoom = hs.GetRoom(botConfiguration.LogRoom);
+        _logRoom = hs.GetRoom(botConfiguration.LogRoom!);
 
         await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Test data collector started!"));
         await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Fetching rooms..."));
@@ -42,16 +34,14 @@ public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher>
 
         await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: "Fetching room data..."));
 
-        Config cfg = new Config();
-
         var roomAliasTasks = rooms.Select(room => room.GetCanonicalAliasAsync()).ToAsyncEnumerable();
         List<Task<(string, string)>> aliasResolutionTasks = new();
         await foreach (var @event in roomAliasTasks) {
             if (@event?.Alias != null) {
                 await _logRoom.SendMessageEventAsync(new RoomMessageEventContent(body: $"Fetched room alias {(@event).Alias}!"));
-                aliasResolutionTasks.Add(Task<(string, string)>.Run(async () => {
+                aliasResolutionTasks.Add(Task.Run(async () => {
                     var alias = await hs.ResolveRoomAliasAsync(@event.Alias);
-                    return (@event.Alias, @alias.RoomId);
+                    return (@event.Alias, alias.RoomId);
                 }, cancellationToken));
             }
         }
@@ -65,5 +55,6 @@ public class DataFetcher(AuthenticatedHomeserverGeneric hs, ILogger<DataFetcher>
     /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param>
     public async Task StopAsync(CancellationToken cancellationToken) {
         logger.LogInformation("Shutting down bot!");
+        _listenerTask?.Dispose();
     }
 }
diff --git a/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs b/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs
index 06df0eb..a586d05 100644
--- a/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs
+++ b/Tests/TestDataGenerator/Bot/DataFetcherConfiguration.cs
@@ -1,6 +1,6 @@
 using Microsoft.Extensions.Configuration;
 
-namespace PluralContactBotPoC.Bot;
+namespace TestDataGenerator.Bot;
 
 public class DataFetcherConfiguration {
     public DataFetcherConfiguration(IConfiguration config) => config.GetRequiredSection("DataFetcher").Bind(this);
diff --git a/Tests/TestDataGenerator/Program.cs b/Tests/TestDataGenerator/Program.cs
index 18ba61e..5d36215 100644
--- a/Tests/TestDataGenerator/Program.cs
+++ b/Tests/TestDataGenerator/Program.cs
@@ -1,19 +1,15 @@
 // See https://aka.ms/new-console-template for more information
 
-using System.Text.Json;
-using System.Text.Json.Serialization;
-using ArcaneLibs.Extensions;
 using LibMatrix.Services;
 using LibMatrix.Utilities.Bot;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
-using PluralContactBotPoC;
-using PluralContactBotPoC.Bot;
+using TestDataGenerator.Bot;
 
 Console.WriteLine("Hello, World!");
 
 var host = Host.CreateDefaultBuilder(args).ConfigureServices((_, services) => {
-    services.AddScoped<TieredStorageService>(x =>
+    services.AddScoped<TieredStorageService>(_ =>
         new TieredStorageService(
             cacheStorageProvider: new FileStorageProvider("bot_data/cache/"),
             dataStorageProvider: new FileStorageProvider("bot_data/data/")