From 6c89a163851a4819ab421c9a167e41a757b77883 Mon Sep 17 00:00:00 2001 From: Stricted Date: Wed, 11 Nov 2015 16:20:48 +0100 Subject: [PATCH] update Overview and DSL page --- SpeedportHybridControl/App.xaml | 4 +- .../Data/SpeedportHybrid.cs | 6 +- SpeedportHybridControl/Model/Connection.cs | 40 +++++ .../Model/{DSLViewModel.cs => Line.cs} | 79 --------- .../PageModel/DslPageModel.cs | 154 ++++++++++++++++++ .../PageModel/MainWindowModel.cs | 8 +- .../OverviewPageModel.cs} | 27 ++- .../SpeedportHybridControl.csproj | 6 +- SpeedportHybridControl/page/DslPage.xaml | 12 +- SpeedportHybridControl/page/OverviewPage.xaml | 10 +- .../page/OverviewPage.xaml.cs | 12 +- 11 files changed, 242 insertions(+), 116 deletions(-) create mode 100644 SpeedportHybridControl/Model/Connection.cs rename SpeedportHybridControl/Model/{DSLViewModel.cs => Line.cs} (69%) create mode 100644 SpeedportHybridControl/PageModel/DslPageModel.cs rename SpeedportHybridControl/{Model/OverviewModel.cs => PageModel/OverviewPageModel.cs} (78%) diff --git a/SpeedportHybridControl/App.xaml b/SpeedportHybridControl/App.xaml index dbc3ae3..38ec605 100644 --- a/SpeedportHybridControl/App.xaml +++ b/SpeedportHybridControl/App.xaml @@ -10,15 +10,15 @@ + + - - diff --git a/SpeedportHybridControl/Data/SpeedportHybrid.cs b/SpeedportHybridControl/Data/SpeedportHybrid.cs index 0b964cf..079ec18 100644 --- a/SpeedportHybridControl/Data/SpeedportHybrid.cs +++ b/SpeedportHybridControl/Data/SpeedportHybrid.cs @@ -17,7 +17,7 @@ namespace SpeedportHybridControl.Data { if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) return; - OverviewModel overview = Application.Current.FindResource("OverviewModel") as OverviewModel; + OverviewPageModel overview = Application.Current.FindResource("OverviewPageModel") as OverviewPageModel; string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/Overview.json"); if (response.IsNullOrEmpty()) @@ -365,14 +365,14 @@ namespace SpeedportHybridControl.Data { if (SpeedportHybridAPI.getInstance().checkLogin().Equals(false)) return; - DSLViewModel dsl = Application.Current.FindResource("DSL") as DSLViewModel; + DslPageModel dsl = Application.Current.FindResource("DslPageModel") as DslPageModel; string response = SpeedportHybridAPI.getInstance().sendEnryptedRequest("data/dsl.json"); if (response.IsNullOrEmpty()) return; try { - DSLViewModel obj = JsonConvert.DeserializeObject(response); + DslPageModel obj = JsonConvert.DeserializeObject(response); double difference = Math.Ceiling((DateTime.Now - SpeedportHybridAPI.getInstance().getLastReboot()).TotalSeconds) / 60; diff --git a/SpeedportHybridControl/Model/Connection.cs b/SpeedportHybridControl/Model/Connection.cs new file mode 100644 index 0000000..1c2af63 --- /dev/null +++ b/SpeedportHybridControl/Model/Connection.cs @@ -0,0 +1,40 @@ +namespace SpeedportHybridControl.Model { + class Connection : SuperViewModel { + private string _dsl_operaing_mode; + private string _path_mode; + private string _state; + private string _training_results; + private string _mode_lo; + private string _vpi_vpc; + + public string dsl_operaing_mode { + get { return _dsl_operaing_mode; } + set { SetProperty(ref _dsl_operaing_mode, value); } + } + + public string path_mode { + get { return _path_mode; } + set { SetProperty(ref _path_mode, value); } + } + + public string state { + get { return _state; } + set { SetProperty(ref _state, value); } + } + + public string training_results { + get { return _training_results; } + set { SetProperty(ref _training_results, value); } + } + + public string mode_lo { + get { return _mode_lo; } + set { SetProperty(ref _mode_lo, value); } + } + + public string vpi_vci { + get { return _vpi_vpc; } + set { SetProperty(ref _vpi_vpc, value); } + } + } +} diff --git a/SpeedportHybridControl/Model/DSLViewModel.cs b/SpeedportHybridControl/Model/Line.cs similarity index 69% rename from SpeedportHybridControl/Model/DSLViewModel.cs rename to SpeedportHybridControl/Model/Line.cs index b378954..26e0393 100644 --- a/SpeedportHybridControl/Model/DSLViewModel.cs +++ b/SpeedportHybridControl/Model/Line.cs @@ -1,83 +1,4 @@ namespace SpeedportHybridControl.Model { - class DSLViewModel : SuperViewModel { - private Connection _Connection; - private Line _Line; - private string _datetime; - - private string _lastCRC; - private string _lastHEC; - private string _lastFEC; - - public Connection Connection { - get { return _Connection; } - set { SetProperty(ref _Connection, value); } - } - - public Line Line { - get { return _Line; } - set { SetProperty(ref _Line, value); } - } - - public string datetime { - get { return _datetime; } - set { SetProperty(ref _datetime, value); } - } - - public string lastCRC { - get { return _lastCRC; } - set { SetProperty(ref _lastCRC, value); } - } - - public string lastFEC { - get { return _lastFEC; } - set { SetProperty(ref _lastFEC, value); } - } - - public string lastHEC { - get { return _lastHEC; } - set { SetProperty(ref _lastHEC, value); } - } -} - - class Connection : SuperViewModel { - private string _dsl_operaing_mode; - private string _path_mode; - private string _state; - private string _training_results; - private string _mode_lo; - private string _vpi_vpc; - - public string dsl_operaing_mode { - get { return _dsl_operaing_mode; } - set { SetProperty(ref _dsl_operaing_mode, value); } - } - - public string path_mode { - get { return _path_mode; } - set { SetProperty(ref _path_mode, value); } - } - - public string state { - get { return _state; } - set { SetProperty(ref _state, value); } - } - - public string training_results { - get { return _training_results; } - set { SetProperty(ref _training_results, value); } - } - - public string mode_lo { - get { return _mode_lo; } - set { SetProperty(ref _mode_lo, value); } - } - - public string vpi_vci { - get { return _vpi_vpc; } - set { SetProperty(ref _vpi_vpc, value); } - } - } - class Line : SuperViewModel { private string _uactual; private string _dactual; diff --git a/SpeedportHybridControl/PageModel/DslPageModel.cs b/SpeedportHybridControl/PageModel/DslPageModel.cs new file mode 100644 index 0000000..edac250 --- /dev/null +++ b/SpeedportHybridControl/PageModel/DslPageModel.cs @@ -0,0 +1,154 @@ +using SpeedportHybridControl.Data; +using SpeedportHybridControl.Implementations; +using SpeedportHybridControl.Model; +using System; +using System.IO; +using System.Threading; +using System.Timers; +using System.Windows; + +namespace SpeedportHybridControl.PageModel { + class DslPageModel : SuperViewModel { + private DelegateCommand _reloadCommand; + private DelegateCommand _autoReloadCommand; + private bool _autoReload; + private bool _log; + private bool _logEnabled; + private System.Timers.Timer _timer; + + private Connection _Connection; + private Line _Line; + private string _datetime; + + private string _lastCRC; + private string _lastHEC; + private string _lastFEC; + + + public Connection Connection { + get { return _Connection; } + set { SetProperty(ref _Connection, value); } + } + + public Line Line { + get { return _Line; } + set { SetProperty(ref _Line, value); } + } + + public string datetime { + get { return _datetime; } + set { SetProperty(ref _datetime, value); } + } + + public string lastCRC { + get { return _lastCRC; } + set { SetProperty(ref _lastCRC, value); } + } + + public string lastFEC { + get { return _lastFEC; } + set { SetProperty(ref _lastFEC, value); } + } + + public string lastHEC { + get { return _lastHEC; } + set { SetProperty(ref _lastHEC, value); } + } + + + public DelegateCommand ReloadCommand { + get { return _reloadCommand; } + set { SetProperty(ref _reloadCommand, value); } + } + + public DelegateCommand AutoReloadCommand { + get { return _autoReloadCommand; } + set { SetProperty(ref _autoReloadCommand, value); } + } + public bool AutoReload { + get { return _autoReload; } + set { SetProperty(ref _autoReload, value); } + } + + public bool Log { + get { return _log; } + set { SetProperty(ref _log, value); } + } + + public bool LogEnabled { + get { return _logEnabled; } + set { SetProperty(ref _logEnabled, value); } + } + + private void OnReloadCommandExecute () { + new Thread(() => { SpeedportHybrid.initDSL(); }).Start(); + } + + private void OnAutoReloadCommandExecute () { + if (AutoReload.Equals(true)) { + StartTimer(); + LogEnabled = true; + } + else { + StopTimer(); + } + } + + public void StopTimer () { + if (Object.Equals(_timer, null).Equals(false)) { + _timer.Stop(); + } + + if (AutoReload.Equals(true)) { + AutoReload = false; + } + + if (Log.Equals(true)) { + Log = false; + } + + LogEnabled = false; + } + + private void StartTimer () { + _timer = new System.Timers.Timer { + Interval = 1000, // every second + }; + + _timer.Elapsed += timer_Elapsed; + _timer.Start(); + } + + private void timer_Elapsed (object sender, ElapsedEventArgs e) { + SpeedportHybrid.initDSL(); + + Application.Current.Dispatcher.BeginInvoke(new Action(() => { + if (Log.Equals(true)) { + //log + string prepare = "State: {0}, Actual Data Rate: up: {1} down: {2}, Attainable Data Rate: up: {3} down: {4}, SNR Margin up: {5} down: {6}, CRC error count: up: {7} down: {8}, HEC error count: up: {9} down: {10}, FEC error count: up: {11} down: {12}"; + log(string.Format(prepare, Connection.state, Line.uactual, Line.dactual, Line.uattainable, Line.dattainable, Line.uSNR, Line.dSNR, Line.uCRC, Line.dCRC, Line.uHEC, Line.dHEC, Line.uFEC, Line.dFEC)); + log(string.Format("CRC/min up: {0} down: {1}, HEC/min up: {2} down: {3}, FEC/min up: {4} down: {5}", Line.uCRCsec, Line.dCRCsec, Line.uHECsec, Line.dHECsec, Line.uFECsec, Line.dFECsec)); + } + })); + } + + private void log (string value) { + DateTime time = DateTime.Now; + + if (Directory.Exists("log/").Equals(false)) + Directory.CreateDirectory("log/"); + + if (Directory.Exists("log/dsl/").Equals(false)) + Directory.CreateDirectory("log/dsl/"); + + StreamWriter file = new StreamWriter(string.Concat("log/dsl/", time.ToString("dd.MM.yyyy"), ".txt"), true); + file.WriteLine(string.Concat("[", time.ToString("dd.MM.yyyy HH:mm:ss"), "]: ", value)); + file.Close(); + } + + public DslPageModel () { + ReloadCommand = new DelegateCommand(new Action(OnReloadCommandExecute)); + AutoReloadCommand = new DelegateCommand(new Action(OnAutoReloadCommandExecute)); + } + } +} diff --git a/SpeedportHybridControl/PageModel/MainWindowModel.cs b/SpeedportHybridControl/PageModel/MainWindowModel.cs index 9b35b5f..7b02efd 100644 --- a/SpeedportHybridControl/PageModel/MainWindowModel.cs +++ b/SpeedportHybridControl/PageModel/MainWindowModel.cs @@ -263,12 +263,14 @@ namespace SpeedportHybridControl.PageModel { private void changePage (string page) { if (object.Equals(FrameSource, null).Equals(false)) { - if (FrameSource.Content.GetType().Equals(typeof(LteInfoPage))) { + Console.WriteLine("HERE!!!"); + if (FrameSource.GetType().Equals(typeof(LteInfoPage))) { // TODO: lteInfoPage.StopTimer(); } - if (FrameSource.Content.GetType().Equals(typeof(DslPage))) { - // TODO: dslPage.StopTimer(); + if (FrameSource.GetType().Equals(typeof(DslPage))) { + DslPageModel dsl = Application.Current.FindResource("DslPageModel") as DslPageModel; + dsl.StopTimer(); } } diff --git a/SpeedportHybridControl/Model/OverviewModel.cs b/SpeedportHybridControl/PageModel/OverviewPageModel.cs similarity index 78% rename from SpeedportHybridControl/Model/OverviewModel.cs rename to SpeedportHybridControl/PageModel/OverviewPageModel.cs index d5a9c85..10f2984 100644 --- a/SpeedportHybridControl/Model/OverviewModel.cs +++ b/SpeedportHybridControl/PageModel/OverviewPageModel.cs @@ -1,5 +1,13 @@ -namespace SpeedportHybridControl.Model { - public class OverviewModel : SuperViewModel { +using SpeedportHybridControl.Data; +using SpeedportHybridControl.Implementations; +using SpeedportHybridControl.Model; +using System; +using System.Threading; + +namespace SpeedportHybridControl.PageModel { + class OverviewPageModel : SuperViewModel { + private DelegateCommand _reloadCommand; + private string _onlinestatus; private string _dsl_link_status; private string _lte_image = "../assets/lte0.png"; @@ -11,13 +19,22 @@ private string _use_wlan_5ghz; private string _wlan_enc; private string _wlan_power; - private string _external_devices; + private string _external_devices; private string _nas_sync_active; private string _nas_backup_active; private string _mc_state; private string _days_online; private string _datetime; + public DelegateCommand ReloadCommand { + get { return _reloadCommand; } + set { SetProperty(ref _reloadCommand, value); } + } + + private void OnReloadCommandExecute () { + new Thread(() => { SpeedportHybrid.initOverview(); }).Start(); + } + public string onlinestatus { get { return _onlinestatus; } set { SetProperty(ref _onlinestatus, value); } @@ -103,8 +120,8 @@ set { SetProperty(ref _datetime, value); } } - public OverviewModel () { - + public OverviewPageModel () { + ReloadCommand = new DelegateCommand(new Action(OnReloadCommandExecute)); } } } diff --git a/SpeedportHybridControl/SpeedportHybridControl.csproj b/SpeedportHybridControl/SpeedportHybridControl.csproj index f01cea1..0f77678 100644 --- a/SpeedportHybridControl/SpeedportHybridControl.csproj +++ b/SpeedportHybridControl/SpeedportHybridControl.csproj @@ -64,13 +64,14 @@ + - + + - @@ -134,6 +135,7 @@ + AboutPage.xaml diff --git a/SpeedportHybridControl/page/DslPage.xaml b/SpeedportHybridControl/page/DslPage.xaml index 5f5dcc3..460c09a 100644 --- a/SpeedportHybridControl/page/DslPage.xaml +++ b/SpeedportHybridControl/page/DslPage.xaml @@ -1,15 +1,15 @@  - + @@ -110,10 +110,10 @@ - - + + -