update SyslogPage
authorStricted <info@stricted.de>
Wed, 11 Nov 2015 20:22:58 +0000 (21:22 +0100)
committerStricted <info@stricted.de>
Wed, 11 Nov 2015 20:22:58 +0000 (21:22 +0100)
SpeedportHybridControl/App.xaml
SpeedportHybridControl/Data/SpeedportHybrid.cs
SpeedportHybridControl/Model/SyslogList.cs [new file with mode: 0644]
SpeedportHybridControl/Model/SyslogViewModel.cs [deleted file]
SpeedportHybridControl/PageModel/SyslogPageModel.cs [new file with mode: 0644]
SpeedportHybridControl/SpeedportHybridControl.csproj
SpeedportHybridControl/page/SyslogPage.xaml
SpeedportHybridControl/page/SyslogPage.xaml.cs

index 26d6c36e04418ac874fc1fa74c9b84182b91ed95..5618ea558ab56f78076ea8594d338eab9340f217 100644 (file)
@@ -14,8 +14,8 @@
             <pagemodel:OverviewPageModel x:Key="OverviewPageModel"></pagemodel:OverviewPageModel>
             <pagemodel:DslPageModel x:Key="DslPageModel"></pagemodel:DslPageModel>
             <pagemodel:LteInfoModel x:Key="LteInfoModel"></pagemodel:LteInfoModel>
+            <pagemodel:SyslogPageModel x:Key="SyslogPageModel"></pagemodel:SyslogPageModel>
             
-            <model:SyslogData x:Key="SyslogData"></model:SyslogData>
             <model:TR181 x:Key="TR181"></model:TR181>
             <model:PhoneCallData x:Key="PhoneCallData"></model:PhoneCallData>
             <model:DeviceData x:Key="DeviceData"></model:DeviceData>
index 3f6bb25345bfdaea2cf5b66e6b9d09c97277647b..6710f6bad290ece0de67e00704beea104d920805 100644 (file)
@@ -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 (file)
index 0000000..a77d167
--- /dev/null
@@ -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 (file)
index 6be7bae..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-using System.Collections.Generic;
-
-namespace SpeedportHybridControl.Model {
-       public class SyslogData : SuperViewModel {
-               private List<SyslogList> _syslogList;
-               private string _datetime;
-
-               public List<SyslogList> 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 (file)
index 0000000..c223a09
--- /dev/null
@@ -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> _syslogList;
+               private List<SyslogList> _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> syslogList {
+                       get { return _syslogList; }
+                       set {
+                               SetProperty(ref _syslogList, value);
+                               ApplyFilter();
+                       }
+               }
+
+               public List<SyslogList> 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<SyslogList> 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));
+               }
+       }
+}
index 7ed6d6234925e94d38f17fa959ba4ed2aa31b292..40fee76310d34730ffe93dab3be01366e4f210fb 100644 (file)
@@ -75,6 +75,7 @@
     <Compile Include="Model\DeviceViewModel.cs" />
     <Compile Include="Model\Line.cs" />
     <Compile Include="Model\StatusPhoneListModel.cs" />
+    <Compile Include="Model\SyslogList.cs" />
     <Compile Include="PageModel\DslPageModel.cs" />
     <Compile Include="PageModel\LoginPageModel.cs" />
     <Compile Include="PageModel\LteInfoModel.cs" />
     </Page>
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Model\SyslogViewModel.cs" />
     <Compile Include="Model\TR181ViewModel.cs" />
     <Compile Include="PageModel\OverviewPageModel.cs" />
     <Compile Include="PageModel\StatusPageModel.cs" />
+    <Compile Include="PageModel\SyslogPageModel.cs" />
     <Compile Include="page\AboutPage.xaml.cs">
       <DependentUpon>AboutPage.xaml</DependentUpon>
     </Compile>
index 702be148b96c4af266c160eb056ef71033f99a72..2ace5cc2451c6934e1ff7f08fb427c840fddd7f2 100644 (file)
@@ -7,19 +7,14 @@
       mc:Ignorable="d"
       Width="Auto" Height="Auto"
       Title="SyslogPage">
