File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ protected override void OnStartup(StartupEventArgs e)
2323 var services = new ServiceCollection ( ) ;
2424
2525 services . AddSingleton < MainWindow > ( ) ;
26+ services . AddSingleton < MainWindowViewModel > ( ) ;
2627 services . AddSingleton < TaskCreation > ( ) ;
2728 services . AddTransient < TaskCreationViewModel > ( ) ;
2829 services . AddTransient < TaskListViewModel > ( ) ;
Original file line number Diff line number Diff line change 1111 <Grid .ColumnDefinitions>
1212 <ColumnDefinition Width =" Auto" />
1313 <ColumnDefinition />
14+ <ColumnDefinition Width =" Auto" />
1415 </Grid .ColumnDefinitions>
1516 <StackPanel Grid.Column=" 0" >
1617 <Label HorizontalAlignment =" Center" >Views</Label >
2526 </Menu >
2627 </StackPanel >
2728 <ContentControl Grid.Column=" 1" Name =" Content" />
29+ <Label Grid.Column=" 2" Content =" {Binding BackendAvailability}" />
2830 </Grid >
2931</Window >
Original file line number Diff line number Diff line change @@ -7,9 +7,11 @@ public partial class MainWindow : Window
77{
88 private readonly TaskListViewModel taskListViewModel ;
99
10- public MainWindow ( TaskListViewModel taskListViewModel )
10+ public MainWindow ( TaskListViewModel taskListViewModel , MainWindowViewModel viewModel )
1111 {
1212 this . taskListViewModel = taskListViewModel ;
13+ DataContext = viewModel ;
14+
1315 InitializeComponent ( ) ;
1416 NavigateToTaskList ( ) ;
1517 }
Original file line number Diff line number Diff line change 1+ using System . Windows . Threading ;
2+ using Desktop . Common ;
3+ using Desktop . Tasks ;
4+
5+ namespace Desktop ;
6+
7+ public class MainWindowViewModel : ViewModelBase
8+ {
9+ private readonly IRemoteTaskRepository backend ;
10+
11+ private static readonly TimeSpan CheckBackendAvailabilityInterval =
12+ TimeSpan . FromSeconds ( 2 ) ;
13+
14+ private string backendAvailability = "Available" ;
15+ private readonly DispatcherTimer periodicBackendAvailabilityCheckTimer ;
16+
17+ public string BackendAvailability
18+ {
19+ get => backendAvailability ;
20+ set
21+ {
22+ backendAvailability = value ;
23+ OnPropertyChanged ( ) ;
24+ }
25+ }
26+
27+ public MainWindowViewModel ( IRemoteTaskRepository backend )
28+ {
29+ this . backend = backend ;
30+ periodicBackendAvailabilityCheckTimer = new DispatcherTimer
31+ {
32+ Interval = CheckBackendAvailabilityInterval
33+ } ;
34+ periodicBackendAvailabilityCheckTimer . Tick += async ( _ , _ ) =>
35+ await CheckBackendAvailability ( ) ;
36+ periodicBackendAvailabilityCheckTimer . Start ( ) ;
37+ }
38+
39+ private async Task CheckBackendAvailability ( )
40+ {
41+ BackendAvailability = await backend . IsAvailable ( ) ? "Available" : "Non available" ;
42+ }
43+ }
Original file line number Diff line number Diff line change 55
66namespace Desktop . Tasks ;
77
8- public class BackendTaskRepository : ITaskRepository
8+ public class BackendTaskRepository : ITaskRepository , IRemoteTaskRepository
99{
1010 private readonly HttpClient httpClient ;
1111
@@ -14,6 +14,22 @@ public BackendTaskRepository(HttpClient httpClient)
1414 this . httpClient = httpClient ;
1515 }
1616
17+ public async Task < bool > IsAvailable ( )
18+ {
19+ try
20+ {
21+ var result = await httpClient . GetAsync ( "/health/" ) ;
22+
23+ result . EnsureSuccessStatusCode ( ) ;
24+
25+ return true ;
26+ }
27+ catch
28+ {
29+ return false ;
30+ }
31+ }
32+
1733 public async Task < IReadOnlyList < Task > > All ( )
1834 {
1935 HttpResponseMessage getResult ;
Original file line number Diff line number Diff line change @@ -25,5 +25,6 @@ public static void AddBackendTaskRepository(
2525 return httpClient ;
2626 } ) ;
2727 services . AddSingleton < ITaskRepository , BackendTaskRepository > ( ) ;
28+ services . AddSingleton < IRemoteTaskRepository , BackendTaskRepository > ( ) ;
2829 }
2930}
Original file line number Diff line number Diff line change 1+ namespace Desktop . Tasks ;
2+
3+ public interface IRemoteTaskRepository
4+ {
5+ Task < bool > IsAvailable ( ) ;
6+ }
You can’t perform that action at this time.
0 commit comments