-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMessageBoardViewModel.cs
More file actions
83 lines (74 loc) · 1.93 KB
/
MessageBoardViewModel.cs
File metadata and controls
83 lines (74 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using FireCore.Services;
using FireCore.Services.Hubs;
namespace FireCore.Models
{
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using System;
using System.ComponentModel;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
public class MessageBoardViewModel : INotifyPropertyChanged
{
private IHubContext<AzureChat>? _hubContext;
private readonly IHubCommander? _commander;
private readonly HttpClient? _httpClient;
private readonly ILogger<MessageBoardViewModel> _logger;
public MessageBoardViewModel(IHubContext<AzureChat> hubContext, IHubCommander? commander, ILogger<MessageBoardViewModel> logger, HttpClient? httpClient)
{
_hubContext = hubContext;
_commander = commander;
_logger = logger;
_httpClient = httpClient;
Initialize().ConfigureAwait(false);
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string? _requestId;
public string? RequestId
{
get => _requestId;
set
{
if (_requestId != value)
{
_requestId = value;
OnPropertyChanged(nameof(RequestId));
ShowRequestId = !string.IsNullOrEmpty(_requestId);
}
}
}
private bool _showRequestId;
public bool ShowRequestId
{
get => _showRequestId;
set
{
if (_showRequestId != value)
{
_showRequestId = value;
OnPropertyChanged(nameof(ShowRequestId));
}
}
}
public Task Initialize()
{
try
{
if (AzureChat.ConnectedIds is null) return Task.CompletedTask;
var users = AzureChat.ConnectedIds?.Select(t => t.Value).ToList();
_commander!.MsalCurrentUsers = users!.ToList();
}
catch (Exception e)
{
_logger.LogWarning(e, "Error initializing MessageBoardViewModel");
return Task.FromException(e);
}
return Task.CompletedTask;
}
}
}