From cd15d687263d067e6ac1e57837649ad01a2b2f9b Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Tue, 25 May 2021 15:22:25 +0200 Subject: [PATCH] adding status bar to main window (outputview) --- .../Implementation/JobListViewModel.cs | 45 +++++-------------- .../Implementation/OutputViewModel.cs | 8 ++++ .../Implementation/SettingsViewModel.cs | 1 + VECTO3GUI2020/Views/OutputView.xaml | 4 +- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs index 20b83f277a..c3a75479a9 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs @@ -22,6 +22,7 @@ using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.InputData.FileIO.JSON; @@ -159,25 +160,19 @@ namespace VECTO3GUI2020.ViewModel.Implementation SimulationRunning = true; await RunSimulationAsync(cancellationTokenSource.Token, new Progress<MessageEntry>((message) => { _outputViewModel.Messages.Add(message); }), - new Progress<int>((i) => _outputViewModel.Progress = i)); + new Progress<int>((i) => _outputViewModel.Progress = i), + new Progress<string>((msg) => _outputViewModel.StatusMessage = msg)); SimulationRunning = false; _outputViewModel.Progress = 0; cancellationTokenSource.Dispose(); } - private async Task RunSimulationAsync(CancellationToken ct, IProgress<MessageEntry> outputMessages, IProgress<int> progress) + private async Task RunSimulationAsync(CancellationToken ct, IProgress<MessageEntry> outputMessages, + IProgress<int> progress, IProgress<string> status) { progress.Report(0); - //for (int i = 0; i <= 100; i++) { - // await Task.Delay(100); - // progress.Report(i); - // if (ct.IsCancellationRequested) { - // return; - // } - //} - - - + status.Report("starting..."); + IDocumentViewModel[] jobs; lock (_jobsLock) { jobs = Jobs.Where(x => x.Selected).ToArray(); @@ -187,22 +182,14 @@ namespace VECTO3GUI2020.ViewModel.Implementation Time = DateTime.Now, Type = MessageType.InfoMessage, }); + status.Report("No jobs selected"); return; } } - //TODO add output path to settings - var outputPath = Settings.Default.DefaultFilePath; - var sumFileWriter = new FileOutputWriter(GetOutputDirectory(Jobs.First(x => x.Selected).DataSource.SourceFile)); - - - var sumContainer = new SummaryDataContainer(sumFileWriter); var jobContainer = new JobContainer(sumContainer); - - - var mode = ExecutionMode.Declaration; var fileWriters = new Dictionary<int, FileOutputWriter>(); @@ -210,9 +197,6 @@ namespace VECTO3GUI2020.ViewModel.Implementation var xmlReader = _inputDataReader; - - - foreach (var jobEntry in jobs) { try { @@ -368,15 +352,10 @@ namespace VECTO3GUI2020.ViewModel.Implementation var duration = start.Elapsed.TotalSeconds; progress.Report(Convert.ToInt32(sumProgress * 100 / jobProgress.Count)); - //outputMessages.Report( - // new MessageEntry() - // { - // Type = VectoSimulationProgress.MsgType.Progress, - // Message = string.Format( - // "Duration: {0:F1}s, Curernt Progress: {1:P} ({2})", duration, sumProgress / progress.Count, - // string.Join(", ", progress.Select(x => string.Format("{0,4:P}", x.Value.Progress)))) - // }); - var justFinished = jobProgress.Where(x => x.Value.Done & !finishedRuns.Contains(x.Key)) + status.Report(string.Format( + "Duration: {0:F1}s, Current Progress: {1:P} ({2})", duration, sumProgress / jobProgress.Count, + string.Join(", ", jobProgress.Select(x => string.Format("{0,4:P}", x.Value.Progress))))); + var justFinished = jobProgress.Where(x => x.Value.Done & !finishedRuns.Contains(x.Key)) .ToDictionary(x => x.Key, x => x.Value); //PrintRuns(justFinished, fileWriters); finishedRuns.AddRange(justFinished.Select(x => x.Key)); diff --git a/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs index 88ea0207fc..476599bad3 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/OutputViewModel.cs @@ -15,6 +15,7 @@ namespace VECTO3GUI2020.ViewModel private object _messageLock = new Object(); private ObservableCollection<MessageEntry> _messages = new ObservableCollection<MessageEntry>(); private int _progress; + private string _statusMessage; public ObservableCollection<MessageEntry> Messages { @@ -30,6 +31,12 @@ namespace VECTO3GUI2020.ViewModel set => SetProperty(ref _progress, value); } + public string StatusMessage + { + get { return _statusMessage; } + set { SetProperty(ref _statusMessage, value); } + } + public OutputViewModel() { @@ -45,5 +52,6 @@ namespace VECTO3GUI2020.ViewModel ObservableCollection<MessageEntry> Messages { get; } int Progress { get; set; } + string StatusMessage { get; set; } } } \ No newline at end of file diff --git a/VECTO3GUI2020/ViewModel/Implementation/SettingsViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/SettingsViewModel.cs index e1a1adcb50..76246e6e1f 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/SettingsViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/SettingsViewModel.cs @@ -61,6 +61,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation _actualModalData = _settings.ActualModalData; _serializeVectoRunData = _settings.SerializeVectoRunData; _dialogHelper = dialogHelper; + _defaultOutputPath = _settings.DefaultOutputPath; } private ICommand _closeWindowCommand; diff --git a/VECTO3GUI2020/Views/OutputView.xaml b/VECTO3GUI2020/Views/OutputView.xaml index 89a5c64cec..e6d9e6863a 100644 --- a/VECTO3GUI2020/Views/OutputView.xaml +++ b/VECTO3GUI2020/Views/OutputView.xaml @@ -5,8 +5,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:VECTO3GUI2020.Views" xmlns:impl="clr-namespace:VECTO3GUI2020.ViewModel.Implementation" + xmlns:viewModel="clr-namespace:VECTO3GUI2020.ViewModel" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> + d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignData Type=viewModel:IOutputViewModel}"> <Grid> <DockPanel> <ProgressBar DockPanel.Dock="Top" Minimum="0" Maximum="100" Value="{Binding Progress}"></ProgressBar> @@ -63,6 +64,7 @@ </Style> </DataGrid.CellStyle> </DataGrid> + <StatusBar DockPanel.Dock="Bottom" VerticalAlignment="Bottom"><TextBlock Text="{Binding StatusMessage}"/></StatusBar> </DockPanel> </Grid> </UserControl> -- GitLab