2022-12-27 21:08:09 +01:00
|
|
|
using System;
|
2022-08-30 15:42:25 +02:00
|
|
|
using System.Collections.Generic;
|
2021-05-13 20:03:07 +02:00
|
|
|
using System.Threading.Tasks;
|
2022-08-30 15:42:25 +02:00
|
|
|
using Serilog;
|
|
|
|
using TINK.Model.Connector.Updater;
|
|
|
|
using TINK.Model.Device;
|
|
|
|
using TINK.Model.User.Account;
|
2021-06-26 20:57:55 +02:00
|
|
|
using TINK.Repository;
|
|
|
|
using TINK.Repository.Request;
|
|
|
|
using TINK.Repository.Response;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
namespace TINK.Model.Connector
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
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 mail,
|
|
|
|
string password,
|
|
|
|
string deviceId)
|
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(mail))
|
|
|
|
{
|
2023-05-11 17:39:28 +02:00
|
|
|
throw new ArgumentNullException("Can not login user. Mail address must not be null or empty.");
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(password))
|
|
|
|
{
|
2023-05-11 17:39:28 +02:00
|
|
|
throw new ArgumentNullException("Can not login user. Password must not be null or empty.");
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(deviceId))
|
|
|
|
{
|
2023-05-11 17:39:28 +02:00
|
|
|
throw new ArgumentNullException("Can not login user. Device not be null or empty.");
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AuthorizationResponse response;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
response = (await CopriServer.DoAuthorizationAsync(mail, password, deviceId)).GetIsResponseOk(mail);
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
var l_oAccount = response.GetAccount(MerchantId, mail, password);
|
|
|
|
|
|
|
|
// 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="bike">Bike to book.</param>
|
|
|
|
public async Task DoReserve(
|
|
|
|
Bikes.BikeInfoNS.BC.IBikeInfoMutable bike)
|
|
|
|
{
|
|
|
|
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.BikeInfoNS.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.BikeInfoNS.BluetoothLock.IBikeInfoMutable bike)
|
|
|
|
{
|
2023-05-11 17:39:28 +02:00
|
|
|
Log.ForContext<Command>().Error("Unexpected request to get authentication keys detected. No user logged in.");
|
2022-09-06 16:08:19 +02:00
|
|
|
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 StartReturningBike(Bikes.BikeInfoNS.BC.IBikeInfoMutable bike)
|
|
|
|
{
|
|
|
|
Log.ForContext<Command>().Error("Unexpected request to notify about start of returning bike. No user logged in.");
|
|
|
|
await Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary> Notifies COPRI about start of returning sequence. </summary>
|
|
|
|
/// <remarks> Operator specific call.</remarks>
|
|
|
|
/// <param name="bike">Bike to return.</param>
|
|
|
|
/// <returns>Response on notification about start of returning sequence.</returns>
|
|
|
|
public async Task UpdateLockingStateAsync(Bikes.BikeInfoNS.BluetoothLock.IBikeInfoMutable bike, LocationDto location)
|
|
|
|
{
|
|
|
|
Log.ForContext<Command>().Error("Unexpected request to update locking state detected. No user logged in.");
|
|
|
|
await Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
2022-12-27 21:08:09 +01:00
|
|
|
public async Task DoBookAsync(Bikes.BikeInfoNS.BC.IBikeInfoMutable bike, LockingAction? nextAction = null)
|
2022-09-06 16:08:19 +02:00
|
|
|
{
|
|
|
|
Log.ForContext<Command>().Error("Unexpected booking request detected. No user logged in.");
|
|
|
|
await Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task BookAndOpenAync(Bikes.BikeInfoNS.CopriLock.IBikeInfoMutable bike)
|
|
|
|
{
|
|
|
|
Log.ForContext<Command>().Error("Unexpected request to book and open bike detected. No user logged in.");
|
|
|
|
await Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<BookingFinishedModel> DoReturn(
|
|
|
|
Bikes.BikeInfoNS.BC.IBikeInfoMutable bike,
|
|
|
|
LocationDto location,
|
|
|
|
ISmartDevice smartDevice)
|
|
|
|
{
|
|
|
|
Log.ForContext<Command>().Error("Unexpected returning request detected. No user logged in.");
|
|
|
|
return await Task.FromResult(new BookingFinishedModel());
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<BookingFinishedModel> ReturnAndCloseAsync(
|
|
|
|
Bikes.BikeInfoNS.CopriLock.IBikeInfoMutable bike,
|
|
|
|
ISmartDevice smartDevice)
|
|
|
|
{
|
|
|
|
Log.ForContext<Command>().Error("Unexpected close lock and return request detected. No user logged in.");
|
|
|
|
return await Task.FromResult(new BookingFinishedModel());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Submits feedback to copri server.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userFeedback">Feedback to submit.</param>
|
2021-06-26 20:57:55 +02:00
|
|
|
#if USCSHARP9
|
2021-05-13 20:03:07 +02:00
|
|
|
public async Task DoSubmitFeedback(ICommand.IUserFeedback userFeedback, Uri opertorUri)
|
2021-06-26 20:57:55 +02:00
|
|
|
#else
|
2022-09-06 16:08:19 +02:00
|
|
|
public async Task DoSubmitFeedback(IUserFeedback userFeedback, Uri opertorUri)
|
2021-06-26 20:57:55 +02:00
|
|
|
#endif
|
2022-09-06 16:08:19 +02:00
|
|
|
{
|
|
|
|
Log.ForContext<Command>().Error("Unexpected submit feedback request detected. No user logged in.");
|
|
|
|
await Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary> Submits mini survey to copri server. </summary>
|
|
|
|
/// <param name="answers">Collection of answers.</param>
|
|
|
|
public async Task DoSubmitMiniSurvey(IDictionary<string, string> answers)
|
|
|
|
{
|
|
|
|
Log.ForContext<Command>().Error("Unexpected submit mini survey request detected. No user logged in.");
|
|
|
|
await Task.CompletedTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task OpenLockAsync(Bikes.BikeInfoNS.CopriLock.IBikeInfoMutable bike)
|
|
|
|
=> throw new NotImplementedException();
|
|
|
|
|
|
|
|
public Task CloseLockAsync(Bikes.BikeInfoNS.CopriLock.IBikeInfoMutable bike)
|
|
|
|
=> throw new NotImplementedException();
|
|
|
|
}
|
2022-12-27 21:08:09 +01:00
|
|
|
}
|