Dreamine.Communication.Wpf
1.0.2
Dreamine.Communication.Wpf 통신 기능과 관련 API를 제공합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
CommunicationMonitorViewModel.cs
이 파일의 문서화 페이지로 가기
1
using
System.Collections.ObjectModel;
2
using
System.ComponentModel;
3
using
System.Runtime.CompilerServices;
4
using
System.Text;
5
using
System.Windows.Input;
6
using
Dreamine.Communication.Abstractions.Enums;
7
using
Dreamine.Communication.Abstractions.Models;
8
using
Dreamine.Communication.Wpf.Commands
;
9
using
Dreamine.Communication.Wpf.Models
;
10
11
namespace
Dreamine.Communication.Wpf.ViewModels
;
12
21
public
sealed
class
CommunicationMonitorViewModel
: INotifyPropertyChanged
22
{
31
private
CommunicationChannelViewItem
?
_selectedChannel
;
32
41
public
CommunicationMonitorViewModel
()
42
{
43
ClearLogsCommand
=
new
DelegateCommand
(_ =>
ClearLogs
());
44
}
45
54
public
event
PropertyChangedEventHandler?
PropertyChanged
;
55
64
public
ObservableCollection<CommunicationChannelViewItem>
Channels
{
get
; } =
new
();
65
74
public
ObservableCollection<CommunicationMessageLogItem>
Logs
{
get
; } =
new
();
75
84
public
CommunicationChannelViewItem
?
SelectedChannel
85
{
86
get
=>
_selectedChannel
;
87
set
=> SetProperty(ref
_selectedChannel
, value);
88
}
89
98
public
ICommand
ClearLogsCommand
{
get
; }
99
140
public
void
AddChannel
(
string
name, TransportKind kind,
string
description =
""
)
141
{
142
ArgumentException.ThrowIfNullOrWhiteSpace(name);
143
144
if
(
Channels
.Any(x => x.Name == name))
145
{
146
return
;
147
}
148
149
Channels
.Add(
new
CommunicationChannelViewItem
150
{
151
Name = name,
152
Kind = kind,
153
State = ConnectionState.Disconnected,
154
Description = description
155
});
156
}
157
182
public
void
UpdateChannelState
(
string
name, ConnectionState state)
183
{
184
ArgumentException.ThrowIfNullOrWhiteSpace(name);
185
186
var channel =
Channels
.FirstOrDefault(x => x.Name == name);
187
188
if
(channel is
null
)
189
{
190
return
;
191
}
192
193
channel.State = state;
194
}
195
220
public
void
UpdateChannelDescription
(
string
name,
string
description)
221
{
222
ArgumentException.ThrowIfNullOrWhiteSpace(name);
223
224
var channel =
Channels
.FirstOrDefault(x => x.Name == name);
225
226
if
(channel is
null
)
227
{
228
return
;
229
}
230
231
channel.Description = description ??
string
.Empty;
232
}
233
266
public
void
AddSendLog
(
string
channelName, TransportKind kind, MessageEnvelope message)
267
{
268
AddMessageLog
(channelName, kind,
"SEND"
, message);
269
}
270
303
public
void
AddReceiveLog
(
string
channelName, TransportKind kind, MessageEnvelope message)
304
{
305
AddMessageLog
(channelName, kind,
"RECV"
, message);
306
}
307
316
public
void
ClearLogs
()
317
{
318
Logs
.Clear();
319
}
320
361
private
void
AddMessageLog
(
362
string
channelName,
363
TransportKind kind,
364
string
direction,
365
MessageEnvelope message)
366
{
367
ArgumentException.ThrowIfNullOrWhiteSpace(channelName);
368
ArgumentNullException.ThrowIfNull(message);
369
370
Logs
.Insert(0,
new
CommunicationMessageLogItem
371
{
372
ChannelName = channelName,
373
Kind = kind,
374
Direction = direction,
375
MessageName = message.Name,
376
Route = message.Route,
377
PayloadLength = message.Payload.Length,
378
PayloadPreview =
CreatePayloadPreview
(message.Payload)
379
});
380
}
381
406
private
static
string
CreatePayloadPreview
(
byte
[] payload)
407
{
408
if
(payload.Length == 0)
409
{
410
return
string
.Empty;
411
}
412
413
var text = Encoding.UTF8.GetString(payload);
414
415
if
(text.Length <= 120)
416
{
417
return
text;
418
}
419
420
return
text[..120] +
"..."
;
421
}
422
463
private
void
SetProperty<T>
(
464
ref T storage,
465
T value,
466
[CallerMemberName]
string
? propertyName =
null
)
467
{
468
if
(EqualityComparer<T>.Default.Equals(storage, value))
469
{
470
return
;
471
}
472
473
storage = value;
474
PropertyChanged
?.Invoke(
this
,
new
PropertyChangedEventArgs(propertyName));
475
}
476
}
Dreamine.Communication.Wpf.Commands
Definition
DelegateCommand.cs:4
Dreamine.Communication.Wpf.Models
Definition
CommunicationChannelViewItem.cs:5
Dreamine.Communication.Wpf.ViewModels
Definition
CommunicationMonitorViewModel.cs:11
Dreamine.Communication.Wpf.Commands.DelegateCommand
Definition
DelegateCommand.cs:15
Dreamine.Communication.Wpf.Models.CommunicationChannelViewItem
Definition
CommunicationChannelViewItem.cs:16
Dreamine.Communication.Wpf.Models.CommunicationMessageLogItem
Definition
CommunicationMessageLogItem.cs:14
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.AddChannel
void AddChannel(string name, TransportKind kind, string description="")
Definition
CommunicationMonitorViewModel.cs:140
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel._selectedChannel
CommunicationChannelViewItem? _selectedChannel
Definition
CommunicationMonitorViewModel.cs:31
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.UpdateChannelDescription
void UpdateChannelDescription(string name, string description)
Definition
CommunicationMonitorViewModel.cs:220
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.CreatePayloadPreview
static string CreatePayloadPreview(byte[] payload)
Definition
CommunicationMonitorViewModel.cs:406
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.Channels
ObservableCollection< CommunicationChannelViewItem > Channels
Definition
CommunicationMonitorViewModel.cs:64
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.ClearLogs
void ClearLogs()
Definition
CommunicationMonitorViewModel.cs:316
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.SelectedChannel
CommunicationChannelViewItem? SelectedChannel
Definition
CommunicationMonitorViewModel.cs:85
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.AddSendLog
void AddSendLog(string channelName, TransportKind kind, MessageEnvelope message)
Definition
CommunicationMonitorViewModel.cs:266
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.ClearLogsCommand
ICommand ClearLogsCommand
Definition
CommunicationMonitorViewModel.cs:98
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.CommunicationMonitorViewModel
CommunicationMonitorViewModel()
Definition
CommunicationMonitorViewModel.cs:41
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.UpdateChannelState
void UpdateChannelState(string name, ConnectionState state)
Definition
CommunicationMonitorViewModel.cs:182
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.PropertyChanged
PropertyChangedEventHandler? PropertyChanged
Definition
CommunicationMonitorViewModel.cs:54
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.Logs
ObservableCollection< CommunicationMessageLogItem > Logs
Definition
CommunicationMonitorViewModel.cs:74
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.AddReceiveLog
void AddReceiveLog(string channelName, TransportKind kind, MessageEnvelope message)
Definition
CommunicationMonitorViewModel.cs:303
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.SetProperty< T >
void SetProperty< T >(ref T storage, T value, [CallerMemberName] string? propertyName=null)
Definition
CommunicationMonitorViewModel.cs:463
Dreamine.Communication.Wpf.ViewModels.CommunicationMonitorViewModel.AddMessageLog
void AddMessageLog(string channelName, TransportKind kind, string direction, MessageEnvelope message)
Definition
CommunicationMonitorViewModel.cs:361
ViewModels
CommunicationMonitorViewModel.cs
다음에 의해 생성됨 :
1.17.0