This commit is contained in:
Tobias Wohlleben 2025-01-20 13:54:38 +01:00
parent e0ebb25f17
commit f68af2d8c7
7 changed files with 72 additions and 77 deletions

View File

@ -55,11 +55,11 @@ public class CameraService : IDisposable
} }
catch (DllNotFoundException) catch (DllNotFoundException)
{ {
ReportError("Canon DLLs not found!", true); this.ReportError("Canon DLLs not found!");
} }
catch (Exception ex) catch (Exception ex)
{ {
ReportError(ex.Message, true); this.ReportError(ex.Message);
} }
} }
@ -141,33 +141,9 @@ public class CameraService : IDisposable
} }
private void ReportError(string message, bool lockdown) private void ReportError(string message)
{ {
int errc;
lock (ErrLock)
{
errc = ++ErrCount;
}
if (lockdown)
{
//this.EnableUI(false);
}
switch (errc)
{
case < 4:
this._logger.Info(message); this._logger.Info(message);
break;
case 4:
this._logger.Info("Many errors happened!");
break;
}
lock (ErrLock)
{
ErrCount--;
}
} }
@ -188,7 +164,7 @@ public class CameraService : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
ReportError(ex.Message, false); this.ReportError(ex.Message);
} }
} }
@ -220,7 +196,7 @@ public class CameraService : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
ReportError(ex.Message, false); this.ReportError(ex.Message);
} }
} }
@ -273,20 +249,20 @@ public class CameraService : IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
ReportError(ex.Message, false); this.ReportError(ex.Message);
} }
} }
private void ErrorHandler_NonSevereErrorHappened(object sender, ErrorCode ex) private void ErrorHandler_NonSevereErrorHappened(object sender, ErrorCode ex)
{ {
ReportError($"SDK Error code: {ex} ({((int)ex).ToString("X")})", false); this.ReportError($"SDK Error code: {ex} ({((int)ex).ToString("X")})");
} }
private void ErrorHandler_SevereErrorHappened(object sender, Exception ex) private void ErrorHandler_SevereErrorHappened(object sender, Exception ex)
{ {
ReportError(ex.Message, true); this.ReportError(ex.Message);
} }
#endregion #endregion
@ -296,11 +272,11 @@ public class CameraService : IDisposable
{ {
try try
{ {
MainCamera.TakePhotoAsync(); MainCamera.TakePhoto();
} }
catch (Exception ex) catch (Exception ex)
{ {
ReportError(ex.Message, false); this.ReportError(ex.Message);
} }
} }

View File

@ -64,9 +64,16 @@ public partial class LiveViewPage : Page
public void TakePhoto() public void TakePhoto()
{
try
{ {
this._cameraService.TakePhoto(); this._cameraService.TakePhoto();
} }
catch (Exception e)
{
this._logger.Error(e.Message);
}
}
public void Dispose() public void Dispose()

View File