-    <Page.CommandBindings>
-        <CommandBinding
-        Command="ApplicationCommands.Copy"
-        Executed="CommandBinding_Executed"/>
-    </Page.CommandBindings>
-    <Grid DataContext="{StaticResource SyslogData}">
+    <Grid DataContext="{StaticResource SyslogPageModel}">
         <TextBlock HorizontalAlignment="Right" Margin="0,0,124,0" Text="Suche:" VerticalAlignment="Top"/>
-        <TextBox x:Name="tbSearch" HorizontalAlignment="Right" VerticalAlignment="Top" Width="120" Text="" TextChanged="TextChanged"/>
+        <TextBox x:Name="tbSearch" HorizontalAlignment="Right" VerticalAlignment="Top" Width="120" Text="{Binding Path=SearchText, UpdateSourceTrigger=PropertyChanged}"/>
 
-        <ListView ItemsSource="{Binding syslogList}" x:Name="listView" Margin="0,23,0,39">
+        <ListView ItemsSource="{Binding filteredList}" SelectedItem="{Binding Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}" x:Name="listView" Margin="0,23,0,39">
             <ListView.ContextMenu>
                 <ContextMenu>
-                    <MenuItem Header="Copy" Command="ApplicationCommands.Copy"/>
+                    <MenuItem Header="Copy" Command="{Binding Path=CopyCommand, NotifyOnTargetUpdated=True}"/>
                 </ContextMenu>
             </ListView.ContextMenu>
             <ListView.Resources>
@@ -36,8 +31,8 @@
         </ListView>
 
         <TextBlock Text="{Binding datetime}" Margin="0,0,10,0" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
-        <Button x:Name="btnClear" Content="Leeren" Click="button_click" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="72"/>
+        <Button Command="{Binding Path=ClearCommand}" x:Name="btnClear" Content="Leeren" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="72"/>
 
-        <Button x:Name="btnReload" Content="Aktualisieren" Margin="218,0,218,0" Click="button_click" VerticalAlignment="Bottom"/>
+        <Button Command="{Binding Path=ReloadCommand}" x:Name="btnReload" Content="Aktualisieren" Margin="218,0,218,0" VerticalAlignment="Bottom"/>
     </Grid>
 </Page>
index 6d17baedfeae59c7094e8ac871f61bffce69fcc6..b01d64e34797b9532a8ad7a0150fae93b1c9c351 100644 (file)
@@ -1,9 +1,4 @@
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System;
-using SpeedportHybridControl.Model;
-using System.Threading.Tasks;
+using System.Windows.Controls;
 
 namespace SpeedportHybridControl.page {
        /// <summary>
@@ -13,55 +8,5 @@ namespace SpeedportHybridControl.page {
                public SyslogPage() {
                        InitializeComponent();
                }
-               
-               public void init () {
-                       tbSearch.Text = string.Empty;
-               }
-
-               private bool SyslogFilter (object item) {
-                       //if (tbSearch.Text.IsNullOrEmpty().Equals(false)) {
-                       //      return ((item as SyslogList).message.IndexOf(tbSearch.Text, StringComparison.OrdinalIgnoreCase) >= 0);
-                       //}
-
-                       return true;
-               }
-               
-               private void button_click(object sender, RoutedEventArgs e) {
-                       /*
-                       if (sender.Equals(btnReload)) {
-                               SpeedportHybrid.initSyslog();
-                               TextChanged(null, null);
-                       }
-                       else if (sender.Equals(btnClear)) {
-                               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();
-                                       util.init("Syslog");
-                                       tbSearch.Text = string.Empty;
-                }
-                       }
-                       */
-               }
-               
-               public void TextChanged (object sender, TextChangedEventArgs e) {
-                       /*
-                       SyslogData syslog = Application.Current.FindResource("SyslogData") as SyslogData;
-                       CollectionView collectionView = CollectionViewSource.GetDefaultView(syslog.syslogList) as CollectionView;
-                       collectionView.Filter = SyslogFilter;
-
-                       CollectionViewSource.GetDefaultView(syslog.syslogList).Refresh();
-                       */                      
-               }
-
-               private void CommandBinding_Executed(object sender, RoutedEventArgs e) {
-                       string text = string.Empty;
-
-                       if (e.Source.Equals(listView)) {
-                               text = listView.SelectedItem.ToString();
-                       }
-
-                       Clipboard.SetText(text);
-                       text = null;
-               }
        }
 }