diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels')
7 files changed, 423 insertions, 31 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/CatalogViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/CatalogViewVM.cs index 97bae6f5b..dbc99fa87 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/CatalogViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/CatalogViewVM.cs @@ -4,6 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; +//using Tango.PPC.Browser; +//using Tango.PPC.Browser.Navigation; +//using Tango.PPC.Browser.Views; using Tango.PPC.Common; namespace Tango.PPC.Technician.ViewModels @@ -16,16 +19,22 @@ namespace Tango.PPC.Technician.ViewModels public RelayCommand<String> NavigationCommand { get; set; } /// <summary> + /// Gets or sets the browser command. + /// </summary> + public RelayCommand BrowserCommand { get; set; } + + /// <summary> /// Initializes a new instance of the <see cref="CatalogViewVM"/> class. /// </summary> public CatalogViewVM() { NavigationCommand = new RelayCommand<string>(NavigateToView); + BrowserCommand = new RelayCommand(OpenBrowserModule); } public override void OnApplicationStarted() { - + } /// <summary> @@ -36,5 +45,17 @@ namespace Tango.PPC.Technician.ViewModels { NavigationManager.NavigateTo<TechnicianModule>(view); } + + /// <summary> + /// Opens the browser module. + /// </summary> + private void OpenBrowserModule() + { + //NavigationManager.NavigateWithObject<BrowserModule, BrowserView, BrowserNavigationRequest>(new BrowserNavigationRequest() + //{ + // Address = "https://twine-s.com/", + // DisplayAddressBar = true, + //}, true); + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/LoggingViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/LoggingViewVM.cs index 6ca693af6..2aee7f561 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/LoggingViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/LoggingViewVM.cs @@ -8,8 +8,11 @@ using System.Threading.Tasks; using System.Windows.Data; using Tango.Core; using Tango.Core.Commands; +using Tango.Integration.Logging; +using Tango.Integration.Operation; using Tango.Logging; using Tango.PPC.Common; +using Tango.PPC.Common.Helpers; using Tango.PPC.Technician.Dialogs; namespace Tango.PPC.Technician.ViewModels @@ -17,19 +20,14 @@ namespace Tango.PPC.Technician.ViewModels public class LoggingViewVM : PPCViewModel { private const int MAX_LOGS = 1000; + private List<LogItemBase> paused_logs; + private List<LogItemBase> paused_embedded_logs; public SynchronizedObservableCollection<LogItemBase> ApplicationLogs { get; set; } public SynchronizedObservableCollection<LogItemBase> EmbeddedLogs { get; set; } - private LogItemBase _selectedLog; - public LogItemBase SelectedLog - { - get { return _selectedLog; } - set { _selectedLog = value; RaisePropertyChangedAuto(); OnSelectedLogChanged(); } - } - private ICollectionView _applicationLogsViewSource; public ICollectionView ApplicationLogsViewSource { @@ -37,6 +35,20 @@ namespace Tango.PPC.Technician.ViewModels set { _applicationLogsViewSource = value; RaisePropertyChangedAuto(); } } + private ICollectionView _embeddedLogsViewSource; + public ICollectionView EmbeddedLogsViewSource + { + get { return _embeddedLogsViewSource; } + set { _embeddedLogsViewSource = value; RaisePropertyChangedAuto(); } + } + + private LogItemBase _selectedLog; + public LogItemBase SelectedLog + { + get { return _selectedLog; } + set { _selectedLog = value; RaisePropertyChangedAuto(); OnSelectedLogChanged(); } + } + private String _filter; public String Filter { @@ -46,6 +58,7 @@ namespace Tango.PPC.Technician.ViewModels _filter = value; RaisePropertyChangedAuto(); ApplicationLogsViewSource.Refresh(); + EmbeddedLogsViewSource.Refresh(); } } @@ -56,6 +69,13 @@ namespace Tango.PPC.Technician.ViewModels set { _isPaused = value; RaisePropertyChangedAuto(); OnIsPausedChanged(); } } + private bool _processDebugLogs; + public bool ProcessDebugLogs + { + get { return _processDebugLogs; } + set { _processDebugLogs = value; RaisePropertyChangedAuto(); OnProcessDebugLogsChanged(); } + } + public RelayCommand ClearCommand { get; set; } public LoggingViewVM() @@ -63,8 +83,19 @@ namespace Tango.PPC.Technician.ViewModels ApplicationLogs = new SynchronizedObservableCollection<LogItemBase>(); EmbeddedLogs = new SynchronizedObservableCollection<LogItemBase>(); ApplicationLogsViewSource = CollectionViewSource.GetDefaultView(ApplicationLogs); + EmbeddedLogsViewSource = CollectionViewSource.GetDefaultView(EmbeddedLogs); paused_logs = new List<LogItemBase>(); + paused_embedded_logs = new List<LogItemBase>(); + + var appStartLogs = LogsHelper.GetLogSafe().EmptyAndDispose(); + + foreach (var log in appStartLogs) + { + ApplicationLogs.Insert(0, log); + } + LogManager.NewLog += LogManager_NewLog; + MachineOperator.EmbeddedLogManager.NewLog += EmbeddedLogManager_NewLog; ClearCommand = new RelayCommand(ClearLogs); Filter = "error"; @@ -81,6 +112,31 @@ namespace Tango.PPC.Technician.ViewModels return false; } }; + + EmbeddedLogsViewSource.Filter = (x) => + { + try + { + LogItemBase log = x as LogItemBase; + return String.IsNullOrWhiteSpace(Filter) || log.Category.ToString().ToLower().Contains(Filter.ToLower()) || log.Message.ToLower().Contains(Filter.ToLower()); + } + catch + { + return false; + } + }; + } + + private void OnProcessDebugLogsChanged() + { + if (ProcessDebugLogs) + { + LogManager.Categories.Add(LogCategory.Debug); + } + else + { + LogManager.Categories.RemoveAll(x => x == LogCategory.Debug); + } } private void OnIsPausedChanged() @@ -91,6 +147,14 @@ namespace Tango.PPC.Technician.ViewModels } paused_logs.Clear(); + + + foreach (var log in paused_embedded_logs) + { + EmbeddedLogManager_NewLog(this, log); + } + + paused_embedded_logs.Clear(); } private void LogManager_NewLog(object sender, LogItemBase log) @@ -120,22 +184,59 @@ namespace Tango.PPC.Technician.ViewModels } } + private void EmbeddedLogManager_NewLog(object sender, LogItemBase log) + { + if (!IsPaused) + { + InvokeUI(() => + { + EmbeddedLogs.Insert(0, log); + + try + { + if (EmbeddedLogs.Count > MAX_LOGS) + { + EmbeddedLogs.Remove(EmbeddedLogs.Last()); + } + } + catch + { + //I don't know if this will cause an exception but I'm tired. + } + }); + } + else + { + paused_embedded_logs.Add(log); + } + } + private void ClearLogs() { ApplicationLogs.Clear(); + EmbeddedLogs.Clear(); paused_logs.Clear(); + paused_embedded_logs.Clear(); } private async void OnSelectedLogChanged() { if (SelectedLog != null) { - await NotificationProvider.ShowDialog<LogItemDetailsViewVM>(new LogItemDetailsViewVM() + if (SelectedLog.GetType() == typeof(EmbeddedLogItem)) { - Log = SelectedLog, - }); - - SelectedLog = null; + await NotificationProvider.ShowDialog<EmbeddedLogItemDetailsViewVM>(new EmbeddedLogItemDetailsViewVM() + { + Log = SelectedLog as EmbeddedLogItem, + }); + } + else + { + await NotificationProvider.ShowDialog<LogItemDetailsViewVM>(new LogItemDetailsViewVM() + { + Log = SelectedLog, + }); + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/MainViewVM.cs index d63a89f3b..4f8aba952 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/MainViewVM.cs @@ -12,13 +12,13 @@ namespace Tango.PPC.Technician.ViewModels { public override void OnApplicationStarted() { - + } public override void OnNavigatedTo() { base.OnNavigatedTo(); - NavigationManager.NavigateTo<TechnicianModule>(nameof(CatalogView)); + NavigationManager.NavigateTo<TechnicianModule>(nameof(CatalogView), false); } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/PackagesViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/PackagesViewVM.cs new file mode 100644 index 000000000..1d7e1780a --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/PackagesViewVM.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.DI; +using Tango.PPC.Common; +using Tango.PPC.Common.UpdatePackages; +using Tango.PPC.Shared.Updates; + +namespace Tango.PPC.Technician.ViewModels +{ + public class PackagesViewVM : PPCViewModel + { + [TangoInject(TangoInjectMode.WhenAvailable)] + public IPackageRunner PackageRunner { get; set; } + + private List<PackageInstallation> _packages; + public List<PackageInstallation> Packages + { + get { return _packages; } + set { _packages = value; RaisePropertyChangedAuto(); } + } + + public override void OnApplicationStarted() + { + + } + + public async override void OnApplicationReady() + { + base.OnApplicationReady(); + + try + { + Packages = (await PackageRunner.GetPackagesFile()).PackageInstallations; + } + catch (Exception ex) + { + LogManager.Log(ex, "An error occurred while trying to list the installed update packages."); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/RemoteConnectionsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/RemoteConnectionsViewVM.cs new file mode 100644 index 000000000..2d8857329 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/RemoteConnectionsViewVM.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Integration.ExternalBridge; +using Tango.PPC.Common; + +namespace Tango.PPC.Technician.ViewModels +{ + public class RemoteConnectionsViewVM : PPCViewModel + { + public RelayCommand DisconnectCommand { get; set; } + + private ExternalBridgeReceiver _selectedReceiver; + public ExternalBridgeReceiver SelectedReceiver + { + get { return _selectedReceiver; } + set + { + if (value != null) + { + _selectedReceiver = value; + InvalidateRelayCommands(); + } + } + } + + public RemoteConnectionsViewVM() + { + DisconnectCommand = new RelayCommand(DisconnectReceiver, () => SelectedReceiver != null); + } + + private async void DisconnectReceiver() + { + if (SelectedReceiver != null) + { + try + { + await Task.Factory.StartNew(() => + { + SelectedReceiver.Disconnect().Wait(); + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error disconnecting the specified receiver."); + } + finally + { + _selectedReceiver = null; + RaisePropertyChanged(nameof(SelectedReceiver)); + InvalidateRelayCommands(); + } + } + } + + public override void OnApplicationStarted() + { + + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs index 444c1d09e..452907366 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs @@ -8,16 +8,20 @@ using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using System.Timers; +using Tango.BL; using Tango.Core.Commands; using Tango.PPC.Common; using Tango.PPC.Common.OS; using Tango.Settings; +using System.Data.Entity; +using Tango.PPC.Common.UWF; namespace Tango.PPC.Technician.ViewModels { public class SystemViewVM : PPCViewModel { private IOperationSystemManager _os; + private IUnifiedWriteFilterManager _uwf; private Timer _statsTimer; private bool _resettingDevice; @@ -56,6 +60,20 @@ namespace Tango.PPC.Technician.ViewModels set { _ipAddress = value; RaisePropertyChangedAuto(); } } + private String _totalDyeTime; + public String TotalDyeTime + { + get { return _totalDyeTime; } + set { _totalDyeTime = value; RaisePropertyChangedAuto(); } + } + + private String _totalDyeMeters; + public String TotalDyeMeters + { + get { return _totalDyeMeters; } + set { _totalDyeMeters = value; RaisePropertyChangedAuto(); } + } + public RelayCommand ResetDeviceCommand { get; set; } public RelayCommand RestartCommand { get; set; } @@ -66,9 +84,10 @@ namespace Tango.PPC.Technician.ViewModels public RelayCommand ExitToExplorerCommand { get; set; } - public SystemViewVM(IOperationSystemManager os) + public SystemViewVM(IOperationSystemManager os, IUnifiedWriteFilterManager uwf) { _os = os; + _uwf = uwf; CPU = 0; RAM = 0; @@ -86,7 +105,7 @@ namespace Tango.PPC.Technician.ViewModels { _resettingDevice = true; ResetDeviceCommand.RaiseCanExecuteChanged(); - await MachineProvider.MachineOperator.ResetDFU(); + await MachineProvider.MachineOperator.Reset(); await NotificationProvider.ShowInfo("Embedded device has been reset successfully."); } catch (Exception ex) @@ -102,11 +121,30 @@ namespace Tango.PPC.Technician.ViewModels private async void FactoryReset() { - if (await NotificationProvider.ShowQuestion("Are you sure you want to reset this device and back to factory settings?")) + if (await NotificationProvider.ShowQuestion("Are you sure you want to reset this device back to factory settings?")) { Settings.ApplicationState = ApplicationStates.FactoryRestore; Settings.Save(); - ApplicationManager.Restart(); + try + { + NotificationProvider.SetGlobalBusyMessage("Disabling write filter protection..."); + await _uwf.Disable(); + await Task.Delay(2000); + NotificationProvider.ReleaseGlobalBusyMessage(); + await NavigationManager.NavigateTo(Common.Navigation.NavigationView.RestartingSystemView); + await Task.Delay(4000); + _os.Restart(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error executing factory reset."); + NotificationProvider.ReleaseGlobalBusyMessage(); + await NotificationProvider.ShowError($"Error executing factory reset.\n{ex.FlattenMessage()}"); + } + finally + { + NotificationProvider.ReleaseGlobalBusyMessage(); + } } } @@ -122,6 +160,8 @@ namespace Tango.PPC.Technician.ViewModels { if (await NotificationProvider.ShowQuestion("Are you sure you want to restart the device?")) { + await NavigationManager.NavigateTo(Common.Navigation.NavigationView.RestartingSystemView); + await Task.Delay(4000); _os.Restart(); } } @@ -130,12 +170,7 @@ namespace Tango.PPC.Technician.ViewModels { if (await NotificationProvider.ShowQuestion("Close the application and start OS shell?")) { - Process.Start(new ProcessStartInfo() - { - UseShellExecute = true, - FileName = "explorer.exe", - }); - + _os.OpenShell(); ApplicationManager.ShutDown(); } } @@ -148,12 +183,6 @@ namespace Tango.PPC.Technician.ViewModels _statsTimer.Start(); } - public override void OnApplicationReady() - { - base.OnApplicationReady(); - IPAddress = GetIpv4Address(); - } - private void _statsTimer_Elapsed(object sender, ElapsedEventArgs e) { if (IsVisible) @@ -244,5 +273,31 @@ namespace Tango.PPC.Technician.ViewModels return "N/A"; } } + + public async override void OnNavigatedTo() + { + base.OnNavigatedTo(); + + IPAddress = GetIpv4Address(); + + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var jobRuns = await db.JobRuns.Select(x => new { x.StartDate, x.EndDate, x.EndPosition }).ToListAsync(); + + TotalDyeTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToStringUnlimitedHours(); + + int meters = (int)jobRuns.Select(x => x.EndPosition).Sum(); + TotalDyeMeters = $"{meters.ToString("N0")} meters"; + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading machine counters."); + TotalDyeTime = "error!"; + TotalDyeMeters = "error!"; + } + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/UpdatesViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/UpdatesViewVM.cs new file mode 100644 index 000000000..3f4232252 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/UpdatesViewVM.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.Core.Commands; +using Tango.PPC.Common; +using System.Data.Entity; +using Tango.PPC.Technician.Dialogs; +using Tango.PPC.Common.Synchronization; + +namespace Tango.PPC.Technician.ViewModels +{ + public class UpdatesViewVM : PPCViewModel + { + public RelayCommand SynchronizeCommand { get; set; } + + private List<TangoUpdate> _updates; + public List<TangoUpdate> Updates + { + get { return _updates; } + set { _updates = value; RaisePropertyChangedAuto(); } + } + + private TangoUpdate _selectedUpdate; + public TangoUpdate SelectedUpdate + { + get { return _selectedUpdate; } + set { _selectedUpdate = value; OnSelectedUpdateChanged(); } + } + + private SynchronizationStatus _selectedSynchronization; + public SynchronizationStatus SelectedSynchronization + { + get { return _selectedSynchronization; } + set { _selectedSynchronization = value; OnSelectedSynchronizationChanged(); } + } + + public UpdatesViewVM() + { + Updates = new List<TangoUpdate>(); + SynchronizeCommand = new RelayCommand(Synchronize, () => !MachineDataSynchronizer.IsSynchronizing); + } + + public override void OnApplicationStarted() + { + + } + + public override void OnApplicationReady() + { + base.OnApplicationReady(); + MachineDataSynchronizer.SynchronizationStarted += (_, __) => InvalidateRelayCommands(); + MachineDataSynchronizer.SynchronizationEnded += (_, __) => InvalidateRelayCommands(); + } + + private async void Synchronize() + { + try + { + await MachineDataSynchronizer.Synchronize(); + } + catch { } + } + + public async override void OnNavigatedTo() + { + base.OnNavigatedTo(); + + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + Updates = await db.TangoUpdates.Where(x => + x.Status != (int)TangoUpdateStatuses.SynchronizationCompleted && + x.Status != (int)TangoUpdateStatuses.SynchronizationFailed && + x.Status != (int)TangoUpdateStatuses.SynchronizationStarted + ).OrderByDescending(x => x.StartDate).ToListAsync(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading update history."); + } + } + + private async void OnSelectedUpdateChanged() + { + if (SelectedUpdate != null) + { + await NotificationProvider.ShowDialog<UpdateDetailsViewVM>(new UpdateDetailsViewVM() { Update = SelectedUpdate }); + } + } + + private async void OnSelectedSynchronizationChanged() + { + if (SelectedSynchronization != null) + { + await NotificationProvider.ShowDialog<SynchronizationDetailsViewVM>(new SynchronizationDetailsViewVM() { Status = SelectedSynchronization }); + } + } + } +} |
