Struktur refactured, jetzt ist MVCP sehr gut erfüllt

This commit is contained in:
OliverT87 2025-06-24 15:05:44 +02:00
parent 8b1d995b0b
commit 78ca5f49c6
7 changed files with 470 additions and 16 deletions

View File

@ -24,19 +24,19 @@ namespace Project_Periodensystem.Controller
}
/// <summary>
/// Lädt alle Elemente über den Persistence-Layer
/// Lädt alle Elemente über den Persistence-Layer (JETZT MIT DATAMANAGER!)
/// </summary>
private void LoadElements()
{
try
{
// Verwende die korrekte statische Methode aus PeriodicTableData
_elements = PeriodicTableData.Elements.ToList();
Logger.Log($"Controller: {_elements.Count} Elemente erfolgreich geladen");
// NEUE METHODE: DataManager statt direkt PeriodicTableData
_elements = DataManager.LoadElements();
Logger.Log($"Controller: {_elements.Count} Elemente erfolgreich geladen (via DataManager)");
}
catch (Exception ex)
{
Logger.Log($"EXCEPTION in LoadElements: {ex.Message}");
Logger.LogException(ex, "LoadElements");
_elements = new List<Element>();
}
}
@ -50,6 +50,22 @@ namespace Project_Periodensystem.Controller
return _elements;
}
/// <summary>
/// Speichert Elemente persistent (NEUE FUNKTION)
/// </summary>
public void SaveElements()
{
try
{
DataManager.SaveElements(_elements);
Logger.Log("Elemente erfolgreich gespeichert");
}
catch (Exception ex)
{
Logger.LogException(ex, "SaveElements");
}
}
/// <summary>
/// Sucht ein Element nach Atomnummer
/// </summary>

View File

@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using Project_Periodensystem.Model;
namespace Project_Periodensystem.Persistence
{
/// <summary>
/// Erweiterte Persistenz - Speichern/Laden von JSON-Dateien
/// </summary>
public static class DataManager
{
private static readonly string DataDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Periodensystem");
private static readonly string ElementsFile = Path.Combine(DataDirectory, "elements.json");
private static readonly string SettingsFile = Path.Combine(DataDirectory, "settings.json");
/// <summary>
/// Speichert Elemente als JSON
/// </summary>
public static void SaveElements(List<Element> elements)
{
try
{
Directory.CreateDirectory(DataDirectory);
var json = JsonSerializer.Serialize(elements, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(ElementsFile, json);
Logger.Log($"Elemente gespeichert: {elements.Count} Einträge");
}
catch (Exception ex)
{
Logger.LogException(ex, "SaveElements");
}
}
/// <summary>
/// Lädt Elemente aus JSON oder Fallback zu eingebauten Daten
/// </summary>
public static List<Element> LoadElements()
{
try
{
if (File.Exists(ElementsFile))
{
var json = File.ReadAllText(ElementsFile);
var elements = JsonSerializer.Deserialize<List<Element>>(json);
if (elements != null && elements.Count > 0)
{
Logger.Log($"Elemente aus Datei geladen: {elements.Count}");
return elements;
}
}
}
catch (Exception ex)
{
Logger.LogException(ex, "LoadElements");
}
// Fallback zu eingebauten Daten
Logger.Log("Fallback zu eingebauten Element-Daten");
return PeriodicTableData.Elements;
}
/// <summary>
/// Speichert Benutzereinstellungen
/// </summary>
public static void SaveSettings(AppSettings settings)
{
try
{
Directory.CreateDirectory(DataDirectory);
var json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(SettingsFile, json);
}
catch (Exception ex)
{
Logger.LogException(ex, "SaveSettings");
}
}
/// <summary>
/// Lädt Benutzereinstellungen
/// </summary>
public static AppSettings LoadSettings()
{
try
{
if (File.Exists(SettingsFile))
{
var json = File.ReadAllText(SettingsFile);
var settings = JsonSerializer.Deserialize<AppSettings>(json);
return settings ?? new AppSettings();
}
}
catch (Exception ex)
{
Logger.LogException(ex, "LoadSettings");
}
return new AppSettings();
}
}
/// <summary>
/// Benutzereinstellungen für Persistenz
/// </summary>
public class AppSettings
{
public string LastTheme { get; set; } = "Dark";
public DateTime LastUsed { get; set; } = DateTime.Now;
public string PreferredLanguage { get; set; } = "German";
}
}

View File

@ -1,7 +1,9 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Project_Periodensystem.Model;
using Project_Periodensystem.Persistence;
namespace Project_Periodensystem.View
{
@ -16,14 +18,51 @@ namespace Project_Periodensystem.View
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
// Standard Dark Theme beim Start
RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Dark;
// Settings laden und Theme setzen
var settings = DataManager.LoadSettings();
// Theme aus Settings setzen
if (settings.LastTheme == "Light")
{
RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Light;
}
else
{
RequestedThemeVariant = Avalonia.Styling.ThemeVariant.Dark;
}
desktop.MainWindow = new MainWindow();
Logger.Log("Application initialized with Dark theme");
Logger.Log($"Application initialized with {settings.LastTheme} theme from settings");
// Settings beim Beenden speichern
desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnMainWindowClose;
desktop.Exit += OnApplicationExit;
}
base.OnFrameworkInitializationCompleted();
}
/// <summary>
/// Speichert Settings beim Beenden der App
/// </summary>
private void OnApplicationExit(object? sender, ControlledApplicationLifetimeExitEventArgs e)
{
try
{
var settings = new AppSettings
{
LastTheme = RequestedThemeVariant?.ToString() ?? "Dark",
LastUsed = DateTime.Now,
PreferredLanguage = "German"
};
DataManager.SaveSettings(settings);
Logger.Log("Settings beim App-Exit gespeichert");
}
catch (Exception ex)
{
Logger.Log($"EXCEPTION in OnApplicationExit: {ex.Message}");
}
}
}
}

