From ef4f9b4ae005a9ea531835255bfd40debdd1632f Mon Sep 17 00:00:00 2001 From: Stricted Date: Wed, 11 Nov 2015 21:22:58 +0100 Subject: [PATCH] update SyslogPage --- SpeedportHybridControl/App.xaml | 2 +- .../Data/SpeedportHybrid.cs | 2 +- .../{SyslogViewModel.cs => SyslogList.cs} | 24 +--- .../PageModel/SyslogPageModel.cs | 110 ++++++++++++++++++ .../SpeedportHybridControl.csproj | 3 +- SpeedportHybridControl/page/SyslogPage.xaml | 17 +-- .../page/SyslogPage.xaml.cs | 57 +-------- 7 files changed, 126 insertions(+), 89 deletions(-) rename SpeedportHybridControl/Model/{SyslogViewModel.cs => SyslogList.cs} (55%) create mode 100644 SpeedportHybridControl/PageModel/SyslogPageModel.cs diff --git a/SpeedportHybridControl/App.xaml b/SpeedportHybridControl/App.xaml index 26d6c36..5618ea5 100644 --- a/SpeedportHybridControl/App.xaml +++ b/SpeedportHybridControl/App.xaml @@ -14,8 +14,8 @@ + - diff --git a/SpeedportHybridControl/Data/SpeedportHybrid.cs b/SpeedportHybridControl/Data/SpeedportHybrid.cs index 3f6bb25..6710f6b 100644 --- a/SpeedportHybridControl/Data/SpeedportHybrid.cs +++ b/SpeedportHybridControl/Data/SpeedportHybrid.cs @@ -564,7 +564,7 @@ namespace SpeedportHybridControl.Data { if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) return; - SyslogData syslog = Application.Current.FindResource("SyslogData") as SyslogData; + SyslogPageModel syslog = Application.Current.FindResource("SyslogPageModel") as SyslogPageModel; string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/SystemMessages.json"); if (response.IsNullOrEmpty()) diff --git a/SpeedportHybridControl/Model/SyslogViewModel.cs b/SpeedportHybridControl/Model/SyslogList.cs similarity index 55% rename from SpeedportHybridControl/Model/SyslogViewModel.cs rename to SpeedportHybridControl/Model/SyslogList.cs index 6be7bae..a77d167 100644 --- a/SpeedportHybridControl/Model/SyslogViewModel.cs +++ b/SpeedportHybridControl/Model/SyslogList.cs @@ -1,24 +1,10 @@ +using System; using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace SpeedportHybridControl.Model { - public class SyslogData : SuperViewModel { - private List _syslogList; - private string _datetime; - - public List syslogList { - get { return _syslogList; } - set { SetProperty(ref _syslogList, value); } - } - - public string datetime { - get { return _datetime; } - set { SetProperty(ref _datetime, value); } - } - - public SyslogData() { - } - } - public class SyslogList : SuperViewModel { private string _message; private string _timestamp; @@ -37,7 +23,7 @@ namespace SpeedportHybridControl.Model { return string.Concat(timestamp, ": ", message); } - public SyslogList() { + public SyslogList () { } } } diff --git a/SpeedportHybridControl/PageModel/SyslogPageModel.cs b/SpeedportHybridControl/PageModel/SyslogPageModel.cs new file mode 100644 index 0000000..c223a09 --- /dev/null +++ b/SpeedportHybridControl/PageModel/SyslogPageModel.cs @@ -0,0 +1,110 @@ +using SpeedportHybridControl.Model; +using SpeedportHybridControl.Implementations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using SpeedportHybridControl.Data; +using System.Windows; + +namespace SpeedportHybridControl.PageModel { + class SyslogPageModel : SuperViewModel { + private DelegateCommand _reloadCommand; + private DelegateCommand _copyCommand; + private DelegateCommand _clearCommand; + + private string _searchText; + private SyslogList _selectedItem; + + private List _syslogList; + private List _filteredList; + private string _datetime; + + public DelegateCommand ReloadCommand { + get { return _reloadCommand; } + set { SetProperty(ref _reloadCommand, value); } + } + + public DelegateCommand CopyCommand { + get { return _copyCommand; } + set { SetProperty(ref _copyCommand, value); } + } + + public DelegateCommand ClearCommand { + get { return _clearCommand; } + set { SetProperty(ref _clearCommand, value); } + } + + public string SearchText { + get { return _searchText; } + set { + SetProperty(ref _searchText, value); + ApplyFilter(); + } + } + + public SyslogList SelectedItem { + get { return _selectedItem; } + set { SetProperty(ref _selectedItem, value); } + } + + public List syslogList { + get { return _syslogList; } + set { + SetProperty(ref _syslogList, value); + ApplyFilter(); + } + } + + public List filteredList { + get { return _filteredList; } + set { SetProperty(ref _filteredList, value); } + } + + public string datetime { + get { return _datetime; } + set { SetProperty(ref _datetime, value); } + } + + private void OnReloadCommandExecute () { + new Thread(() => { + SpeedportHybrid.initSyslog(); + }).Start(); + } + + private void OnCopyCommandExecute () { + Clipboard.SetText(SelectedItem.ToString()); + } + + private void OnClearCommandExecute () { + MessageBoxResult result = MessageBox.Show("Sollen die System-Informationen wirklich gelöscht werden?", "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); + if (result.Equals(MessageBoxResult.Yes)) { + SpeedportHybridAPI.getInstance().clearSyslog(); + SpeedportHybrid.initSyslog(); + SearchText = string.Empty; + } + } + + private void ApplyFilter () { + if (object.ReferenceEquals(syslogList, null).Equals(false)) { + List tmp = syslogList; + filteredList = tmp.Where(item => SyslogFilter(item)).ToList(); + } + } + + private bool SyslogFilter (object item) { + if (SearchText.IsNullOrEmpty().Equals(false)) { + bool a = ((item as SyslogList).message.IndexOf(SearchText, StringComparison.OrdinalIgnoreCase) >= 0); + return a; + } + + return true; + } + + public SyslogPageModel () { + ReloadCommand = new DelegateCommand(new Action(OnReloadCommandExecute)); + CopyCommand = new DelegateCommand(new Action(OnCopyCommandExecute)); + ClearCommand = new DelegateCommand(new Action(OnClearCommandExecute)); + } + } +} diff --git a/SpeedportHybridControl/SpeedportHybridControl.csproj b/SpeedportHybridControl/SpeedportHybridControl.csproj index 7ed6d62..40fee76 100644 --- a/SpeedportHybridControl/SpeedportHybridControl.csproj +++ b/SpeedportHybridControl/SpeedportHybridControl.csproj @@ -75,6 +75,7 @@ + @@ -144,10 +145,10 @@ - + AboutPage.xaml diff --git a/SpeedportHybridControl/page/SyslogPage.xaml b/SpeedportHybridControl/page/SyslogPage.xaml index 702be14..2ace5cc 100644 --- a/SpeedportHybridControl/page/SyslogPage.xaml +++ b/SpeedportHybridControl/page/SyslogPage.xaml @@ -7,19 +7,14 @@ mc:Ignorable="d" Width="Auto" Height="Auto" Title="SyslogPage"> - - - - + - + - + - + @@ -36,8 +31,8 @@ -