@ -49,11 +49,12 @@ public partial class MainWindow : Window
} }
private void LoadPicturePanelAsync() private async void LoadPicturePanelAsync()
{ {
//this.PicturePanelPage.Visibility = Visibility.Hidden; //this.PictureGalleryPage.Visibility = Visibility.Hidden;
//this.PicturePanelPage.Navigate(new PicturePanelPage(this._appSettings, this._logger)); //this.PictureGalleryPage.Navigate(new PictureGalleryPage(this._appSettings, this._logger));
this._pictureGalleryService.LoadThumbnailsToCache(); // this._pictureGalleryService.LoadThumbnailsToCache();
await this._pictureGalleryService.LoadThumbnailsToCache();
//this.DebugFrame.Navigate(new DebugConsolePage(this._logger)); //this.DebugFrame.Navigate(new DebugConsolePage(this._logger));
} }
@ -62,7 +63,7 @@ public partial class MainWindow : Window
{ {
if (visibility) if (visibility)
{ {
this.PicturePanel.Navigate(new PicturePanelPage(this._appSettings, this._logger, this._pictureGalleryService)); this.PicturePanel.Navigate(new PictureGalleryPage(this._appSettings, this._logger, this._pictureGalleryService));
} }
else else
{ {

View File

@ -1,11 +1,11 @@
<Page x:Class="CamBooth.App.PictureGallery.PicturePanelPage" <Page x:Class="CamBooth.App.PictureGallery.PictureGalleryPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CamBooth.App.PictureGallery" xmlns:local="clr-namespace:CamBooth.App.PictureGallery"
mc:Ignorable="d" mc:Ignorable="d"
Title="PicturePanelPage" Width="1600" Height="795" Title="PictureGalleryPage" Width="1600" Height="795"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Background="Magenta"> Background="Magenta">
<Grid> <Grid>

View File

@ -10,7 +10,7 @@ using Image = Wpf.Ui.Controls.Image;
namespace CamBooth.App.PictureGallery; namespace CamBooth.App.PictureGallery;
public partial class PicturePanelPage : Page, IDisposable public partial class PictureGalleryPage : Page, IDisposable
{ {
private readonly AppSettingsService _appSettingsService; private readonly AppSettingsService _appSettingsService;
@ -19,7 +19,7 @@ public partial class PicturePanelPage : Page, IDisposable
private readonly PictureGalleryService _pictureGalleryService; private readonly PictureGalleryService _pictureGalleryService;
public PicturePanelPage(AppSettingsService appSettingsService, Logger logger, PictureGalleryService pictureGalleryService) public PictureGalleryPage(AppSettingsService appSettingsService, Logger logger, PictureGalleryService pictureGalleryService)
{ {
this._appSettingsService = appSettingsService; this._appSettingsService = appSettingsService;
this._logger = logger; this._logger = logger;
@ -46,6 +46,9 @@ public partial class PicturePanelPage : Page, IDisposable
{ {
int loop = 0; int loop = 0;
this.Dispatcher.Invoke(
() =>
{
do do
{ {
BitmapImage thumbnail = this._pictureGalleryService.ThumbnailsOrderedByNewestDescending[loop]; BitmapImage thumbnail = this._pictureGalleryService.ThumbnailsOrderedByNewestDescending[loop];
@ -61,6 +64,7 @@ public partial class PicturePanelPage : Page, IDisposable
loop++; loop++;
} }
while ((loop < howManyPictures || howManyPictures == 0) && loop < this._pictureGalleryService.ThumbnailsOrderedByNewestDescending.Count); while ((loop < howManyPictures || howManyPictures == 0) && loop < this._pictureGalleryService.ThumbnailsOrderedByNewestDescending.Count);
});
} }

View File

@ -15,8 +15,8 @@ public class PictureGalleryService
private readonly Logger _logger; private readonly Logger _logger;
public List<BitmapImage> ThumbnailsOrderedByNewestDescending => this.thumbnails. public List<BitmapImage> ThumbnailsOrderedByNewestDescending =>
OrderByDescending(map => map.Key) this.thumbnails.OrderByDescending(map => map.Key)
.Select(ordered => ordered.Value) .Select(ordered => ordered.Value)
.ToList(); .ToList();
@ -30,7 +30,7 @@ public class PictureGalleryService
} }
public void LoadThumbnailsToCache(int cacheSize = 0) public async Task LoadThumbnailsToCache(int cacheSize = 0)
{ {
this._logger.Info("Start load thumbnails into cache"); this._logger.Info("Start load thumbnails into cache");
string? pictureLocation = this._appSettings.PictureLocation; string? pictureLocation = this._appSettings.PictureLocation;
@ -38,6 +38,9 @@ public class PictureGalleryService
List<string> picturePaths = Directory.EnumerateFiles(pictureLocation).ToList(); List<string> picturePaths = Directory.EnumerateFiles(pictureLocation).ToList();
await Task.Run(
() =>
{
do do
{ {
string picturePath = picturePaths[loop]; string picturePath = picturePaths[loop];
@ -54,10 +57,11 @@ public class PictureGalleryService
loop++; loop++;
} }
while ((loop < cacheSize || cacheSize == 0) && loop < picturePaths.Count); while ((loop < cacheSize || cacheSize == 0) && loop < picturePaths.Count);
});
this._logger.Info("Loading thumbnails into cache completed"); this._logger.Info("Loading thumbnails into cache completed");
} }
public static BitmapImage CreateThumbnail(string filePath, int maxWidth, int maxHeight) public static BitmapImage CreateThumbnail(string filePath, int maxWidth, int maxHeight)
{ {
var bitmap = new BitmapImage(); var bitmap = new BitmapImage();
@ -66,6 +70,7 @@ public class PictureGalleryService
bitmap.DecodePixelWidth = maxWidth; // Größe des ThumbnailsOrderedByNewestDescending direkt beim Dekodieren festlegen bitmap.DecodePixelWidth = maxWidth; // Größe des ThumbnailsOrderedByNewestDescending direkt beim Dekodieren festlegen
bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit(); bitmap.EndInit();
bitmap.Freeze(); // Threadsicher machen
return bitmap; return bitmap;
} }
} }

View File

@ -7,6 +7,8 @@
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CDev_005CRepos_005CPrivat_005CCamBooth_005Cmisc_005CCanonBinaries_005CMlib_002Edll/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CDev_005CRepos_005CPrivat_005CCamBooth_005Cmisc_005CCanonBinaries_005CMlib_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CDev_005CRepos_005CPrivat_005CCamBooth_005Cmisc_005CCanonBinaries_005CUcs32P_002Edll/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CDev_005CRepos_005CPrivat_005CCamBooth_005Cmisc_005CCanonBinaries_005CUcs32P_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AApplication_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6665f2e3e843578225e3796b83c5342a58c3f72bfef19eeee7aa90d157d4949_003FApplication_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AApplication_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F6665f2e3e843578225e3796b83c5342a58c3f72bfef19eeee7aa90d157d4949_003FApplication_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADispatcher_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F9ac32f819d6853e0a6eda168c52b7f38eef9ae75936fb85d96a15c39d115245_003FDispatcher_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEventRoute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F4bda76b5cc453e1edf5d5c754c4a8215edbd3d3e4f80706dcf4f52a4f68979_003FEventRoute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F793c644a163b4a9992123fa9cc1562efbf3908_003F4a_003Fd28af422_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F793c644a163b4a9992123fa9cc1562efbf3908_003F4a_003Fd28af422_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fbd1d5c50194fea68ff3559c160230b0ab50f5acf4ce3061bffd6d62958e2182_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExceptionDispatchInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fbd1d5c50194fea68ff3559c160230b0ab50f5acf4ce3061bffd6d62958e2182_003FExceptionDispatchInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWindow_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0713c794b56e4feca091d5981a6f5967f60930_003Fc8_003F61b7e802_003FWindow_002Ecs/@EntryIndexedValue">ForceIncluded</s:String> <s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AWindow_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003Ftobia_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0713c794b56e4feca091d5981a6f5967f60930_003Fc8_003F61b7e802_003FWindow_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>