1 Commits

Author SHA1 Message Date
0ed9beb69a - fix antipattern 2026-02-12 14:50:38 +01:00
6 changed files with 84 additions and 7 deletions

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.IO;
using LeanderShiftPlannerV2.Util;
namespace LeanderShiftPlannerV2.FileIO;
public static class GoogleApiLoader
{
public static bool CheckFileSystem()
{
if (!Directory.Exists(Constants.DataPath))
Directory.CreateDirectory(Constants.DataPath);
if (!File.Exists(Constants.DataPath + Constants.GoogleApiFilePath))
{
File.Create(Constants.DataPath + Constants.GoogleApiFilePath).Close();
File.WriteAllLines(Constants.DataPath + Constants.GoogleApiFilePath,
File.ReadAllLines(Constants.GoogleApiFileResource));
return false;
}
return true;
}
public static Dictionary<string, string> ReadFile()
{
if (!CheckFileSystem()) return new Dictionary<string, string>();
Dictionary<string, string> apiSecrets = new Dictionary<string, string>();
try
{
string[] lines = File.ReadAllLines(Constants.DataPath + Constants.GoogleApiFilePath);
foreach (string line in lines)
{
string[] parts = line.Split(new[] { '=' }, 2);
if (parts.Length == 2)
{
string pattern = parts[0].Trim();
string value = parts[1].Trim();
if (!string.IsNullOrEmpty(pattern))
{
apiSecrets[pattern] = value;
}
}
}
}
catch (Exception ex)
{
//TODO
Console.WriteLine($"Fehler beim Lesen der Datei: {ex.Message}");
}
return apiSecrets;
}
}

View File

@@ -8,10 +8,10 @@
<ApplicationIcon>Resources/icon/ShiftPlannerIcon.ico</ApplicationIcon> <ApplicationIcon>Resources/icon/ShiftPlannerIcon.ico</ApplicationIcon>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault> <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<PackageIcon>Resources\icon\ShiftPlannerIcon.png</PackageIcon> <PackageIcon>Resources\icon\ShiftPlannerIcon.png</PackageIcon>
<AssemblyVersion>1.0.4</AssemblyVersion> <AssemblyVersion>1.0.5</AssemblyVersion>
<FileVersion>1.0.4</FileVersion> <FileVersion>1.0.5</FileVersion>
<NeutralLanguage>en</NeutralLanguage> <NeutralLanguage>en</NeutralLanguage>
<Version>1.0.1</Version> <Version>1.0.5</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -42,6 +42,9 @@
<EmbeddedResource Include="Resources\templates\timesheet.xlsx"> <EmbeddedResource Include="Resources\templates\timesheet.xlsx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Resources\templates\googleapi.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -0,0 +1,2 @@
GoogleClientId=
GoogleClientSecret=

View File

@@ -12,6 +12,7 @@ using LeanderShiftPlannerV2.Util;
using Google.Apis.Auth.OAuth2; using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3; using Google.Apis.Calendar.v3;
using Google.Apis.Services; using Google.Apis.Services;
using LeanderShiftPlannerV2.FileIO;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace LeanderShiftPlannerV2.Service; namespace LeanderShiftPlannerV2.Service;
@@ -21,8 +22,6 @@ public class TimesheetService
private readonly AppService _appService; private readonly AppService _appService;
private const string HolidayApiUriPart1 = "https://feiertage-api.de/api/?jahr="; private const string HolidayApiUriPart1 = "https://feiertage-api.de/api/?jahr=";
private const string HolidayApiUriPart2 = "&nur_land="; private const string HolidayApiUriPart2 = "&nur_land=";
private const string GoogleClientId = "823920428427-ub5n9a9dkfpuvjlut4eneg2058so49o3.apps.googleusercontent.com";
private const string GoogleClientSecret = "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";
public TimesheetService(AppService appService) public TimesheetService(AppService appService)
{ {
@@ -34,9 +33,18 @@ public class TimesheetService
string[] scopes = { CalendarService.Scope.CalendarReadonly }; string[] scopes = { CalendarService.Scope.CalendarReadonly };
const string applicationName = "LeanderShiftPlanner"; const string applicationName = "LeanderShiftPlanner";
Dictionary<string, string> secrets = GoogleApiLoader.ReadFile();
if (!secrets.ContainsKey(Constants.GoogleClientId) || !secrets.ContainsKey(Constants.GoogleClientSecret))
return;
if (secrets[Constants.GoogleClientId].Equals(string.Empty) || secrets[Constants.GoogleClientSecret].Equals(string.Empty))
return;
ClientSecrets clientSecrets = new ClientSecrets(); ClientSecrets clientSecrets = new ClientSecrets();
clientSecrets.ClientId = GoogleClientId; clientSecrets.ClientId = secrets[Constants.GoogleClientId];
clientSecrets.ClientSecret = GoogleClientSecret; clientSecrets.ClientSecret = secrets[Constants.GoogleClientSecret];
//clientSecrets.ClientId = "823920428427-ub5n9a9dkfpuvjlut4eneg2058so49o3.apps.googleusercontent.com";
//clientSecrets.ClientSecret = "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";
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(clientSecrets, scopes, "user", CancellationToken.None); UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(clientSecrets, scopes, "user", CancellationToken.None);
// Erstelle den CalendarService // Erstelle den CalendarService

View File

@@ -17,6 +17,10 @@ namespace LeanderShiftPlannerV2.Util
public const string FontPath = @"Resources/font/"; public const string FontPath = @"Resources/font/";
public const string FontEmblem = "Emblem.ttf"; public const string FontEmblem = "Emblem.ttf";
public const string FontRoboto = "Roboto.ttf"; public const string FontRoboto = "Roboto.ttf";
public const string GoogleApiFilePath = @"/googleapi.txt";
public const string GoogleClientId = "GoogleClientId";
public const string GoogleClientSecret = "GoogleClientSecret";
public const string GoogleApiFileResource = @"Resources/templates/googleapi.txt";
// TimeSheets // TimeSheets
public static readonly string TimeSheetSourceRandom = "Random"; public static readonly string TimeSheetSourceRandom = "Random";

View File

@@ -31,6 +31,7 @@ public partial class LeanderShiftPlannerMainWindow : Window
InitializeComponent(); InitializeComponent();
LoadData(); LoadData();
CreateApiFile();
DeactivateView(); DeactivateView();
ViewModePersons(); ViewModePersons();
@@ -44,6 +45,11 @@ public partial class LeanderShiftPlannerMainWindow : Window
_appService.FilterService.Filters.CollectionChanged += FilterListChanged; _appService.FilterService.Filters.CollectionChanged += FilterListChanged;
} }
private void CreateApiFile()
{
GoogleApiLoader.CheckFileSystem();
}
// ------------------------------------------------------UI-Interactions------------------------------------------------------ // ------------------------------------------------------UI-Interactions------------------------------------------------------
private void ButtonAddPerson_Click(object? sender, RoutedEventArgs e) private void ButtonAddPerson_Click(object? sender, RoutedEventArgs e)