yea boy, now I got it!

This commit is contained in:
2024-05-28 15:18:27 +02:00
parent b08041204d
commit 991987bb6d
28 changed files with 396 additions and 312 deletions

View File

@@ -1,54 +1,7 @@
using OwnChar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OwnChar.Manager
namespace OwnChar.Manager
{
public class CharacterManager(OwnCharManager manager)
{
public OwnCharManager Manager { get; } = manager;
/// <summary>
/// Gets all personal characters (private & within groups).
/// </summary>
/// <param name="group"></param>
/// <returns>Returns a collection with personal characters.</returns>
public IEnumerable<Character>? GetCharacters()
{
if (!IsLoggedIn || UserProfile == null)
return null;
return GetCharacters(Manager.CurrentUser);
}
/// <summary>
/// Gets all public ore accessable (e.g. via shares) characters from the specified group.
/// </summary>
/// <param name="group"></param>
/// <returns>Returns a collection with characters for the specified group.</returns>
public IEnumerable<Character> GetCharacters(Group group)
{
}
/// <summary>
/// Saves a character. If it doesn't exists, it will be created.
/// </summary>
/// <param name="character">The caracter to save.</param>
/// <returns><see cref="true"/> if success, otherwise <see cref="false"/>.</returns>
public bool SaveCharacter(Character character)
{
}
/// <summary>
/// Deletes a given character. If it doesn't exists, it will be ignored.
/// </summary>
/// <param name="character"></param>
/// <returns><see cref="true"/> if the given character has been deleted successfully or doesn't exist, otherwise <see cref="false"/>.</returns>
public bool DeleteCharacter(Character character)
{
}
}
}

View File

@@ -1,9 +1,4 @@
using OwnChar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OwnChar.Manager
{
@@ -11,40 +6,16 @@ namespace OwnChar.Manager
{
public OwnCharManager Manager { get; } = manager;
public Group? GetGroup()
public UserProfile? GetOwner(Group? group)
{
if (!IsLoggedIn || UserProfile == null)
return null;
// ...
ArgumentNullException.ThrowIfNull(group, nameof(group));
return Manager.DataProxy?.GetOwner(group);
}
public IEnumerable<Group>? GetGroups()
{
if (!IsLoggedIn || UserProfile == null)
return null;
return GetGroups(UserProfile);
}
public IEnumerable<Group>? GetGroups(UserProfile profile)
{
if (!IsLoggedIn)
return null;
// ...
}
public Group? CreateGroup(UserProfile owner)
{
}
public bool SaveGroup(Group group)
{
}
public bool DeleteGroup(Group group)
public IEnumerable<UserProfile>? GetMembers(Group? group)
{
ArgumentNullException.ThrowIfNull(group, nameof(group));
return Manager.DataProxy?.GetMembers(group);
}
}
}

View File

@@ -8,11 +8,11 @@ namespace OwnChar.Manager
public class OwnCharManager
{
// User
public bool IsLoggedIn => DataProvider != null && DataProvider.IsLoggedIn;
public UserAccount? CurrentUser => DataProvider?.CurrentUserAccount;
public bool IsLoggedIn => CurrentUser != null;
public UserAccount? CurrentUser { get; private set; }
// Data Provider
public IDataProvider? DataProvider { get; set; }
public IDataProxy? DataProxy { get; set; }
// Manager
public UserManager Users { get; }
@@ -26,7 +26,7 @@ namespace OwnChar.Manager
Characters = new(this);
}
private void CheckLogin()
internal protected void CheckLogin()
{
if (!IsLoggedIn)
throw new LoginException("You are already logged in!");
@@ -36,11 +36,15 @@ namespace OwnChar.Manager
/// Tries to login on the given data provider.
/// </summary>
/// <returns>Returns <see cref="true"/> if the login was successfull and <see cref="false"/> if not.</returns>
public bool Login(IDataProvider? dataProvider, string username, SecureString password)
public bool Login(IDataProxy? proxy, string? username, SecureString? password)
{
CheckLogin();
ArgumentNullException.ThrowIfNull(dataProvider);
return dataProvider.Login(username, password) != null;
ArgumentNullException.ThrowIfNull(proxy, nameof(proxy));
ArgumentException.ThrowIfNullOrWhiteSpace(username, nameof(username));
ArgumentException.ThrowIfNullOrWhiteSpace(password, nameof(password));
CurrentUser = proxy.Login(username, password);
return IsLoggedIn;
}
/// <summary>
@@ -49,9 +53,7 @@ namespace OwnChar.Manager
/// <returns></returns>
public bool Logout()
{
if (DataProvider != null)
return DataProvider.Logout();
return true;
return DataProxy?.Logout(CurrentUser) ?? true;
}
}
}

View File

@@ -1,5 +1,4 @@
using OwnChar.Model;
using Pilz.Cryptography;
namespace OwnChar.Manager
{
@@ -7,50 +6,17 @@ namespace OwnChar.Manager
{
public OwnCharManager Manager { get; } = manager;
public UserProfile? GetUserProfile(UserAccount account)
public UserProfile? GetOwnUserProfile(UserAccount account)
{
Manager.CheckLogin();
return Manager.DataProxy!.GetUserProfile(Manager.CurrentUser!);
}
public UserAccount? CreateAccount(string username, SecureString password, string email, string displayName)
{
// Create account
// ...
// Create profile
// ...
}
/// <summary>
/// Saves the current logged in user account.
/// </summary>
/// <returns><see cref="true"/> if success, otherwise <see cref="false"/>.</returns>
public bool SaveAccount()
{
}
public bool DeleteAccount()
{
}
public UserProfile? CreateProfile()
{
// Create profile
// ...
// Create pre-defined group
// ...
}
/// <summary>
/// Saves the current logged in user profile.
/// </summary>
/// <returns><see cref="true"/> if success, otherwise <see cref="false"/>.</returns>
public bool SaveProfile()
{
}
public bool DeleteProfile()
public UserAccount? CreateUserAccount(string? username, string? password)
{
ArgumentException.ThrowIfNullOrWhiteSpace(username, nameof(username));
ArgumentException.ThrowIfNullOrWhiteSpace(password, nameof(password));
return Manager.DataProxy?.CreateUserAccount(username, password);
}
}
}