Started implementing backend
This commit is contained in:
@@ -17,4 +17,8 @@
|
|||||||
<EmbeddedResource Include="UI/AddShortcutWindow/AddShortcutWindow.xml" />
|
<EmbeddedResource Include="UI/AddShortcutWindow/AddShortcutWindow.xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../Logic/Logic.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Logic;
|
||||||
|
|
||||||
namespace Keychain;
|
namespace Keychain;
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ class Program
|
|||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
//services.AddTransient<IPasswordStoreService, PasswordStoreService>();
|
//services.AddTransient<IPasswordStoreService, PasswordStoreService>();
|
||||||
|
services.AddSingleton<IPasswordStoreService, PasswordStoreService>();
|
||||||
return services.BuildServiceProvider();
|
return services.BuildServiceProvider();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using Logic;
|
||||||
|
|
||||||
namespace Keychain.UI.ViewModels;
|
namespace Keychain.ViewModels;
|
||||||
|
|
||||||
public class PasswordStoreShortcut : INotifyPropertyChanged
|
public class PasswordStoreShortcut : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
private IPasswordService passwordService;
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
|
||||||
private string displayName;
|
private string displayName;
|
||||||
@@ -12,6 +14,7 @@ public class PasswordStoreShortcut : INotifyPropertyChanged
|
|||||||
private string path;
|
private string path;
|
||||||
public bool DisplayNameSet { get => displayNameSet; }
|
public bool DisplayNameSet { get => displayNameSet; }
|
||||||
|
|
||||||
|
|
||||||
public string DisplayName
|
public string DisplayName
|
||||||
{
|
{
|
||||||
get => displayName;
|
get => displayName;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Keychain.UI.ViewModels;
|
namespace Keychain.ViewModels;
|
||||||
|
|
||||||
using Adw;
|
using Adw;
|
||||||
using Gtk;
|
using Gtk;
|
||||||
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logic", "Logic\Logic.csproj
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Keychain", "App\Keychain.csproj", "{D4755A56-58E0-46A3-859B-49ACAA3EDAED}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Keychain", "App\Keychain.csproj", "{D4755A56-58E0-46A3-859B-49ACAA3EDAED}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repository", "Repository\Repository.csproj", "{AB25C193-3B52-46B4-BE6A-0B2E331BD2A8}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -27,6 +29,10 @@ Global
|
|||||||
{D4755A56-58E0-46A3-859B-49ACAA3EDAED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D4755A56-58E0-46A3-859B-49ACAA3EDAED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D4755A56-58E0-46A3-859B-49ACAA3EDAED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D4755A56-58E0-46A3-859B-49ACAA3EDAED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D4755A56-58E0-46A3-859B-49ACAA3EDAED}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D4755A56-58E0-46A3-859B-49ACAA3EDAED}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{AB25C193-3B52-46B4-BE6A-0B2E331BD2A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AB25C193-3B52-46B4-BE6A-0B2E331BD2A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AB25C193-3B52-46B4-BE6A-0B2E331BD2A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AB25C193-3B52-46B4-BE6A-0B2E331BD2A8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Logic;
|
|
||||||
|
|
||||||
public class Class1
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
14
Logic/IPasswordStoreService.cs
Normal file
14
Logic/IPasswordStoreService.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Models;
|
||||||
|
|
||||||
|
namespace Logic;
|
||||||
|
|
||||||
|
public interface IPasswordStoreService
|
||||||
|
{
|
||||||
|
IEnumerable<PasswordStore> GetAll();
|
||||||
|
PasswordStore Get(uint ID);
|
||||||
|
int Delete(uint ID);
|
||||||
|
int Delete(PasswordStore item);
|
||||||
|
int Create(string path, string? displayName = null, string? iconName = null);
|
||||||
|
int Create(PasswordStore item);
|
||||||
|
int Edit(uint ID, PasswordStore newItem);
|
||||||
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../Models/Models.csproj" />
|
||||||
|
<ProjectReference Include="../Repository/Repository.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
44
Logic/PasswordStoreService.cs
Normal file
44
Logic/PasswordStoreService.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using Models;
|
||||||
|
using Repository;
|
||||||
|
|
||||||
|
namespace Logic;
|
||||||
|
|
||||||
|
public class PasswordStoreService : IPasswordStoreService
|
||||||
|
{
|
||||||
|
private readonly IRepository repository;
|
||||||
|
|
||||||
|
public int Create(string path, string? displayName = null, string? iconName = null)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Create(PasswordStore item)
|
||||||
|
{
|
||||||
|
return Create(item.Path, item.DisplayName, item.IconName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Delete(uint ID)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Delete(PasswordStore item)
|
||||||
|
{
|
||||||
|
return Delete(item.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Edit(uint ID, PasswordStore newItem)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PasswordStore Get(uint ID)
|
||||||
|
{
|
||||||
|
return repository.ReadAll().Where(item => item.ID.Equals(ID)).First();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<PasswordStore> GetAll()
|
||||||
|
{
|
||||||
|
return (IEnumerable<PasswordStore>)repository.ReadAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
public class PasswordStore
|
public class PasswordStore
|
||||||
{
|
{
|
||||||
private List<FileInfo> passwordFiles;
|
public uint ID;
|
||||||
|
public string Path;
|
||||||
}
|
public string? DisplayName;
|
||||||
|
public string? IconName;
|
||||||
|
}
|
||||||
10
Repository/IRepository.cs
Normal file
10
Repository/IRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Repository;
|
||||||
|
|
||||||
|
public interface IRepository
|
||||||
|
{
|
||||||
|
IEnumerable ReadAll();
|
||||||
|
void WriteAll(IEnumerable items);
|
||||||
|
object Get(uint id);
|
||||||
|
}
|
||||||
67
Repository/Repository.cs
Normal file
67
Repository/Repository.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Repository;
|
||||||
|
|
||||||
|
public class Repository : IRepository
|
||||||
|
{
|
||||||
|
private const string _appName = "Keychain";
|
||||||
|
private readonly string _filePath;
|
||||||
|
private List<object>? _cache;
|
||||||
|
private bool _cacheDirty = true;
|
||||||
|
|
||||||
|
public Repository(string fileName)
|
||||||
|
{
|
||||||
|
var xdgDataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||||
|
string dataHome;
|
||||||
|
if (!string.IsNullOrEmpty(xdgDataHome))
|
||||||
|
{
|
||||||
|
dataHome = Path.Combine(xdgDataHome, _appName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataHome = Path.Combine(
|
||||||
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"),
|
||||||
|
_appName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_filePath = Path.Combine(dataHome, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable ReadAll()
|
||||||
|
{
|
||||||
|
if (!_cacheDirty && _cache != null)
|
||||||
|
return _cache;
|
||||||
|
|
||||||
|
if (!File.Exists(_filePath))
|
||||||
|
{
|
||||||
|
_cache = new List<object>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var json = File.ReadAllText(_filePath);
|
||||||
|
_cache = JsonSerializer.Deserialize<List<object>>(json) ?? new List<object>();
|
||||||
|
}
|
||||||
|
_cacheDirty = false;
|
||||||
|
return _cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Get(uint id)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteAll(IEnumerable items)
|
||||||
|
{
|
||||||
|
var json = JsonSerializer.Serialize(items);
|
||||||
|
var directory = Path.GetDirectoryName(_filePath);
|
||||||
|
if (!Directory.Exists(directory))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(directory!);
|
||||||
|
}
|
||||||
|
File.WriteAllText(_filePath, json);
|
||||||
|
|
||||||
|
_cache = (List<object>)items;
|
||||||
|
_cacheDirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Repository/Repository.csproj
Normal file
9
Repository/Repository.csproj
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user