From 813c78eb40d6c3a5079947707a9b481f25f55064 Mon Sep 17 00:00:00 2001 From: Ankitkumar Satapara Date: Sun, 19 Apr 2026 18:24:36 +0530 Subject: [PATCH] Added running log panel in the below screen --- .../Nodify.Calculator/ApplicationViewModel.cs | 22 +++- .../Nodify.Calculator/LogPanelViewModel.cs | 76 ++++++++++++ Examples/Nodify.Calculator/MainWindow.xaml | 114 +++++++++++++++++- Examples/Nodify.Calculator/MainWindow.xaml.cs | 19 +++ 4 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 Examples/Nodify.Calculator/LogPanelViewModel.cs diff --git a/Examples/Nodify.Calculator/ApplicationViewModel.cs b/Examples/Nodify.Calculator/ApplicationViewModel.cs index 4d45578..fac7041 100644 --- a/Examples/Nodify.Calculator/ApplicationViewModel.cs +++ b/Examples/Nodify.Calculator/ApplicationViewModel.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Shapes; @@ -25,6 +26,8 @@ namespace Nodify.Calculator _ => Editors.Count > 0 && SelectedEditor != null); RunFlowCommand = new DelegateCommand(() => { + if (LogPanel.IsRunning) return; + Executor ex = new Executor(Editors.First()); var result = ex.PerformPreCheck(); if (!string.IsNullOrEmpty(result)) @@ -33,8 +36,21 @@ namespace Nodify.Calculator } else { - FlowRunner runner = new FlowRunner(ex); - runner.ShowDialog(); + LogPanel.LogEntries.Clear(); + LogPanel.IsOpen = true; + LogPanel.IsRunning = true; + ex.OnLogMe += LogPanel.WriteLog; + Task.Run(() => + { + try + { + ex.Execute(); + } + finally + { + Application.Current?.Dispatcher.Invoke(() => LogPanel.IsRunning = false); + } + }); } }); SaveFileCommand = new DelegateCommand(() => @@ -127,5 +143,7 @@ namespace Nodify.Calculator get => _autoSelectNewEditor; set => SetProperty(ref _autoSelectNewEditor, value); } + + public LogPanelViewModel LogPanel { get; } = new LogPanelViewModel(); } } diff --git a/Examples/Nodify.Calculator/LogPanelViewModel.cs b/Examples/Nodify.Calculator/LogPanelViewModel.cs new file mode 100644 index 0000000..55d30c1 --- /dev/null +++ b/Examples/Nodify.Calculator/LogPanelViewModel.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.ObjectModel; +using System.Windows.Media; + +namespace Nodify.Calculator +{ + public class LogEntry + { + public string Timestamp { get; set; } + public string Level { get; set; } + public string Message { get; set; } + public Brush Color { get; set; } + } + + public class LogPanelViewModel : ObservableObject + { + private bool _isOpen; + public bool IsOpen + { + get => _isOpen; + set => SetProperty(ref _isOpen, value); + } + + private bool _isRunning; + public bool IsRunning + { + get => _isRunning; + set => SetProperty(ref _isRunning, value); + } + + public ObservableCollection LogEntries { get; } = new ObservableCollection(); + + public INodifyCommand ClearLogsCommand { get; } + public INodifyCommand ClosePanelCommand { get; } + + public LogPanelViewModel() + { + ClearLogsCommand = new DelegateCommand(() => LogEntries.Clear()); + ClosePanelCommand = new DelegateCommand(() => IsOpen = false); + } + + public void WriteLog(string message, logType logtype = logType.Information) + { + Brush color; + switch (logtype) + { + case logType.Warning: + color = Brushes.Orange; + break; + case logType.Error: + color = Brushes.OrangeRed; + break; + default: + color = Brushes.White; + break; + } + + var entry = new LogEntry + { + Timestamp = DateTime.Now.ToString("HH:mm:ss"), + Level = logtype.ToString(), + Message = message, + Color = color + }; + + if (System.Windows.Application.Current?.Dispatcher.CheckAccess() == true) + { + LogEntries.Add(entry); + } + else + { + System.Windows.Application.Current?.Dispatcher.Invoke(() => LogEntries.Add(entry)); + } + } + } +} diff --git a/Examples/Nodify.Calculator/MainWindow.xaml b/Examples/Nodify.Calculator/MainWindow.xaml index 3990ccd..2e6ebd1 100644 --- a/Examples/Nodify.Calculator/MainWindow.xaml +++ b/Examples/Nodify.Calculator/MainWindow.xaml @@ -51,7 +51,14 @@ - + + + + + + @@ -70,7 +77,110 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + +