feat: Add GitRepoRegistration cmdlets #5
2 changed files with 36 additions and 0 deletions
feat(git-provider): Initial DatabaseManager
commit
caa65ca7c3
33
src/ModuleCore/Database/DatabaseManager.cs
Normal file
33
src/ModuleCore/Database/DatabaseManager.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
namespace ModuleCore.Database;
|
||||
|
||||
public class DatabaseManager
|
||||
{
|
||||
private readonly FileInfo _databaseLocation;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new manager for the given database file by name
|
||||
/// </summary>
|
||||
/// <param name="databaseName">
|
||||
/// Filename for the database with no extension. Slashes are accepted and will create directories as needed.
|
||||
/// </param>
|
||||
public DatabaseManager(string databaseName)
|
||||
{
|
||||
// Even though the xmldoc says "with no extension", we strip off any extension regardless
|
||||
_databaseLocation = new FileInfo(Path.Combine(".", "data", $"{SanitiseFilename(databaseName)}.db"));
|
||||
|
||||
Directory.CreateDirectory(_databaseLocation.DirectoryName!);
|
||||
var file = File.Create(_databaseLocation.FullName);
|
||||
file.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes double dots from the filename and removes the file extension
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
private string SanitiseFilename(string filename)
|
||||
{
|
||||
// Honestly not really needed seeing as its just me and this isn't coming from user supplied code, but eh.
|
||||
return Path.GetFileNameWithoutExtension(filename.Replace("..", string.Empty));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using ModuleCore.Database;
|
||||
using ModuleCore.Git.Models;
|
||||
|
||||
namespace ModuleCore.Git;
|
||||
|
|
@ -9,12 +10,14 @@ public class GitManager
|
|||
{
|
||||
private static readonly Lazy<GitManager> GitManagerInstance = new(() => new GitManager());
|
||||
private readonly ConcurrentDictionary<string, InternalGitRegistration> _registrations;
|
||||
private readonly DatabaseManager _db;
|
||||
|
||||
private GitManager()
|
||||
{
|
||||
Debug.WriteLine($"{nameof(GitManager)} init");
|
||||
|
||||
_registrations = new ConcurrentDictionary<string, InternalGitRegistration>();
|
||||
_db = new DatabaseManager("git.db");
|
||||
}
|
||||
|
||||
public static GitManager Instance => GitManagerInstance.Value;
|
||||
|
|
|
|||
Loading…
Reference in a new issue