From: Stricted Date: Wed, 11 Nov 2015 20:22:58 +0000 (+0100) Subject: update SyslogPage X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ef4f9b4ae005a9ea531835255bfd40debdd1632f;p=GitHub%2FStricted%2FSpeedportHybridControl.git update SyslogPage --- 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/SyslogList.cs b/SpeedportHybridControl/Model/SyslogList.cs new file mode 100644 index 0000000..a77d167 --- /dev/null +++ b/SpeedportHybridControl/Model/SyslogList.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SpeedportHybridControl.Model { + public class SyslogList : SuperViewModel { + private string _message; + private string _timestamp; + + public string message { + get { return _message; } + set { SetProperty(ref _message, value); } + } + + public string timestamp { + get { return _timestamp; } + set { SetProperty(ref _timestamp, value); } + } + + public override string ToString () { + return string.Concat(timestamp, ": ", message); + } + + public SyslogList () { + } + } +} diff --git a/SpeedportHybridControl/Model/SyslogViewModel.cs b/SpeedportHybridControl/Model/SyslogViewModel.cs deleted file mode 100644 index 6be7bae..0000000 --- a/SpeedportHybridControl/Model/SyslogViewModel.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections.Generic; - -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; - - public string message { - get { return _message; } - set { SetProperty(ref _message, value); } - } - - public string timestamp { - get { return _timestamp; } - set { SetProperty(ref _timestamp, value); } - } - - public override string ToString () { - return string.Concat(timestamp, ": ", message); - } - - 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 @@ -