Weitere verbesserungen
This commit is contained in:
parent
3a3c780c07
commit
6740835be7
@ -1,4 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
using CamBooth.App.Core.AppSettings;
|
||||
using CamBooth.App.Core.Logging;
|
||||
@ -25,31 +26,65 @@ public partial class App : Application
|
||||
base.OnStartup(e);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
|
||||
// Register base services
|
||||
services.AddSingleton<Logger>();
|
||||
services.AddSingleton<AppSettingsService>();
|
||||
services.AddSingleton<PictureGalleryService>();
|
||||
services.AddSingleton<CameraService>();
|
||||
|
||||
// Zuerst den Provider bauen, um AppSettings zu laden
|
||||
var tempProvider = services.BuildServiceProvider();
|
||||
var appSettings = tempProvider.GetRequiredService<AppSettingsService>();
|
||||
var logger = tempProvider.GetRequiredService<Logger>();
|
||||
|
||||
// Stelle sicher, dass das PictureLocation-Verzeichnis existiert
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(appSettings.PictureLocation))
|
||||
{
|
||||
Directory.CreateDirectory(appSettings.PictureLocation);
|
||||
logger.Info($"Picture directory created: {appSettings.PictureLocation}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error($"Failed to create picture directory: {ex.Message}");
|
||||
}
|
||||
|
||||
// Jetzt die Camera Services basierend auf AppSettings registrieren
|
||||
// Mit Try-Catch für fehlende DLL-Abhängigkeiten
|
||||
try
|
||||
{
|
||||
if (appSettings.UseMockCamera)
|
||||
{
|
||||
services.AddSingleton<ICanonAPI, CanonAPIMock>();
|
||||
services.AddSingleton<ICamera, CameraMock>();
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddSingleton<ICanonAPI, CanonAPI>();
|
||||
services.AddSingleton<ICamera, Camera>();
|
||||
}
|
||||
}
|
||||
catch (DllNotFoundException ex)
|
||||
{
|
||||
// Falls EDSDK DLL nicht gefunden, fallback auf Mock
|
||||
MessageBox.Show(
|
||||
$"EDSDK konnte nicht geladen werden. Verwende Mock-Kamera.\n\nFehler: {ex.Message}",
|
||||
"DLL nicht gefunden",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
services.AddSingleton<ICanonAPI, CanonAPIMock>();
|
||||
services.AddSingleton<ICamera, CameraMock>();
|
||||
}
|
||||
|
||||
services.AddTransient<MainWindow>();
|
||||
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
var mainWindow = _serviceProvider.GetRequiredService<MainWindow>();
|
||||
mainWindow.Show();
|
||||
}
|
||||
|
||||
|
||||
private void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Register your services and view models here
|
||||
services.AddTransient<MainWindow>();
|
||||
services.AddSingleton<Logger>();
|
||||
services.AddSingleton<AppSettingsService>();
|
||||
services.AddSingleton<PictureGalleryService>();
|
||||
services.AddSingleton<CameraService>();
|
||||
#if DEBUG
|
||||
services.AddSingleton<ICanonAPI, CanonAPIMock>();
|
||||
services.AddSingleton<ICamera, CameraMock>();
|
||||
#else
|
||||
services.AddSingleton<ICanonAPI, CanonAPI>();
|
||||
services.AddSingleton<ICamera, Camera>();
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
using CamBooth.App.Core.Logging;
|
||||
using CamBooth.App.Core.Logging;
|
||||
|
||||
namespace CamBooth.App.Core.AppSettings;
|
||||
|
||||
@ -21,22 +21,43 @@ public class AppSettingsService
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
|
||||
|
||||
loadedConfigFile = "Core/AppSettings/app.settings.json";
|
||||
#if DEBUG
|
||||
loadedConfigFile = "Core/AppSettings/app.settings.dev.json";
|
||||
#endif
|
||||
configuration = new ConfigurationBuilder()
|
||||
var configBuilder = new ConfigurationBuilder()
|
||||
.SetBasePath(AppContext.BaseDirectory)
|
||||
.AddJsonFile(loadedConfigFile, optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
.AddJsonFile(loadedConfigFile, optional: false, reloadOnChange: true);
|
||||
|
||||
// Lade umgebungsspezifische Konfigurationsdatei
|
||||
if (environment == "Development")
|
||||
{
|
||||
configBuilder.AddJsonFile("Core/AppSettings/app.settings.dev.json", optional: true, reloadOnChange: true);
|
||||
loadedConfigFile = "Core/AppSettings/app.settings.dev.json";
|
||||
}
|
||||
|
||||
configuration = configBuilder.Build();
|
||||
|
||||
_logger.Info($"Konfiguration geladen aus: {loadedConfigFile} (Environment: {environment})");
|
||||
}
|
||||
|
||||
public bool IsDebugMode => bool.Parse(configuration["AppSettings:IsDebugMode"] ?? "false");
|
||||
|
||||
public string? AppName => configuration["AppSettings:AppName"];
|
||||
|
||||
public bool IsDebugConsoleVisible => bool.Parse(configuration["AppSettings:DebugConsoleVisible"] ?? string.Empty);
|
||||
|
||||
public string? PictureLocation => configuration["AppSettings:PictureLocation"];
|
||||
|
||||
public int PhotoCountdownSeconds => int.Parse(configuration["AppSettings:PhotoCountdownSeconds"] ?? "5");
|
||||
|
||||
public int FocusDelaySeconds => int.Parse(configuration["AppSettings:FocusDelaySeconds"] ?? "2");
|
||||
|
||||
public int FocusTimeoutMs => int.Parse(configuration["AppSettings:FocusTimeoutMs"] ?? "3000");
|
||||
|
||||
public bool IsShutdownEnabled => bool.Parse(configuration["AppSettings:IsShutdownEnabled"] ?? "false");
|
||||
|
||||
public bool UseMockCamera => bool.Parse(configuration["AppSettings:UseMockCamera"] ?? "false");
|
||||
|
||||
public string? ConnectionString => configuration.GetConnectionString("DefaultConnection");
|
||||
|
||||
public string ConfigFileName => loadedConfigFile;
|
||||
|
||||
@ -2,8 +2,14 @@
|
||||
"AppSettings": {
|
||||
"AppName": "Meine Anwendung",
|
||||
"Version": "1.0.0",
|
||||
"IsDebugMode": true,
|
||||
"PictureLocation": "C:\\tmp\\cambooth",
|
||||
"DebugConsoleVisible": "true"
|
||||
"DebugConsoleVisible": "true",
|
||||
"PhotoCountdownSeconds": 2,
|
||||
"FocusDelaySeconds": 1,
|
||||
"FocusTimeoutMs": 1000,
|
||||
"IsShutdownEnabled": false,
|
||||
"UseMockCamera": true
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=myServer;Database=myDB;User Id=myUser;Password=myPassword;"
|
||||
|
||||
@ -2,8 +2,14 @@
|
||||
"AppSettings": {
|
||||
"AppName": "Meine Anwendung",
|
||||
"Version": "1.0.0",
|
||||
"IsDebugMode": false,
|
||||
"PictureLocation": "C:\\cambooth\\pictures",
|
||||
"DebugConsoleVisible": "true"
|
||||
"DebugConsoleVisible": "false",
|
||||
"PhotoCountdownSeconds": 5,
|
||||
"FocusDelaySeconds": 2,
|
||||
"FocusTimeoutMs": 3000,
|
||||
"IsShutdownEnabled": true,
|
||||
"UseMockCamera": true
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=myServer;Database=myDB;User Id=myUser;Password=myPassword;"
|
||||
|
||||
@ -317,7 +317,10 @@ public class CameraService : IDisposable
|
||||
Info.FileName = $"img_{Guid.NewGuid().ToString()}.jpg";
|
||||
sender.DownloadFile(Info, this._appSettings.PictureLocation);
|
||||
this._logger.Info("Download complete: " + Path.Combine(this._appSettings.PictureLocation, Info.FileName));
|
||||
Application.Current.Dispatcher.Invoke(() => { this._pictureGalleryService.LoadThumbnailsToCache(); });
|
||||
Application.Current.Dispatcher.Invoke(() => {
|
||||
this._pictureGalleryService.IncrementNewPhotoCount();
|
||||
this._pictureGalleryService.LoadThumbnailsToCache();
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@ -14,7 +14,6 @@ public partial class DebugConsolePage : Page
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
private void Logger_OnErrorLog(string text)
|
||||
{
|
||||
this.tbDebugOutput.Text = this.tbDebugOutput.Text.Insert(0, text + "\n");
|
||||
|
||||
@ -24,6 +24,8 @@ public partial class PictureGalleryPage : Page
|
||||
|
||||
private readonly PictureGalleryService _pictureGalleryService;
|
||||
|
||||
private ContentDialog? _openContentDialog;
|
||||
|
||||
|
||||
public PictureGalleryPage(AppSettingsService appSettingsService, Logger logger, PictureGalleryService pictureGalleryService)
|
||||
{
|
||||
@ -90,19 +92,52 @@ public partial class PictureGalleryPage : Page
|
||||
}
|
||||
|
||||
|
||||
public void CloseOpenDialog()
|
||||
{
|
||||
void CloseDialog()
|
||||
{
|
||||
if (this._openContentDialog is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._openContentDialog.ButtonClicked -= this.ContentDialog_OnButtonClicked;
|
||||
this._openContentDialog.GetType().GetMethod("Hide", Type.EmptyTypes)?.Invoke(this._openContentDialog, null);
|
||||
this.RootContentDialogPresenter.Content = null;
|
||||
this._openContentDialog = null;
|
||||
}
|
||||
|
||||
if (this.Dispatcher.CheckAccess())
|
||||
{
|
||||
CloseDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
this.Dispatcher.Invoke(CloseDialog);
|
||||
}
|
||||
|
||||
|
||||
private void Hyperlink_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Uri? picturePathUri = ((Hyperlink)sender).Tag as Uri;
|
||||
if (picturePathUri is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string picturePath = picturePathUri.AbsolutePath;
|
||||
Application.Current.Dispatcher.BeginInvoke(
|
||||
async () =>
|
||||
{
|
||||
ContentDialog contentDialog = new (this.RootContentDialogPresenter);
|
||||
this.CloseOpenDialog();
|
||||
ContentDialog contentDialog = new(this.RootContentDialogPresenter);
|
||||
this._openContentDialog = contentDialog;
|
||||
Image imageToShow = new()
|
||||
{
|
||||
MaxHeight = 570,
|
||||
Background = new SolidColorBrush(Colors.White),
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Source = PictureGalleryService.CreateThumbnail(picturePathUri.AbsolutePath, 450, 300)
|
||||
Source = PictureGalleryService.CreateThumbnail(picturePath, 450, 300)
|
||||
};
|
||||
|
||||
contentDialog.VerticalAlignment = VerticalAlignment.Top;
|
||||
@ -117,10 +152,23 @@ public partial class PictureGalleryPage : Page
|
||||
|
||||
// contentDialog.SetCurrentValue(ContentDialog.PrimaryButtonIconProperty, PictureGalleryService.CreateRegularSymbolIcon(SymbolRegular.Print48, Colors.Tomato));
|
||||
|
||||
contentDialog.Tag = picturePathUri.AbsolutePath;
|
||||
contentDialog.Tag = picturePath;
|
||||
contentDialog.ButtonClicked += this.ContentDialog_OnButtonClicked;
|
||||
|
||||
try
|
||||
{
|
||||
await contentDialog.ShowAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
contentDialog.ButtonClicked -= this.ContentDialog_OnButtonClicked;
|
||||
if (ReferenceEquals(this._openContentDialog, contentDialog))
|
||||
{
|
||||
this._openContentDialog = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
@ -17,6 +17,10 @@ public class PictureGalleryService
|
||||
|
||||
private readonly Dictionary<DateTime, BitmapImage> thumbnails = new();
|
||||
|
||||
private int _newPhotoCount = 0;
|
||||
|
||||
public event EventHandler<int>? NewPhotoCountChanged;
|
||||
|
||||
|
||||
public PictureGalleryService(AppSettingsService appSettings, Logger logger)
|
||||
{
|
||||
@ -30,6 +34,25 @@ public class PictureGalleryService
|
||||
.Select(ordered => ordered.Value)
|
||||
.ToList();
|
||||
|
||||
public int NewPhotoCount => _newPhotoCount;
|
||||
|
||||
public void IncrementNewPhotoCount()
|
||||
{
|
||||
_newPhotoCount++;
|
||||
OnNewPhotoCountChanged(_newPhotoCount);
|
||||
}
|
||||
|
||||
public void ResetNewPhotoCount()
|
||||
{
|
||||
_newPhotoCount = 0;
|
||||
OnNewPhotoCountChanged(_newPhotoCount);
|
||||
}
|
||||
|
||||
private void OnNewPhotoCountChanged(int count)
|
||||
{
|
||||
NewPhotoCountChanged?.Invoke(this, count);
|
||||
}
|
||||
|
||||
|
||||
public async Task LoadThumbnailsToCache(int cacheSize = 0)
|
||||
{
|
||||
@ -37,7 +60,33 @@ public class PictureGalleryService
|
||||
string? pictureLocation = this._appSettings.PictureLocation;
|
||||
int loop = 0;
|
||||
|
||||
List<string> picturePaths = Directory.EnumerateFiles(pictureLocation).ToList();
|
||||
// Sicherstellen, dass das Verzeichnis existiert
|
||||
if (!Directory.Exists(pictureLocation))
|
||||
{
|
||||
this._logger.Info($"Picture directory does not exist: '{pictureLocation}'. Creating it...");
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(pictureLocation);
|
||||
this._logger.Info($"Picture directory created: '{pictureLocation}'");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this._logger.Error($"Failed to create picture directory: {ex.Message}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter nur Bilddateien
|
||||
string[] imageExtensions = { ".jpg", ".jpeg", ".png", ".bmp", ".gif" };
|
||||
List<string> picturePaths = Directory.EnumerateFiles(pictureLocation)
|
||||
.Where(f => imageExtensions.Contains(Path.GetExtension(f).ToLower()))
|
||||
.ToList();
|
||||
|
||||
if (picturePaths.Count == 0)
|
||||
{
|
||||
this._logger.Info($"No pictures found in directory: '{pictureLocation}'");
|
||||
return;
|
||||
}
|
||||
|
||||
await Task.Run(
|
||||
() =>
|
||||
|
||||
@ -56,13 +56,12 @@
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Name="ButtonPanel" Background="Transparent" Panel.ZIndex="2"
|
||||
Visibility="Hidden"
|
||||
Margin="0 0 0 0">
|
||||
<ui:Button Content="Hide Debug" Click="SetVisibilityDebugConsole" Width="200" Height="75"
|
||||
<ui:Button x:Name="HideDebugButton" Content="Hide Debug" Click="SetVisibilityDebugConsole" Width="200" Height="75"
|
||||
VerticalAlignment="Bottom" Margin="0 0 5 0" />
|
||||
<!-- <ui:Button Content="Take Photo" Click="StartTakePhotoProcess" Width="200" Height="75" VerticalAlignment="Bottom" -->
|
||||
<!-- Margin="0 0 5 0" /> -->
|
||||
<Button Width="160" Height="160"
|
||||
Click="StartTakePhotoProcess"
|
||||
Content="PUSH ME"
|
||||
FontSize="64"
|
||||
Foreground="White"
|
||||
Margin="0 0 5 0"
|
||||
@ -71,12 +70,77 @@
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Style="{StaticResource ModernRounded3DButtonStyle}"/>
|
||||
|
||||
<ui:Button Content="Pictures" Click="SetVisibilityPicturePanel" Width="200" Height="75"
|
||||
VerticalAlignment="Bottom" Margin="0 0 5 0" />
|
||||
<ui:Button x:Name="DebugCloseButton" Content="Close" Appearance="Danger" Click="CloseApp" Width="200" Height="75" VerticalAlignment="Bottom" Margin="0 0 5 0" />
|
||||
</StackPanel>
|
||||
|
||||
<!-- Picture Gallery Dock (bottom-right) -->
|
||||
<Grid Grid.Row="0"
|
||||
x:Name="PictureGalleryDock"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="20"
|
||||
Panel.ZIndex="3"
|
||||
Visibility="Hidden">
|
||||
<ui:Button Content=""
|
||||
FontFamily="Segoe MDL2 Assets"
|
||||
FontSize="30"
|
||||
Width="72"
|
||||
Height="72"
|
||||
Click="SetVisibilityPicturePanel"
|
||||
Background="#D4AF37"
|
||||
Foreground="#1F1A00"
|
||||
BorderBrush="#F6E7A1"
|
||||
BorderThickness="2" />
|
||||
<!-- Badge for new photos -->
|
||||
<Border x:Name="NewPhotosBadge"
|
||||
Background="#E61A1A1A"
|
||||
BorderBrush="#FF0000"
|
||||
BorderThickness="2"
|
||||
CornerRadius="12"
|
||||
Width="36"
|
||||
Height="36"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,-8,-8,0"
|
||||
Visibility="Collapsed"
|
||||
Panel.ZIndex="1">
|
||||
<TextBlock x:Name="NewPhotoCountText"
|
||||
Text="1"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- Gallery Prompt -->
|
||||
<Border Grid.Row="0"
|
||||
x:Name="GalleryPrompt"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="20"
|
||||
Padding="16"
|
||||
Background="#E61A1A1A"
|
||||
BorderBrush="#66FFFFFF"
|
||||
BorderThickness="1"
|
||||
CornerRadius="12"
|
||||
Panel.ZIndex="4"
|
||||
Visibility="Collapsed">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<TextBlock Text="Foto gespeichert"
|
||||
Foreground="White"
|
||||
FontSize="24"
|
||||
FontWeight="SemiBold"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0 0 12 0" />
|
||||
<ui:Button Content="Jetzt in Galerie ansehen"
|
||||
Click="OpenGalleryFromPrompt"
|
||||
Width="240"
|
||||
Height="52" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- Shutdown Slider (bottom-left) -->
|
||||
<Grid Grid.Row="0"
|
||||
x:Name="ShutdownDock"
|
||||
@ -149,17 +213,20 @@
|
||||
TextAlignment="Center"
|
||||
TextWrapping="Wrap"
|
||||
Margin="0 0 0 16"/>
|
||||
<TextBlock Text="Viel Spaß mit der CamBooth!"
|
||||
Foreground="#FFFFD280"
|
||||
FontSize="34"
|
||||
FontWeight="SemiBold"
|
||||
<ui:Button Click="StartExperience"
|
||||
Width="480"
|
||||
Height="100"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="#1F1A00"
|
||||
Background="#FFFFD280"
|
||||
Margin="0 12 0 0">
|
||||
<TextBlock Text="Party starten"
|
||||
FontSize="52"
|
||||
FontWeight="Bold"
|
||||
TextAlignment="Center"
|
||||
Margin="0 0 0 36"/>
|
||||
<ui:Button Content="Start"
|
||||
Click="StartExperience"
|
||||
Width="240"
|
||||
Height="80"
|
||||
HorizontalAlignment="Center"/>
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
</ui:Button>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@ -47,6 +47,8 @@ public partial class MainWindow : Window
|
||||
|
||||
private readonly DispatcherTimer _focusStatusAnimationTimer = new() { Interval = TimeSpan.FromMilliseconds(250) };
|
||||
|
||||
private readonly DispatcherTimer _galleryPromptTimer = new() { Interval = TimeSpan.FromSeconds(5) };
|
||||
|
||||
private int _focusStatusDots;
|
||||
|
||||
|
||||
@ -71,11 +73,14 @@ public partial class MainWindow : Window
|
||||
this._focusStatusDots = (this._focusStatusDots + 1) % 4;
|
||||
this.CaptureStatusText.Text = $"Scharfstellen{new string('.', this._focusStatusDots)}";
|
||||
};
|
||||
#if DEBUG
|
||||
this.DebugCloseButton.Visibility = Visibility.Visible;
|
||||
#else
|
||||
this._galleryPromptTimer.Tick += (_, _) => this.HideGalleryPrompt();
|
||||
|
||||
// Subscribe to new photo count changes
|
||||
this._pictureGalleryService.NewPhotoCountChanged += PictureGalleryService_NewPhotoCountChanged;
|
||||
|
||||
this.DebugCloseButton.Visibility = Visibility.Collapsed;
|
||||
#endif
|
||||
this.HideDebugButton.Visibility = this._appSettings.IsDebugConsoleVisible ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
logger.Info($"config file loaded: '{appSettings.ConfigFileName}'");
|
||||
logger.Info("MainWindow initialized");
|
||||
}
|
||||
@ -83,9 +88,12 @@ public partial class MainWindow : Window
|
||||
|
||||
private void TimerControlRectangleAnimation_OnTimerEllapsed()
|
||||
{
|
||||
var photoTakenSuccessfully = false;
|
||||
|
||||
try
|
||||
{
|
||||
this._cameraService.TakePhoto();
|
||||
photoTakenSuccessfully = true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@ -99,6 +107,10 @@ public partial class MainWindow : Window
|
||||
this.CaptureStatusText.Visibility = Visibility.Collapsed;
|
||||
SwitchButtonAndTimerPanel();
|
||||
this._isPhotoProcessRunning = false;
|
||||
if (photoTakenSuccessfully)
|
||||
{
|
||||
this.ShowGalleryPrompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +119,10 @@ public partial class MainWindow : Window
|
||||
{
|
||||
if (visibility)
|
||||
{
|
||||
this.HideGalleryPrompt();
|
||||
this.PicturePanel.Navigate(new PictureGalleryPage(this._appSettings, this._logger, this._pictureGalleryService));
|
||||
// Reset new photo count when opening gallery
|
||||
this._pictureGalleryService.ResetNewPhotoCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -118,6 +133,22 @@ public partial class MainWindow : Window
|
||||
}
|
||||
|
||||
|
||||
private void ClosePicturePanel()
|
||||
{
|
||||
if (this.PicturePanel.Content is PictureGalleryPage pictureGalleryPage)
|
||||
{
|
||||
pictureGalleryPage.CloseOpenDialog();
|
||||
}
|
||||
|
||||
if (this.PicturePanel.Content is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.SetVisibilityPicturePanel(false);
|
||||
}
|
||||
|
||||
|
||||
private void OnClosing(object? sender, CancelEventArgs e)
|
||||
{
|
||||
this._liveViewPage?.Dispose();
|
||||
@ -129,6 +160,7 @@ public partial class MainWindow : Window
|
||||
this.StartLiveViewIfNeeded();
|
||||
this.WelcomeOverlay.Visibility = Visibility.Collapsed;
|
||||
this.ButtonPanel.Visibility = Visibility.Visible;
|
||||
this.PictureGalleryDock.Visibility = Visibility.Visible;
|
||||
this.ShutdownDock.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
@ -173,6 +205,9 @@ public partial class MainWindow : Window
|
||||
|
||||
private async void StartTakePhotoProcess(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.HideGalleryPrompt();
|
||||
this.ClosePicturePanel();
|
||||
|
||||
if (this._isPhotoProcessRunning)
|
||||
{
|
||||
return;
|
||||
@ -184,33 +219,18 @@ public partial class MainWindow : Window
|
||||
{
|
||||
SwitchButtonAndTimerPanel();
|
||||
|
||||
#if DEBUG
|
||||
TimerControlRectangleAnimation.StartTimer(2);
|
||||
TimerControlRectangleAnimation.StartTimer(this._appSettings.PhotoCountdownSeconds);
|
||||
this.StartFocusStatusAnimation();
|
||||
this.CaptureStatusText.Visibility = Visibility.Visible;
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
await Task.Delay(TimeSpan.FromSeconds(this._appSettings.FocusDelaySeconds));
|
||||
if (!this._isPhotoProcessRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await this._cameraService.PrepareFocusAsync(focusTimeoutMs: 1000);
|
||||
await this._cameraService.PrepareFocusAsync(focusTimeoutMs: this._appSettings.FocusTimeoutMs);
|
||||
this.StopFocusStatusAnimation();
|
||||
this.CaptureStatusText.Visibility = Visibility.Collapsed;
|
||||
#else
|
||||
TimerControlRectangleAnimation.StartTimer(5);
|
||||
this.StartFocusStatusAnimation();
|
||||
this.CaptureStatusText.Visibility = Visibility.Visible;
|
||||
await Task.Delay(TimeSpan.FromSeconds(2));
|
||||
if (!this._isPhotoProcessRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await this._cameraService.PrepareFocusAsync(focusTimeoutMs: 3000);
|
||||
this.StopFocusStatusAnimation();
|
||||
this.CaptureStatusText.Visibility = Visibility.Collapsed;
|
||||
#endif
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@ -228,6 +248,7 @@ public partial class MainWindow : Window
|
||||
private void SwitchButtonAndTimerPanel()
|
||||
{
|
||||
this.ButtonPanel.Visibility = this.ButtonPanel.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden;
|
||||
this.PictureGalleryDock.Visibility = this.PictureGalleryDock.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden;
|
||||
this.TimerPanel.Visibility = this.TimerPanel.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden;
|
||||
}
|
||||
|
||||
@ -243,6 +264,8 @@ public partial class MainWindow : Window
|
||||
}
|
||||
|
||||
private void ShutdownWindows(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (this._appSettings.IsShutdownEnabled)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -261,6 +284,9 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void ToggleShutdownSlider(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this._isShutdownSliderOpen = !this._isShutdownSliderOpen;
|
||||
@ -292,4 +318,36 @@ public partial class MainWindow : Window
|
||||
this._focusStatusAnimationTimer.Stop();
|
||||
this._focusStatusDots = 0;
|
||||
}
|
||||
|
||||
private void ShowGalleryPrompt()
|
||||
{
|
||||
this.GalleryPrompt.Visibility = Visibility.Visible;
|
||||
this._galleryPromptTimer.Stop();
|
||||
this._galleryPromptTimer.Start();
|
||||
}
|
||||
|
||||
private void HideGalleryPrompt()
|
||||
{
|
||||
this._galleryPromptTimer.Stop();
|
||||
this.GalleryPrompt.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void OpenGalleryFromPrompt(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.HideGalleryPrompt();
|
||||
this.SetVisibilityPicturePanel(true);
|
||||
}
|
||||
|
||||
private void PictureGalleryService_NewPhotoCountChanged(object? sender, int newPhotoCount)
|
||||
{
|
||||
if (newPhotoCount > 0)
|
||||
{
|
||||
this.NewPhotosBadge.Visibility = Visibility.Visible;
|
||||
this.NewPhotoCountText.Text = newPhotoCount.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.NewPhotosBadge.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -146,7 +146,14 @@ namespace EDSDKLib.API.Base
|
||||
/// <exception cref="ArgumentNullException">The DownloadInfo is null</exception>
|
||||
public void DownloadFile(IDownloadInfo Info, string directory)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(directory, Info.FileName), File.ReadAllBytes(this.mockImageFiles[new Random().Next(1, this.mockImageFiles.Count)].FullName));
|
||||
if (this.mockImageFiles.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No mock images available");
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
int randomIndex = random.Next(0, this.mockImageFiles.Count);
|
||||
File.WriteAllBytes(Path.Combine(directory, Info.FileName), File.ReadAllBytes(this.mockImageFiles[randomIndex].FullName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -200,7 +207,7 @@ namespace EDSDKLib.API.Base
|
||||
|
||||
this.DownloadReady?.Invoke(this, new DownloadInfoMock()
|
||||
{
|
||||
FileName = $"{mockImageFiles[random.Next(1, 99)].FullName}"
|
||||
FileName = $"MockPhoto_{Guid.NewGuid().ToString()}.jpg"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user