View File

@ -1,7 +1,9 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Project_Periodensystem.Model;
using Project_Periodensystem.Persistence;
namespace Project_Periodensystem.View
{
@ -33,7 +35,7 @@ namespace Project_Periodensystem.View
Logger.Log("Navigation zum Periodensystem");
}
}
catch (System.Exception ex)
catch (Exception ex)
{
Logger.Log($"Fehler bei Navigation zum Periodensystem: {ex.Message}");
}
@ -54,14 +56,14 @@ namespace Project_Periodensystem.View
Logger.Log("Navigation zur About-Seite");
}
}
catch (System.Exception ex)
catch (Exception ex)
{
Logger.Log($"Fehler bei Navigation zu About: {ex.Message}");
}
}
/// <summary>
/// Event-Handler für Theme-Button
/// Event-Handler für Theme-Button (MIT SETTINGS-SPEICHERUNG)
/// </summary>
private void ThemeButton_Click(object? sender, RoutedEventArgs e)
{
@ -81,15 +83,22 @@ namespace Project_Periodensystem.View
app.RequestedThemeVariant = newTheme;
Logger.Log($"Theme gewechselt zu: {newTheme}");
// NEUE FUNKTION: Theme-Einstellung speichern
var settings = DataManager.LoadSettings();
settings.LastTheme = newTheme.ToString();
settings.LastUsed = DateTime.Now;
DataManager.SaveSettings(settings);
Logger.Log("Theme-Einstellung gespeichert");
}
else
{
Logger.Log("Application.Current ist null!");
}
}
catch (System.Exception ex)
catch (Exception ex)
{
Logger.Log($"Fehler beim Theme-Wechsel: {ex.Message}");
Logger.Log($"EXCEPTION in ThemeButton_Click: {ex.Message}");
}
}
}

View File

@ -1,13 +1,14 @@
using System;
using System.Globalization;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Project_Periodensystem.Controller;
using Project_Periodensystem.Model;
using Project_Periodensystem.Persistence;
using Project_Periodensystem.View.Converters;
using System;
using System.Globalization;
using System.Linq;
namespace Project_Periodensystem.View
{
@ -218,5 +219,25 @@ namespace Project_Periodensystem.View
Logger.Log($"Fehler bei Navigation zurück: {ex.Message}");
}
}
/// <summary>
/// Export-Button für Element-Daten (NEUE FUNKTION)
/// </summary>
private void ExportButton_Click(object? sender, RoutedEventArgs e)
{
try
{
var elements = _controller.GetAllElements();
DataManager.SaveElements(elements);
Logger.Log($"Export: {elements.Count} Elemente als JSON gespeichert");
// Optional: Benutzer-Feedback
// ShowMessage("Daten erfolgreich exportiert!");
}
catch (Exception ex)
{
Logger.Log($"EXCEPTION in ExportButton_Click: {ex.Message}");
}
}
}
}

