mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-23 15:46:29 +01:00
141 lines
5.5 KiB
C#
141 lines
5.5 KiB
C#
|
using Serilog;
|
|||
|
using System;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using TINK.Model.Repository;
|
|||
|
using TINK.Model.Repository.Request;
|
|||
|
using TINK.Model.Repository.Response;
|
|||
|
using TINK.Model.User.Account;
|
|||
|
|
|||
|
namespace TINK.Model.Connector
|
|||
|
{
|
|||
|
public class Command : Base, ICommand
|
|||
|
{
|
|||
|
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
|
|||
|
public bool IsConnected => CopriServer.IsConnected;
|
|||
|
|
|||
|
/// <summary> No user is logged in.</summary>
|
|||
|
public string SessionCookie => null;
|
|||
|
|
|||
|
/// <summary> Is raised whenever login state has changed.</summary>
|
|||
|
public event LoginStateChangedEventHandler LoginStateChanged;
|
|||
|
|
|||
|
/// <summary>Constructs a copri query object.</summary>
|
|||
|
/// <param name="p_oCopriServer">Server which implements communication.</param>
|
|||
|
public Command(
|
|||
|
ICopriServerBase p_oCopriServer) : base(p_oCopriServer)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Logs user in.
|
|||
|
/// If log in succeeds either and session might be updated if it was no more valid (logged in by an different device).
|
|||
|
/// If log in fails (password modified) session cookie is set to empty.
|
|||
|
/// If communication fails an exception is thrown.
|
|||
|
/// </summary>
|
|||
|
public async Task<IAccount> DoLogin(
|
|||
|
string p_strMail,
|
|||
|
string p_strPassword,
|
|||
|
string p_strDeviceId)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(p_strMail))
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Can not loging user. Mail address must not be null or empty.");
|
|||
|
}
|
|||
|
|
|||
|
if (string.IsNullOrEmpty(p_strPassword))
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Can not loging user. Password must not be null or empty.");
|
|||
|
}
|
|||
|
|
|||
|
if (string.IsNullOrEmpty(p_strDeviceId))
|
|||
|
{
|
|||
|
throw new ArgumentNullException("Can not loging user. Device not be null or empty.");
|
|||
|
}
|
|||
|
|
|||
|
AuthorizationResponse l_oResponse;
|
|||
|
try
|
|||
|
{
|
|||
|
l_oResponse = (await CopriServer.DoAuthorizationAsync(p_strMail, p_strPassword, p_strDeviceId)).GetIsResponseOk(p_strMail);
|
|||
|
}
|
|||
|
catch (System.Exception)
|
|||
|
{
|
|||
|
throw;
|
|||
|
}
|
|||
|
|
|||
|
var l_oAccount = l_oResponse.GetAccount(MerchantId, p_strMail, p_strPassword);
|
|||
|
|
|||
|
// Log in state changes. Notify parent object to update.
|
|||
|
LoginStateChanged?.Invoke(this, new LoginStateChangedEventArgs(l_oAccount.SessionCookie, l_oAccount.Mail));
|
|||
|
|
|||
|
return l_oAccount;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary> Logs user out. </summary>
|
|||
|
public async Task DoLogout()
|
|||
|
{
|
|||
|
Log.ForContext<Command>().Error("Unexpected log out request detected. No user logged in.");
|
|||
|
await Task.CompletedTask;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Request to reserve a bike.
|
|||
|
/// </summary>
|
|||
|
/// <param name="p_oBike">Bike to book.</param>
|
|||
|
public async Task DoReserve(
|
|||
|
Bikes.Bike.BC.IBikeInfoMutable p_oBike)
|
|||
|
{
|
|||
|
Log.ForContext<Command>().Error("Unexpected booking request detected. No user logged in.");
|
|||
|
await Task.CompletedTask;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary> Request to cancel a reservation.</summary>
|
|||
|
/// <param name="p_oBike">Bike to book.</param>
|
|||
|
public async Task DoCancelReservation(Bikes.Bike.BC.IBikeInfoMutable bike)
|
|||
|
{
|
|||
|
Log.ForContext<Command>().Error("Unexpected cancel reservation request detected. No user logged in.");
|
|||
|
await Task.CompletedTask;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary> Get authentication keys.</summary>
|
|||
|
/// <param name="bike">Bike to book.</param>
|
|||
|
public async Task CalculateAuthKeys(Bikes.Bike.BluetoothLock.IBikeInfoMutable bike)
|
|||
|
{
|
|||
|
Log.ForContext<Command>().Error("Unexpected request to get authenticatin keys detected. No user logged in.");
|
|||
|
await Task.CompletedTask;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary> Updates COPRI lock state for a booked bike. </summary>
|
|||
|
/// <param name="bike">Bike to update locking state for.</param>
|
|||
|
/// <param name="location">Location where lock was opened/ changed.</param>
|
|||
|
/// <returns>Response on updating locking state.</returns>
|
|||
|
public async Task UpdateLockingStateAsync(Bikes.Bike.BluetoothLock.IBikeInfoMutable bike, LocationDto location)
|
|||
|
{
|
|||
|
Log.ForContext<Command>().Error("Unexpected request to update locking state detected. No user logged in.");
|
|||
|
await Task.CompletedTask;
|
|||
|
}
|
|||
|
|
|||
|
public async Task DoBook(Bikes.Bike.BluetoothLock.IBikeInfoMutable bike)
|
|||
|
{
|
|||
|
Log.ForContext<Command>().Error("Unexpected booking request detected. No user logged in.");
|
|||
|
await Task.CompletedTask;
|
|||
|
}
|
|||
|
|
|||
|
public async Task DoReturn(
|
|||
|
Bikes.Bike.BluetoothLock.IBikeInfoMutable bike,
|
|||
|
LocationDto location)
|
|||
|
{
|
|||
|
Log.ForContext<Command>().Error("Unexpected returning request detected. No user logged in.");
|
|||
|
await Task.CompletedTask;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Submits feedback to copri server.
|
|||
|
/// </summary>
|
|||
|
/// <param name="userFeedback">Feedback to submit.</param>
|
|||
|
public async Task DoSubmitFeedback(ICommand.IUserFeedback userFeedback, Uri opertorUri)
|
|||
|
{
|
|||
|
Log.ForContext<Command>().Error("Unexpected submit feedback request detected. No user logged in.");
|
|||
|
await Task.CompletedTask;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|