update Controls page
authorStricted <info@stricted.de>
Wed, 11 Nov 2015 22:57:29 +0000 (23:57 +0100)
committerStricted <info@stricted.de>
Wed, 11 Nov 2015 22:57:29 +0000 (23:57 +0100)
SpeedportHybridControl/App.xaml
SpeedportHybridControl/PageModel/ControlsPageModel.cs [new file with mode: 0644]
SpeedportHybridControl/SpeedportHybridControl.csproj
SpeedportHybridControl/page/ControlsPage.xaml
SpeedportHybridControl/page/ControlsPage.xaml.cs

index 5c0bcffc36d4676a994228b66e1dcef260ae98ac..d510c233b2374eed82d6041bc2e9fdf4cda4fa24 100644 (file)
@@ -18,6 +18,7 @@
             <pagemodel:TR181PageModel x:Key="TR181PageModel"></pagemodel:TR181PageModel>
             <pagemodel:PhonePageModel x:Key="PhonePageModel"></pagemodel:PhonePageModel>
             <pagemodel:LanPageModel x:Key="LanPageModel"></pagemodel:LanPageModel>
+            <pagemodel:ControlsPageModel x:Key="ControlsPageModel"></pagemodel:ControlsPageModel>
         </ResourceDictionary>
     </Application.Resources>
 </Application>
diff --git a/SpeedportHybridControl/PageModel/ControlsPageModel.cs b/SpeedportHybridControl/PageModel/ControlsPageModel.cs
new file mode 100644 (file)
index 0000000..1bb7702
--- /dev/null
@@ -0,0 +1,218 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SpeedportHybridControl.Implementations;
+using SpeedportHybridControl.Model;
+using SpeedportHybridControl.Data;
+using System.Windows;
+using System.Threading;
+using System.Diagnostics;
+
+namespace SpeedportHybridControl.PageModel {
+       class ControlsPageModel : SuperViewModel {
+               private DelegateCommand _rebootCommand;
+               private DelegateCommand _dslReconnectCommand;
+               private DelegateCommand _lteReconnectCommand;
+               private DelegateCommand _dslLteReconnectCommand;
+               private DelegateCommand _checkFirmwareUpdateCommand;
+               private DelegateCommand _clearDNSCacheCommand;
+               private DelegateCommand _speedtestNetCommand;
+               private DelegateCommand _speedtestTKCommand;
+               private DelegateCommand _disconnectDslCommand;
+               private DelegateCommand _connectDslCommand;
+               private DelegateCommand _disconnectLteCommand;
+               private DelegateCommand _connectLteCommand;
+               private DelegateCommand _resetToFactoryCommand;
+
+               public DelegateCommand RebootCommand {
+                       get { return _rebootCommand; }
+                       set { SetProperty(ref _rebootCommand, value); }
+               }
+
+               public DelegateCommand DslReconnectcommand {
+                       get { return _dslReconnectCommand; }
+                       set { SetProperty(ref _dslReconnectCommand, value); }
+               }
+
+               public DelegateCommand LteReconncetCommand {
+                       get { return _lteReconnectCommand; }
+                       set { SetProperty(ref _lteReconnectCommand, value); }
+               }
+
+               public DelegateCommand DslLteReconnectCommand {
+                       get { return _dslLteReconnectCommand; }
+                       set { SetProperty(ref _dslLteReconnectCommand, value); }
+               }
+
+               public DelegateCommand CheckFirmwareUpdateCommand {
+                       get { return _checkFirmwareUpdateCommand; }
+                       set { SetProperty(ref _checkFirmwareUpdateCommand, value); }
+               }
+
+               public DelegateCommand ClearDNSCacheCommand {
+                       get { return _clearDNSCacheCommand; }
+                       set { SetProperty(ref _clearDNSCacheCommand, value); }
+               }
+
+               public DelegateCommand SpeedtestNetCommand {
+                       get { return _speedtestNetCommand; }
+                       set { SetProperty(ref _speedtestNetCommand, value); }
+               }
+
+               public DelegateCommand SpeedtestTKCommand {
+                       get { return _speedtestTKCommand; }
+                       set { SetProperty(ref _speedtestTKCommand, value); }
+               }
+
+               public DelegateCommand DisconnectDslCommand {
+                       get { return _disconnectDslCommand; }
+                       set { SetProperty(ref _disconnectDslCommand, value); }
+               }
+
+               public DelegateCommand ConnectDslCommand {
+                       get { return _connectDslCommand; }
+                       set { SetProperty(ref _connectDslCommand, value); }
+               }
+
+               public DelegateCommand DisconnectLteCommand {
+                       get { return _disconnectLteCommand; }
+                       set { SetProperty(ref _disconnectLteCommand, value); }
+               }
+
+               public DelegateCommand ConnectLteCommand {
+                       get { return _connectLteCommand; }
+                       set { SetProperty(ref _connectLteCommand, value); }
+               }
+
+               public DelegateCommand ResetToFactoryCommand {
+                       get { return _resetToFactoryCommand; }
+                       set { SetProperty(ref _resetToFactoryCommand, value); }
+               }
+
+               private void OnRebootCommandExecute () {
+                       MessageBoxResult result = MessageBox.Show("Willst du den Router wirklich neustarten?", "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
+                       if (result.Equals(MessageBoxResult.Yes)) {
+                               SpeedportHybridAPI.getInstance().reboot();
+                       }
+               }
+
+               private void OnDslReconnectcommandExecute () {
+                       new Thread(() => {
+                               bool reconnectDSL = SpeedportHybridAPI.getInstance().reconnectDSL();
+                               if (reconnectDSL.Equals(false)) {
+                                       new Thread(() => { MessageBox.Show("Could not reconnect DSL.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
+                                       LogManager.WriteToLog("Could not reconnect DSL.");
+                               }
+                               else {
+                                       new Thread(() => { MessageBox.Show("DSL reconnected", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
+                               }
+                       }).Start();
+               }
+
+               private void OnLteReconncetCommandExecute () {
+                       new Thread(() => {
+                               bool reconnectLte = SpeedportHybridAPI.getInstance().reconnectLte();
+                               if (reconnectLte.Equals(false)) {
+                                       new Thread(() => { MessageBox.Show("Could not reconnect LTE.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
+                                       LogManager.WriteToLog("Could not reconnect LTE.");
+                               }
+                               else {
+                                       new Thread(() => { MessageBox.Show("LTE reconnected", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
+                               }
+                       }).Start();
+               }
+
+               private void OnDslLteReconnectCommandExecute () {
+                       //TODO
+               }
+
+               private void OnCheckFirmwareUpdateCommandExecute () {
+                       SpeedportHybridAPI.getInstance().checkFirmware();
+               }
+
+               private void OnClearDNSCacheCommandExecute () {
+                       new Thread(() => { SpeedportHybridAPI.getInstance().flushDNS(); }).Start();
+               }
+
+               private void OnSpeedtestNetCommandExecute () {
+                       Process.Start("http://www.speedtest.net/");
+               }
+
+               private void OnSpeedtestTKCommandExecute () {
+                       Process.Start("http://speedtest.t-online.de/");
+               }
+
+               private void OnDisconnectDslCommandExecute () {
+                       bool status = SpeedportHybridAPI.getInstance().changeDSLStatus("offline");
+                       if (status.Equals(false)) {
+                               new Thread(() => { MessageBox.Show("DSL Trennen Fehlgeschlagen", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
+                               LogManager.WriteToLog("Could not disconnect DSL.");
+                       }
+                       else {
+                               new Thread(() => { MessageBox.Show("DSL Trennen erfolgreich.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
+                       }
+               }
+
+               private void OnConnectDslCommandExecute () {
+                       bool status = SpeedportHybridAPI.getInstance().changeDSLStatus("online");
+                       if (status.Equals(false)) {
+                               new Thread(() => { MessageBox.Show("DSL Verbinden Fehlgeschlagen", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
+                               LogManager.WriteToLog("Could not connect DSL.");
+                       }
+                       else {
+                               new Thread(() => { MessageBox.Show("DSL Verbinden erfolgreich.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
+                       }
+               }
+
+               private void OnDisconnectLteCommandExecute () {
+                       bool status = SpeedportHybridAPI.getInstance().changeLTEStatus("offline");
+                       if (status.Equals(false)) {
+                               new Thread(() => { MessageBox.Show("LTE Trennen Fehlgeschlagen", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
+                               LogManager.WriteToLog("Could not disconnect LTE.");
+                       }
+                       else {
+                               new Thread(() => { MessageBox.Show("LTE Trennen erfolgreich.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
+                       }
+               }
+
+               private void OnConnectLteCommandExecute () {
+                       bool status = SpeedportHybridAPI.getInstance().changeLTEStatus("online");
+                       if (status.Equals(false)) {
+                               new Thread(() => { MessageBox.Show("LTE Verbinden Fehlgeschlagen", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
+                               LogManager.WriteToLog("Could not connect LTE.");
+                       }
+                       else {
+                               new Thread(() => { MessageBox.Show("LTE Verbinden erfolgreich.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
+                       }
+               }
+
+               private void OnResetToFactoryCommandExecute () {
+                       MessageBoxResult result = MessageBox.Show("Beim Zurücksetzen auf die Werkseinstellungen gehen alle Ihre Einstellungen verloren.\nSind Sie sicher, dass Sie den Router zurücksetzen möchten ? ", "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
+                       if (result.Equals(MessageBoxResult.Yes)) {
+                               bool reconnectDSL = SpeedportHybridAPI.getInstance().resetToFactoryDefault();
+                               if (reconnectDSL.Equals(false)) {
+                                       new Thread(() => { MessageBox.Show("Could not reset the router.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
+                                       LogManager.WriteToLog("Could not reset the router.");
+                               }
+                       }
+               }
+
+               public ControlsPageModel () {
+                       RebootCommand = new DelegateCommand(new Action(OnRebootCommandExecute));
+                       DslReconnectcommand = new DelegateCommand(new Action(OnDslReconnectcommandExecute));
+                       LteReconncetCommand = new DelegateCommand(new Action(OnLteReconncetCommandExecute));
+                       DslLteReconnectCommand = new DelegateCommand(new Action(OnDslLteReconnectCommandExecute));
+                       CheckFirmwareUpdateCommand = new DelegateCommand(new Action(OnCheckFirmwareUpdateCommandExecute));
+                       ClearDNSCacheCommand = new DelegateCommand(new Action(OnClearDNSCacheCommandExecute));
+                       SpeedtestNetCommand = new DelegateCommand(new Action(OnSpeedtestNetCommandExecute));
+                       SpeedtestTKCommand = new DelegateCommand(new Action(OnSpeedtestTKCommandExecute));
+                       DisconnectDslCommand = new DelegateCommand(new Action(OnDisconnectDslCommandExecute));
+                       ConnectDslCommand = new DelegateCommand(new Action(OnConnectDslCommandExecute));
+                       DisconnectLteCommand = new DelegateCommand(new Action(OnDisconnectLteCommandExecute));
+                       ConnectLteCommand = new DelegateCommand(new Action(OnConnectLteCommandExecute));
+                       ResetToFactoryCommand = new DelegateCommand(new Action(OnResetToFactoryCommandExecute));
+               }
+       }
+}
index 488db6e0a72eaa20f4910c0aa7b3a31ab14a3114..c1957de423de6ea0f58a05d0e351a4e6039c47be 100644 (file)
@@ -77,6 +77,7 @@
     <Compile Include="Model\PhoneCallList.cs" />
     <Compile Include="Model\StatusPhoneList.cs" />
     <Compile Include="Model\SyslogList.cs" />
+    <Compile Include="PageModel\ControlsPageModel.cs" />
     <Compile Include="PageModel\DslPageModel.cs" />
     <Compile Include="PageModel\LanPageModel.cs" />
     <Compile Include="PageModel\LoginPageModel.cs" />
index f80ecf28d56e583e10828206f378015860be799f..9aa326c4960d685fc63a15f56d9ae34b1ba4b1e8 100644 (file)
@@ -8,7 +8,7 @@
       Width="Auto" Height="Auto"
       Title="ControlsPage">
 
-    <Grid>
+    <Grid DataContext="{StaticResource ControlsPageModel}">
         <StackPanel HorizontalAlignment="Left" Width="117" Height="282" VerticalAlignment="Top" Margin="10,0,0,0">
             <StackPanel.Resources>
                 <Style TargetType="{x:Type Button}">
                 </Style>
             </StackPanel.Resources>
 
-            <Button x:Name="button7" Content="Router Neustarten" Click="button_click"/>
-            <Button x:Name="button9" Content="DSL neu verbinden" Click="button_click"/>
-            <Button x:Name="button10" Content="Firmware-Update" Click="button_click"/>
-            <Button x:Name="btnflushdns" Content="DNS Cache Leeren" Click="button_click"/>
-            <Button x:Name="btnSpeedtest" Content="speedtest.net" Click="button_click"/>
+            <Button Command="{Binding Path=RebootCommand}" Content="Router Neustarten"/>
+            <Button Command="{Binding Path=DslReconnectcommand}" Content="DSL neu verbinden"/>
+            <Button Command="{Binding Path=CheckFirmwareUpdateCommand}" Content="Firmware-Update"/>
+            <Button Command="{Binding Path=ClearDNSCacheCommand}" Content="DNS Cache Leeren"/>
+            <Button Command="{Binding Path=SpeedtestNetCommand}" Content="speedtest.net"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
-            <Button x:Name="button17" Content="Werkseinstellungen" Click="button_click" />
+            <Button Command="{Binding Path=ResetToFactoryCommand}" Content="Werkseinstellungen" />
         </StackPanel>
 
         <StackPanel HorizontalAlignment="Left" Width="117" Height="282" VerticalAlignment="Top" Margin="132,0,0,0">
             </StackPanel.Resources>
 
             <Button Visibility="Hidden" Content="[SPACER]"/>
-            <Button x:Name="button8" Content="LTE neu verbinden" Click="button_click" />
+            <Button Command="{Binding Path=LteReconncetCommand}" Content="LTE neu verbinden" />
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
-            <Button x:Name="btnSpeedtest2" Content="speedtest.t-online.de" Click="button_click"/>
+            <Button Command="{Binding Path=SpeedtestTKCommand}" Content="speedtest.t-online.de"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
-            <Button x:Name="btnDSLdisconnect" Content="DSL Trennen" Click="button_click"/>
-            <Button x:Name="btnLTEdisconnect" Content="LTE Trennen" Click="button_click"/>
+            <Button Command="{Binding Path=DisconnectDslCommand}" Content="DSL Trennen"/>
+            <Button Command="{Binding Path=DisconnectLteCommand}" Content="LTE Trennen"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             </StackPanel.Resources>
 
             <Button Visibility="Hidden" Content="[SPACER]"/>
-            <Button IsEnabled="False" x:Name="button" Content="DSL + LTE neu verbinden"/>
+            <Button IsEnabled="False" Command="{Binding Path=DslLteReconnectCommand}" Content="DSL + LTE neu verbinden"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
-            <Button x:Name="btnDSLconnect" Content="DSL Verbinden" Click="button_click"/>
-            <Button x:Name="btnLTEconnect" Content="LTE Verbinden" Click="button_click"/>
+            <Button Command="{Binding Path=ConnectDslCommand}" Content="DSL Verbinden"/>
+            <Button Command="{Binding Path=ConnectLteCommand}" Content="LTE Verbinden"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
             <Button Visibility="Hidden" Content="[SPACER]"/>
index c170e16fd0053ebcee573f7dac717e46f02a3269..47eb856bb871e089077051827cf1b9ee5919e5dd 100644 (file)
@@ -1,7 +1,4 @@
-using System.Windows;
-using System.Windows.Controls;
-using System.Threading;
-using System.Diagnostics;
+using System.Windows.Controls;
 
 namespace SpeedportHybridControl.page {
        /// <summary>
@@ -11,102 +8,5 @@ namespace SpeedportHybridControl.page {
                public ControlsPage() {
                        InitializeComponent();
                }
-
-               private void button_click (object sender, RoutedEventArgs e) {
-                       /*
-                       if (sender.Equals(button7)) {
-                               MessageBoxResult result = MessageBox.Show("Willst du den Router wirklich neustarten?", "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
-                               if (result.Equals(MessageBoxResult.Yes)) {
-                                       SpeedportHybridAPI.getInstance().reboot();
-                               }
-                       }
-                       else if (sender.Equals(button8)) {
-                               new Thread(() => {
-                                       bool reconnectLte = SpeedportHybridAPI.getInstance().reconnectLte();
-                                       if (reconnectLte.Equals(false)) {
-                                               new Thread(() => { MessageBox.Show("Could not reconnect LTE.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
-                                               LogManager.WriteToLog("Could not reconnect LTE.");
-                                       }
-                                       else {
-                                               new Thread(() => { MessageBox.Show("LTE reconnected", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
-                                       }
-                               }).Start();
-                       }
-                       else if (sender.Equals(button9)) {
-                               new Thread(() => {
-                                       bool reconnectDSL = SpeedportHybridAPI.getInstance().reconnectDSL();
-                                       if (reconnectDSL.Equals(false)) {
-                                               new Thread(() => { MessageBox.Show("Could not reconnect DSL.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
-                                               LogManager.WriteToLog("Could not reconnect DSL.");
-                                       }
-                                       else {
-                                               new Thread(() => { MessageBox.Show("DSL reconnected", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
-                                       }
-                               }).Start();
-                       }
-                       else if (sender.Equals(button10)) {
-                               SpeedportHybridAPI.getInstance().checkFirmware();
-                       }
-                       else if (sender.Equals(button17)) {
-                               MessageBoxResult result = MessageBox.Show("Beim Zurücksetzen auf die Werkseinstellungen gehen alle Ihre Einstellungen verloren.\nSind Sie sicher, dass Sie den Router zurücksetzen möchten ? ", "Confirmation", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
-                               if (result.Equals(MessageBoxResult.Yes)) {
-                                       bool reconnectDSL = SpeedportHybridAPI.getInstance().resetToFactoryDefault();
-                                       if (reconnectDSL.Equals(false)) {
-                                               new Thread(() => { MessageBox.Show("Could not reset the router.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
-                                               LogManager.WriteToLog("Could not reset the router.");
-                                       }
-                               }
-                       }
-                       else if (sender.Equals(btnflushdns)) {
-                               new Thread(() => { SpeedportHybridAPI.getInstance().flushDNS(); }).Start();
-                       }
-                       else if (sender.Equals(btnSpeedtest)) {
-                               Process.Start("http://www.speedtest.net/");
-                       }
-                       else if (sender.Equals(btnSpeedtest2)) {
-                               Process.Start("http://speedtest.t-online.de/");
-                       }
-                       else if (sender.Equals(btnDSLconnect)) {
-                               bool status = SpeedportHybridAPI.getInstance().changeDSLStatus("online");
-                               if (status.Equals(false)) {
-                                       new Thread(() => { MessageBox.Show("DSL Verbinden Fehlgeschlagen", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
-                                       LogManager.WriteToLog("Could not connect DSL.");
-                               }
-                               else {
-                                       new Thread(() => { MessageBox.Show("DSL Verbinden erfolgreich.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
-                               }
-                       }
-                       else if (sender.Equals(btnDSLdisconnect)) {
-                               bool status = SpeedportHybridAPI.getInstance().changeDSLStatus("offline");
-                               if (status.Equals(false)) {
-                                       new Thread(() => { MessageBox.Show("DSL Trennen Fehlgeschlagen", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
-                                       LogManager.WriteToLog("Could not disconnect DSL.");
-                               }
-                               else {
-                                       new Thread(() => { MessageBox.Show("DSL Trennen erfolgreich.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
-                               }
-                       }
-                       else if (sender.Equals(btnLTEconnect)) {
-                               bool status = SpeedportHybridAPI.getInstance().changeLTEStatus("online");
-                               if (status.Equals(false)) {
-                                       new Thread(() => { MessageBox.Show("LTE Verbinden Fehlgeschlagen", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
-                                       LogManager.WriteToLog("Could not connect LTE.");
-                               }
-                               else {
-                                       new Thread(() => { MessageBox.Show("LTE Verbinden erfolgreich.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
-                               }
-                       }
-                       else if (sender.Equals(btnLTEdisconnect)) {
-                               bool status = SpeedportHybridAPI.getInstance().changeLTEStatus("offline");
-                               if (status.Equals(false)) {
-                                       new Thread(() => { MessageBox.Show("LTE Trennen Fehlgeschlagen", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
-                                       LogManager.WriteToLog("Could not disconnect LTE.");
-                               }
-                               else {
-                                       new Thread(() => { MessageBox.Show("LTE Trennen erfolgreich.", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); }).Start();
-                               }
-                       }
-                       */
-               }
        }
 }