This commit is contained in:
2020-08-21 21:41:01 +00:00
parent 20286478de
commit 2bde80e488
12 changed files with 130 additions and 30 deletions

View File

@@ -33,24 +33,33 @@ namespace AyaNova.Util
//UserFiles
if (string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_FOLDER_USER_FILES))
{
ServerBootConfig.AYANOVA_FOLDER_USER_FILES = Path.Combine(contentRootPath, "userfiles");
}
//BackupFiles
if (ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES == null)
{
ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES = Path.Combine(contentRootPath, "backupfiles");
}
//Temporary system files (reports etc)
if (ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES == null)
ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES = Path.Combine(contentRootPath, "tempfiles");
//Prevent using the same folder for both
if (string.Equals(Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_USER_FILES), Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES), StringComparison.OrdinalIgnoreCase))
if (
string.Equals(Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_USER_FILES), Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES), StringComparison.OrdinalIgnoreCase) ||
string.Equals(Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_USER_FILES), Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES), StringComparison.OrdinalIgnoreCase) ||
string.Equals(Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES), Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES), StringComparison.OrdinalIgnoreCase)
)
{
throw new System.NotSupportedException("E1040: The configuration settings AYANOVA_FOLDER_USER_FILES and the AYANOVA_FOLDER_BACKUP_FILES must not point to the exact same location");
throw new System.NotSupportedException("E1040: The configuration settings AYANOVA_FOLDER_USER_FILES, AYANOVA_FOLDER_BACKUP_FILES and AYANOVA_FOLDER_TEMPORARY_SYSTEM_FILES must all be different locations");
}
EnsurePath(ServerBootConfig.AYANOVA_FOLDER_USER_FILES);
EnsurePath(ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES);
EnsurePath(ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES);
}
//create path if doesn't exist already
@@ -61,6 +70,35 @@ namespace AyaNova.Util
}
#endregion folder ensurance
#region Temporary files handling
/// <summary>
/// Get backup file folder
/// </summary>
/// <returns></returns>
internal static string TemporaryFilesFolder
{
get
{
return ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES;
}
}
/// <summary>
/// Get a random file name with path to temporary files folder
/// </summary>
/// <returns></returns>
internal static string NewRandomTempFilesFolderFileName
{
get
{
return Path.Combine(TemporaryFilesFolder, NewRandomFileName);
}
}
#endregion
#region Utility (BACKUP) file handling
@@ -315,17 +353,7 @@ namespace AyaNova.Util
}
/// <summary>
/// Get a random file name
/// </summary>
/// <returns></returns>
internal static string NewRandomFileName
{
get
{
return Path.GetRandomFileName();
}
}
/// <summary>
/// Get a random file name with path to attachments folder
@@ -569,6 +597,18 @@ namespace AyaNova.Util
#region General utilities
/// <summary>
/// Get a random file name
/// </summary>
/// <returns></returns>
internal static string NewRandomFileName
{
get
{
return Path.GetRandomFileName();
}
}
//https://stackoverflow.com/a/11124118/8939
// Returns the human-readable file size for an arbitrary, 64-bit file size
// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB"

View File

@@ -46,6 +46,7 @@ namespace AyaNova.Util
//FILE FOLDERS
internal static string AYANOVA_FOLDER_USER_FILES { get; set; }
internal static string AYANOVA_FOLDER_BACKUP_FILES { get; set; }
internal static string AYANOVA_FOLDER_TEMPORARY_SERVER_FILES { get; set; }
//BACKUP PG_DUMP PATH (IF NOT IN PATH ALREADY)
internal static string AYANOVA_BACKUP_PG_DUMP_PATH { get; set; }
@@ -159,6 +160,9 @@ namespace AyaNova.Util
//BackupFiles
AYANOVA_FOLDER_BACKUP_FILES = config.GetValue<string>("AYANOVA_FOLDER_BACKUP_FILES");
//TemporaryFiles
AYANOVA_FOLDER_TEMPORARY_SERVER_FILES = config.GetValue<string>("AYANOVA_FOLDER_TEMPORARY_SERVER_FILES");
//pgdump backup utility path
AYANOVA_BACKUP_PG_DUMP_PATH = config.GetValue<string>("AYANOVA_BACKUP_PG_DUMP_PATH");