Skip to content

Commit 56becd9

Browse files
committed
Organize presentation by adding ServerController & helpful messages
1 parent 0ffd250 commit 56becd9

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using RealTimeWeatherMonitoringApp.Application.Interfaces;
2+
using RealTimeWeatherMonitoringApp.Application.Interfaces.Service;
3+
using RealTimeWeatherMonitoringApp.Domain.Interfaces.Service;
4+
using RealTimeWeatherMonitoringApp.Domain.Models;
5+
6+
namespace RealTimeWeatherMonitoringApp.Presentation.Controller;
7+
8+
public class ServerController
9+
{
10+
private readonly IDataChangeNotifier<WeatherData> _weatherDataNotifier;
11+
private readonly IBotPublishingService _botPublishingService;
12+
private readonly IBotEventManager<WeatherData> _weatherDataBotEventManager;
13+
14+
public ServerController(
15+
IDataChangeNotifier<WeatherData> weatherDataNotifier,
16+
IBotPublishingService botPublishingService,
17+
IBotEventManager<WeatherData> weatherDataBotEventManager)
18+
{
19+
_weatherDataNotifier = weatherDataNotifier;
20+
_botPublishingService = botPublishingService;
21+
_weatherDataBotEventManager = weatherDataBotEventManager;
22+
}
23+
24+
public void Start()
25+
{
26+
_weatherDataBotEventManager.Attach(_weatherDataNotifier, _botPublishingService);
27+
Console.WriteLine("Server:\tBots are now listening for weather data...");
28+
Console.WriteLine("Server:\t[Tip] Use weather data processor to send data to the system.");
29+
Console.WriteLine("Server:\t[Tip] Subscribe to bot notifications to receive any new events.");
30+
Console.WriteLine(new string('-', 70));
31+
}
32+
}

RealTimeWeatherMonitoringApp/Presentation/UserController.cs renamed to RealTimeWeatherMonitoringApp/Presentation/Controller/UserController.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using RealTimeWeatherMonitoringApp.Application.Interfaces.Service;
22
using RealTimeWeatherMonitoringApp.Domain.Models;
33

4-
namespace RealTimeWeatherMonitoringApp.Presentation;
4+
namespace RealTimeWeatherMonitoringApp.Presentation.Controller;
55

66
public class UserController
77
{
@@ -21,9 +21,15 @@ public void Start()
2121
_botNotificationService.OnBotNotification += (_, args) =>
2222
Console.WriteLine($"\n{args.BotName}: {args.Message}");
2323

24+
Console.WriteLine("User:\tSubscribed to bot notifications.");
25+
Console.WriteLine("User:\tYou can now enter weather data to process.");
26+
Console.WriteLine("User:\t[Tip] No need to specify data format, the system auto detects it.");
27+
Console.WriteLine("User:\t[Tip] Enter (q) to quit.");
28+
2429
while (true)
2530
{
26-
Console.WriteLine("\nEnter weather data, or (q) to quit:");
31+
Console.WriteLine(new string('-', 70));
32+
Console.WriteLine("User: Enter weather data to process.");
2733

2834
var input = Console.ReadLine() ?? string.Empty;
2935
if (input.Equals("q", StringComparison.CurrentCultureIgnoreCase)) break;
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
using Microsoft.Extensions.DependencyInjection;
2-
using RealTimeWeatherMonitoringApp.Application.Interfaces;
3-
using RealTimeWeatherMonitoringApp.Application.Interfaces.Service;
4-
using RealTimeWeatherMonitoringApp.Domain.Interfaces.Service;
5-
using RealTimeWeatherMonitoringApp.Domain.Models;
6-
using RealTimeWeatherMonitoringApp.Presentation;
2+
using RealTimeWeatherMonitoringApp.Presentation.Controller;
73
using RealTimeWeatherMonitoringApp.Presentation.Utility;
84

95
// Inject Dependencies
106
var provider = DependencyInjector.CreateServiceProvider();
117

12-
// Initialize Bot Events
13-
var weatherBotPublisher = provider.GetRequiredService<IBotPublishingService>();
14-
var weatherDataNotifier = provider.GetRequiredService<IDataChangeNotifier<WeatherData>>();
15-
var weatherEventManager = provider.GetRequiredService<IBotEventManager<WeatherData>>();
16-
weatherEventManager.Attach(weatherDataNotifier, weatherBotPublisher);
17-
188
// Start
9+
provider.GetRequiredService<ServerController>().Start();
1910
provider.GetRequiredService<UserController>().Start();

RealTimeWeatherMonitoringApp/Presentation/Utility/DependencyInjector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using RealTimeWeatherMonitoringApp.Infrastructure.Interfaces.Factory;
1212
using RealTimeWeatherMonitoringApp.Infrastructure.Repository;
1313
using RealTimeWeatherMonitoringApp.Infrastructure.Service;
14+
using RealTimeWeatherMonitoringApp.Presentation.Controller;
1415

1516
namespace RealTimeWeatherMonitoringApp.Presentation.Utility;
1617

@@ -72,5 +73,6 @@ private static void InjectApplication(IServiceCollection services)
7273
private static void InjectPresentation(IServiceCollection services)
7374
{
7475
services.AddSingleton<UserController>();
76+
services.AddSingleton<ServerController>();
7577
}
7678
}

0 commit comments

Comments
 (0)