add UserNotifier for user notifications with a logger implementation
continuous-integration/drone/push Build is passing Details

pull/40/head
Maxime BATISTA 2 years ago
parent fe44bf737d
commit fcbbb28a34

@ -7,14 +7,15 @@ using LocalEndpoint;
public partial class App : Application, ConnectionObserver
{
private IEndpoint endpoint = new LocalEndpoint();
private IEndpoint Endpoint = new LocalEndpoint();
private UserNotifier Notifier = new ConsoleUserNotifier();
public App()
{
InitializeComponent();
Shell shell = new ConnectAppShell(this, endpoint.AccountManager);
Shell shell = new ConnectAppShell(this, Endpoint.AccountManager, Notifier);
shell.GoToAsync("//Splash");
MainPage = shell;
}

@ -7,9 +7,9 @@ using ShoopNCook.Pages;
public partial class ConnectAppShell : Shell
{
public ConnectAppShell(ConnectionObserver observer, IAccountManager accounts)
public ConnectAppShell(ConnectionObserver observer, IAccountManager accounts, UserNotifier notifier)
{
ConnectionController controller = new ConnectionController(observer, accounts);
ConnectionController controller = new ConnectionController(observer, accounts, notifier);
InitializeComponent();
LoginPage.ContentTemplate = new DataTemplate(() => new LoginPage(controller));
RegisterPage.ContentTemplate = new DataTemplate(() => new RegisterPage(controller));

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoopNCook
{
/// <summary>
/// A notice reporter implementation that prints in console the applications's user notices.
/// </summary>
public class ConsoleUserNotifier :
UserNotifier
{
public void Error(string message)
{
Console.WriteLine("<Notice Reporter> Error: " + message);
}
public void Notice(string message)
{
Console.WriteLine("<Notice Reporter> Notice: " + message);
}
public void Warn(string message)
{
Console.WriteLine("<Notice Reporter> Warn: " + message);
}
}
}

@ -7,19 +7,32 @@ namespace ShoopNCook.Controllers
{
private readonly ConnectionObserver observer;
private readonly IAccountManager accounts;
public ConnectionController(ConnectionObserver observer, IAccountManager accounts) {
private readonly UserNotifier notifier;
public ConnectionController(ConnectionObserver observer, IAccountManager accounts, UserNotifier notifier) {
this.observer = observer;
this.accounts = accounts;
this.notifier = notifier;
}
public void Login(string email, string password)
{
Account acc = accounts.Login(email, password);
Account? acc = accounts.Login(email, password);
if (acc == null)
{
notifier.Error("Email or password invalid.");
return;
}
observer.OnAccountConnected(acc);
}
public void Register(string username, string email, string password)
{
Account acc = accounts.Register(username, email, password);
Account? acc = accounts.Register(username, email, password);
if (acc == null)
{
notifier.Error("Invalid credentials.");
return;
}
observer.OnAccountConnected(acc);
}
}

@ -26,6 +26,9 @@ namespace LocalEndpoint
public Account? Register(string email, string username, string password)
{
if (email == null || username == null || password == null)
return null;
userAccount = new Account(new User(DEFAULT_ACCOUNT_IMAGE, username), email);
userPassword = password;
return userAccount;

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoopNCook
{
public interface UserNotifier
{
public void Notice(string message);
public void Error(string message);
public void Warn(string message);
}
}
Loading…
Cancel
Save