View File

@ -0,0 +1,253 @@
Auflistung der Ordnerpfade
Volumeseriennummer : 00C1-D40F
C:.
¦ AboutPage.axaml
¦ AboutPage.axaml.cs
¦ App.axaml
¦ App.axaml.cs
¦ app.manifest
¦ LandingPage.axaml
¦ LandingPage.axaml.cs
¦ logger.cs
¦ MainWindow.axaml
¦ MainWindow.axaml.cs
¦ PeriodicTablePage.axaml
¦ PeriodicTablePage.axaml.cs
¦ Program.cs
¦ Project_Periodensystem.View.csproj
¦ Project_Periodensystem.View.sln
¦ projektstruktur.txt
¦
+---bin
¦ +---Debug
¦ +---net8.0
¦ ¦ app_log.txt
¦ ¦ Avalonia.Base.dll
¦ ¦ Avalonia.Controls.ColorPicker.dll
¦ ¦ Avalonia.Controls.DataGrid.dll
¦ ¦ Avalonia.Controls.dll
¦ ¦ Avalonia.DesignerSupport.dll
¦ ¦ Avalonia.Desktop.dll
¦ ¦ Avalonia.Diagnostics.dll
¦ ¦ Avalonia.Dialogs.dll
¦ ¦ Avalonia.dll
¦ ¦ Avalonia.FreeDesktop.dll
¦ ¦ Avalonia.Markup.dll
¦ ¦ Avalonia.Markup.Xaml.dll
¦ ¦ Avalonia.Metal.dll
¦ ¦ Avalonia.MicroCom.dll
¦ ¦ Avalonia.Native.dll
¦ ¦ Avalonia.OpenGL.dll
¦ ¦ Avalonia.ReactiveUI.dll
¦ ¦ Avalonia.Remote.Protocol.dll
¦ ¦ Avalonia.Skia.dll
¦ ¦ Avalonia.Themes.Fluent.dll
¦ ¦ Avalonia.Themes.Simple.dll
¦ ¦ Avalonia.Win32.dll
¦ ¦ Avalonia.X11.dll
¦ ¦ DynamicData.dll
¦ ¦ HarfBuzzSharp.dll
¦ ¦ MicroCom.Runtime.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.dll
¦ ¦ Microsoft.CodeAnalysis.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.dll
¦ ¦ Microsoft.Win32.SystemEvents.dll
¦ ¦ Project_Periodensystem.Controller.dll
¦ ¦ Project_Periodensystem.Controller.pdb
¦ ¦ Project_Periodensystem.Model.dll
¦ ¦ Project_Periodensystem.Model.pdb
¦ ¦ Project_Periodensystem.Persistence.dll
¦ ¦ Project_Periodensystem.Persistence.pdb
¦ ¦ Project_Periodensystem.View.deps.json
¦ ¦ Project_Periodensystem.View.dll
¦ ¦ Project_Periodensystem.View.exe
¦ ¦ Project_Periodensystem.View.pdb
¦ ¦ Project_Periodensystem.View.runtimeconfig.json
¦ ¦ ReactiveUI.dll
¦ ¦ SkiaSharp.dll
¦ ¦ Splat.dll
¦ ¦ System.Drawing.Common.dll
¦ ¦ System.IO.Pipelines.dll
¦ ¦ System.Reactive.dll
¦ ¦ Tmds.DBus.Protocol.dll
¦ ¦
¦ +---cs
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---de
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---es
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---fr
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---it
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---ja
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---ko
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---pl
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---pt-BR
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---ru
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---runtimes
¦ ¦ +---linux-arm
¦ ¦ ¦ +---native
¦ ¦ ¦ libHarfBuzzSharp.so
¦ ¦ ¦ libSkiaSharp.so
¦ ¦ ¦
¦ ¦ +---linux-arm64
¦ ¦ ¦ +---native
¦ ¦ ¦ libHarfBuzzSharp.so
¦ ¦ ¦ libSkiaSharp.so
¦ ¦ ¦
¦ ¦ +---linux-musl-x64
¦ ¦ ¦ +---native
¦ ¦ ¦ libHarfBuzzSharp.so
¦ ¦ ¦ libSkiaSharp.so
¦ ¦ ¦
¦ ¦ +---linux-x64
¦ ¦ ¦ +---native
¦ ¦ ¦ libHarfBuzzSharp.so
¦ ¦ ¦ libSkiaSharp.so
¦ ¦ ¦
¦ ¦ +---osx
¦ ¦ ¦ +---native
¦ ¦ ¦ libAvaloniaNative.dylib
¦ ¦ ¦ libHarfBuzzSharp.dylib
¦ ¦ ¦ libSkiaSharp.dylib
¦ ¦ ¦
¦ ¦ +---unix
¦ ¦ ¦ +---lib
¦ ¦ ¦ +---net6.0
¦ ¦ ¦ System.Drawing.Common.dll
¦ ¦ ¦
¦ ¦ +---win
¦ ¦ ¦ +---lib
¦ ¦ ¦ +---net6.0
¦ ¦ ¦ Microsoft.Win32.SystemEvents.dll
¦ ¦ ¦ System.Drawing.Common.dll
¦ ¦ ¦
¦ ¦ +---win-arm64
¦ ¦ ¦ +---native
¦ ¦ ¦ av_libglesv2.dll
¦ ¦ ¦ libHarfBuzzSharp.dll
¦ ¦ ¦ libSkiaSharp.dll
¦ ¦ ¦
¦ ¦ +---win-x64
¦ ¦ ¦ +---native
¦ ¦ ¦ av_libglesv2.dll
¦ ¦ ¦ libHarfBuzzSharp.dll
¦ ¦ ¦ libSkiaSharp.dll
¦ ¦ ¦
¦ ¦ +---win-x86
¦ ¦ +---native
¦ ¦ av_libglesv2.dll
¦ ¦ libHarfBuzzSharp.dll
¦ ¦ libSkiaSharp.dll
¦ ¦
¦ +---tr
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---zh-Hans
¦ ¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ ¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ ¦ Microsoft.CodeAnalysis.resources.dll
¦ ¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦ ¦
¦ +---zh-Hant
¦ Microsoft.CodeAnalysis.CSharp.resources.dll
¦ Microsoft.CodeAnalysis.CSharp.Scripting.resources.dll
¦ Microsoft.CodeAnalysis.resources.dll
¦ Microsoft.CodeAnalysis.Scripting.resources.dll
¦
+---Components
¦ ElementTile.axaml
¦ ElementTile.axaml.cs
¦
+---Converters
¦ GridPositionConverters.cs
¦ SeriesToColorConverter.cs
¦
+---obj
¦ project.assets.json
¦ project.nuget.cache
¦ Project_Periodensystem.View.csproj.nuget.dgspec.json
¦ Project_Periodensystem.View.csproj.nuget.g.props
¦ Project_Periodensystem.View.csproj.nuget.g.targets
¦
+---Debug
+---net8.0
¦ .NETCoreApp,Version=v8.0.AssemblyAttributes.cs
¦ apphost.exe
¦ Project_.29B724C0.Up2Date
¦ Project_Periodensystem.View.AssemblyInfo.cs
¦ Project_Periodensystem.View.AssemblyInfoInputs.cache
¦ Project_Periodensystem.View.assets.cache
¦ Project_Periodensystem.View.csproj.AssemblyReference.cache
¦ Project_Periodensystem.View.csproj.CoreCompileInputs.cache
¦ Project_Periodensystem.View.csproj.FileListAbsolute.txt
¦ Project_Periodensystem.View.dll
¦ Project_Periodensystem.View.GeneratedMSBuildEditorConfig.editorconfig
¦ Project_Periodensystem.View.genruntimeconfig.cache
¦ Project_Periodensystem.View.pdb
¦
+---Avalonia
¦ original.dll
¦ original.pdb
¦ original.ref.dll
¦ references
¦ resources
¦ Resources.Inputs.cache
¦
+---ref
¦ Project_Periodensystem.View.dll
¦
+---refint
Project_Periodensystem.View.dll

Binary file not shown.