-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainModel.cs
107 lines (92 loc) · 2.7 KB
/
MainModel.cs
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows.Data;
using RDPShadow.Entities;
using TinyMVVM;
namespace RDPShadow
{
public class MainModel : ObservableObject
{
private bool _enableSessionSelect;
private ObservableCollection<Session> _sessions;
private ObservableCollection<ComputerModel> _computers;
private ICollectionView _computersView;
private ICollectionView _sessionsView;
private bool _allowControl;
public MainModel()
{
Computers = new ObservableCollection<ComputerModel>();
Sessions = new ObservableCollection<Session>();
}
public bool AllowControl
{
get => _allowControl;
set
{
_allowControl = value;
OnPropertyChanged();
}
}
public ComputerModel SelectedComputer => ComputersView.CurrentItem as ComputerModel;
public Session SelectedSession => SessionsView.CurrentItem as Session;
public ICollectionView ComputersView
{
get => _computersView;
set
{
_computersView = value;
OnPropertyChanged();
}
}
public ICollectionView SessionsView
{
get => _sessionsView;
set
{
_sessionsView = value;
OnPropertyChanged();
}
}
public bool EnableSessionSelect
{
get => _enableSessionSelect;
set
{
_enableSessionSelect = value;
OnPropertyChanged();
}
}
public ObservableCollection<ComputerModel> Computers
{
get => _computers;
set
{
if (NotNullGuard(value)) return;
_computers = value;
ComputersView = CollectionViewSource.GetDefaultView(_computers);
OnPropertyChanged();
}
}
public ObservableCollection<Session> Sessions
{
get => _sessions;
set
{
if(NotNullGuard(value))return;
_sessions = value;
SessionsView = CollectionViewSource.GetDefaultView(_sessions);
OnPropertyChanged();
}
}
private bool NotNullGuard(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(Computers));
if (_computers == value) return true;
return false;
}
}
}