Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Copyright (c) 2025, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
Expand Down Expand Up @@ -30,7 +30,13 @@ public class DatabaseController : ControllerBase
{
private readonly IDbContextManager _dbContextManager;
private readonly IDatabaseConfigUpdateService _databaseUpdateService;
private readonly string _dataDirectory = @".\Backups\";
private static readonly string DataDirectory;

static DatabaseController()
{
var executingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
DataDirectory = Path.Combine(executingDirectory!, "Backups");
}

public DatabaseController(IDbContextManager dbContextManager)
{
Expand Down Expand Up @@ -183,7 +189,7 @@ public ActionResult<InvocationResponse> DumpDatabase(string targetModel, Databas
return BadConfigValues();


var targetPath = Path.Combine(_dataDirectory, targetModel);
var targetPath = Path.Combine(DataDirectory, targetModel);
if (!Directory.Exists(targetPath))
Directory.CreateDirectory(targetPath);

Expand All @@ -204,7 +210,7 @@ public ActionResult<InvocationResponse> RestoreDatabase(string targetModel, Rest
if (!IsConfigValid(updatedConfig))
return BadConfigValues();

var filePath = Path.Combine(_dataDirectory, targetModel, request.BackupFileName);
var filePath = Path.Combine(DataDirectory, targetModel, request.BackupFileName);
targetConfigurator.RestoreDatabase(updatedConfig, filePath);

return new InvocationResponse();
Expand Down Expand Up @@ -355,7 +361,7 @@ private IEnumerable<SetupModel> GetAllSetups(Type contextType)
var setups = allSetups.Where(setup => string.IsNullOrEmpty(setup.SupportedFileRegex))
.Select(ConvertSetup).OrderBy(setup => setup.SortOrder).ToList();
string[] files;
if (!Directory.Exists(_dataDirectory) || !(files = Directory.GetFiles(_dataDirectory)).Any())
if (!Directory.Exists(DataDirectory) || !(files = Directory.GetFiles(DataDirectory)).Any())
return setups.ToArray();

var fileSetups = allSetups.Where(setup => !string.IsNullOrEmpty(setup.SupportedFileRegex))
Expand All @@ -372,7 +378,7 @@ private IEnumerable<SetupModel> GetAllSetups(Type contextType)
private IEnumerable<BackupModel> GetAllBackups(Type contextType)
{
var targetModel = TargetModelName(contextType);
var backupFolder = Path.Combine(_dataDirectory, targetModel);
var backupFolder = Path.Combine(DataDirectory, targetModel);

if (!Directory.Exists(backupFolder))
return Array.Empty<BackupModel>();
Expand Down
Loading