diff --git a/src/CamBooth/CamBooth.App/Core/Logging/Logger.cs b/src/CamBooth/CamBooth.App/Core/Logging/Logger.cs index 699b9a9..6285f93 100644 --- a/src/CamBooth/CamBooth.App/Core/Logging/Logger.cs +++ b/src/CamBooth/CamBooth.App/Core/Logging/Logger.cs @@ -6,6 +6,7 @@ namespace CamBooth.App.Core.Logging; public class Logger { public event LoggingEventHandler? InfoLog; + public event LoggingEventHandler? ErrorLog; public delegate void LoggingEventHandler(string text); public void Info(string message) @@ -18,4 +19,14 @@ public class Logger }); } + public void Error(string message) + { + Application.Current.Dispatcher.Invoke(() => + { + message = DateTime.Now.ToString("dd.MM.yyyy HH:MM:ss", CultureInfo.InvariantCulture) + ": " + message; + ErrorLog?.Invoke(message); + Console.WriteLine(message); + }); + + } } \ No newline at end of file diff --git a/src/CamBooth/CamBooth.App/DebugConsole/DebugConsolePage.xaml.cs b/src/CamBooth/CamBooth.App/DebugConsole/DebugConsolePage.xaml.cs index 83c58db..9cde885 100644 --- a/src/CamBooth/CamBooth.App/DebugConsole/DebugConsolePage.xaml.cs +++ b/src/CamBooth/CamBooth.App/DebugConsole/DebugConsolePage.xaml.cs @@ -1,4 +1,5 @@ using System.Windows.Controls; +using System.Windows.Media; using CamBooth.App.Core.Logging; @@ -9,9 +10,18 @@ public partial class DebugConsolePage : Page public DebugConsolePage(Logger logger) { logger.InfoLog += Logger_OnInfoLog; + logger.ErrorLog += Logger_OnErrorLog; InitializeComponent(); } + + private void Logger_OnErrorLog(string text) + { + this.tbDebugOutput.Text = this.tbDebugOutput.Text.Insert(0, text + "\n"); + this.tbDebugOutput.Background = new SolidColorBrush(Colors.Tomato); + } + + private void Logger_OnInfoLog(string text) { this.tbDebugOutput.Text = this.tbDebugOutput.Text.Insert(0, text + "\n"); diff --git a/src/CamBooth/CamBooth.App/MainWindow.xaml.cs b/src/CamBooth/CamBooth.App/MainWindow.xaml.cs index 72dae0a..d158c5d 100644 --- a/src/CamBooth/CamBooth.App/MainWindow.xaml.cs +++ b/src/CamBooth/CamBooth.App/MainWindow.xaml.cs @@ -46,7 +46,7 @@ public partial class MainWindow : Window { //this.PicturePanel.Visibility = Visibility.Hidden; //this.PicturePanel.Navigate(new PicturePanel(this._appSettings, this._logger)); - Task.Run(() => this._pictureGalleryService.LoadThumbnailsToCache(12)); + this._pictureGalleryService.LoadThumbnailsToCache(12); //this.DebugFrame.Navigate(new DebugConsolePage(this._logger)); } diff --git a/src/CamBooth/CamBooth.App/PictureGallery/PictureGalleryService.cs b/src/CamBooth/CamBooth.App/PictureGallery/PictureGalleryService.cs index 503640c..458edb1 100644 --- a/src/CamBooth/CamBooth.App/PictureGallery/PictureGalleryService.cs +++ b/src/CamBooth/CamBooth.App/PictureGallery/PictureGalleryService.cs @@ -19,16 +19,18 @@ public class PictureGalleryService { get { - List tmp = new List(); - foreach (var image in imageControls) - { - tmp.Add(image); - } - return tmp; + // List tmp = new List(); + // foreach (var image in imageControls) + // { + // tmp.Add(image); + // } + // return tmp; + + return this.imageControls; } } - public List imageControls = new List(); + private List imageControls = new List(); public PictureGalleryService(AppSettingsService appSettings, Logger logger) @@ -70,7 +72,6 @@ public class PictureGalleryService bitmap.BeginInit(); bitmap.UriSource = new Uri(filePath); bitmap.DecodePixelWidth = maxWidth; // Größe des Thumbnails direkt beim Dekodieren festlegen - // bitmap.DecodePixelHeight = maxHeight; bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.EndInit(); return bitmap; diff --git a/src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml.cs b/src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml.cs index b44a907..ba324fa 100644 --- a/src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml.cs +++ b/src/CamBooth/CamBooth.App/PictureGallery/PicturePanel.xaml.cs @@ -10,7 +10,7 @@ using Image = Wpf.Ui.Controls.Image; namespace CamBooth.App.PictureGallery; -public partial class PicturePanel : Page +public partial class PicturePanel : Page, IDisposable { private readonly AppSettingsService _appSettingsService; @@ -37,7 +37,7 @@ public partial class PicturePanel : Page } catch (Exception e) { - this._logger.Info(e.Message); + this._logger.Error(e.Message); } } @@ -46,7 +46,17 @@ public partial class PicturePanel : Page { foreach (Image ctl in this._pictureGalleryService.ImageControls) { - this.PicturesPanel.Children.Add(ctl); + if(!this.PicturesPanel.Children.Contains(ctl)) + { + this.PicturesPanel.Children.Add(ctl); + } } } + + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + public void Dispose() + { + this.PicturesPanel.Children.Clear(); + } } \ No newline at end of file