Commit | Line | Data |
---|---|---|
ef4f9b4a S |
1 | using SpeedportHybridControl.Model; |
2 | using SpeedportHybridControl.Implementations; | |
3 | using System; | |
4 | using System.Collections.Generic; | |
5 | using System.Linq; | |
6 | using System.Threading; | |
7 | using SpeedportHybridControl.Data; | |
8 | using System.Windows; | |
9 | ||
10 | namespace SpeedportHybridControl.PageModel { | |
11 | class SyslogPageModel : SuperViewModel { | |
12 | private DelegateCommand _reloadCommand; | |
13 | private DelegateCommand _copyCommand; | |
14 | private DelegateCommand _clearCommand; | |
15 | ||
16 | private string _searchText; | |
ef4f9b4a S |
17 | |
18 | private List<SyslogList> _syslogList; | |
19 | private List<SyslogList> _filteredList; | |
20 | private string _datetime; | |
21 | ||
22 | public DelegateCommand ReloadCommand { | |
23 | get { return _reloadCommand; } | |
24 | set { SetProperty(ref _reloadCommand, value); } | |
25 | } | |
26 | ||
27 | public DelegateCommand CopyCommand { | |
28 | get { return _copyCommand; } | |
29 | set { SetProperty(ref _copyCommand, value); } | |
30 | } | |
31 | ||
32 | public DelegateCommand ClearCommand { | |
33 | get { return _clearCommand; } | |
34 | set { SetProperty(ref _clearCommand, value); } | |
35 | } | |
36 | ||
37 | public string SearchText { | |
38 | get { return _searchText; } | |
39 | set { | |
40 | SetProperty(ref _searchText, value); | |
41 | ApplyFilter(); | |
42 | } | |
43 | } | |
44 | ||
ef4f9b4a S |
45 | public List<SyslogList> syslogList { |
46 | get { return _syslogList; } | |
47 | set { | |
48 | SetProperty(ref _syslogList, value); | |
49 | ApplyFilter(); | |
50 | } | |
51 | } | |
52 | ||
53 | public List<SyslogList> filteredList { | |
54 | get { return _filteredList; } | |
55 | set { SetProperty(ref _filteredList, value); } | |
56 | } | |
57 | ||
58 | public string datetime { | |
59 | get { return _datetime; } | |
60 | set { SetProperty(ref _datetime, value); } | |
61 | } | |
62 | ||
63 | private void OnReloadCommandExecute () { | |
413a0c58 | 64 | new Thread(() => { SpeedportHybrid.initSyslog(); }).Start(); |
ef4f9b4a S |
65 | } |
66 | ||
15fd2b09 S |
67 | public IEnumerable<SyslogList> SelectedItens |
68 | { | |
69 | get { return filteredList.Where(o => o.IsSelected); } | |
70 | } | |
71 | ||
ef4f9b4a | 72 | private void OnCopyCommandExecute () { |
15fd2b09 S |
73 | string text = string.Empty; |
74 | foreach (SyslogList item in SelectedItens) { | |
75 | text = string.Concat(text, Environment.NewLine, item.ToString()); | |
76 | } | |
77 | ||
78 | Clipboard.SetText(text); | |
ef4f9b4a S |
79 | } |
80 | ||
81 | private void OnClearCommandExecute () { | |
82 | MessageBoxResult result = MessageBox.Show("Sollen die System-Informationen wirklich gelöscht werden?", "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); | |
83 | if (result.Equals(MessageBoxResult.Yes)) { | |
84 | SpeedportHybridAPI.getInstance().clearSyslog(); | |
85 | SpeedportHybrid.initSyslog(); | |
86 | SearchText = string.Empty; | |
87 | } | |
88 | } | |
89 | ||
90 | private void ApplyFilter () { | |
413a0c58 S |
91 | if (object.ReferenceEquals(syslogList, null)) { |
92 | filteredList = syslogList; | |
93 | } | |
94 | else { | |
ef4f9b4a S |
95 | List<SyslogList> tmp = syslogList; |
96 | filteredList = tmp.Where(item => SyslogFilter(item)).ToList(); | |
97 | } | |
98 | } | |
99 | ||
100 | private bool SyslogFilter (object item) { | |
101 | if (SearchText.IsNullOrEmpty().Equals(false)) { | |
413a0c58 | 102 | return ((item as SyslogList).message.IndexOf(SearchText, StringComparison.OrdinalIgnoreCase) >= 0); |
ef4f9b4a S |
103 | } |
104 | ||
105 | return true; | |
106 | } | |
107 | ||
108 | public SyslogPageModel () { | |
109 | ReloadCommand = new DelegateCommand(new Action(OnReloadCommandExecute)); | |
110 | CopyCommand = new DelegateCommand(new Action(OnCopyCommandExecute)); | |
111 | ClearCommand = new DelegateCommand(new Action(OnClearCommandExecute)); | |
112 | } | |
113 | } | |
114 | } |