2023-02-22 14:03:35 +01:00
|
|
|
using System;
|
2024-04-09 12:53:23 +02:00
|
|
|
using ShareeBike.Model.Device;
|
|
|
|
using ShareeBike.Model.Services.CopriApi;
|
|
|
|
using ShareeBike.Repository;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
namespace ShareeBike.Model.Connector
|
2021-05-13 20:03:07 +02:00
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Connects app to copri data by getting data from cache.
|
|
|
|
/// </summary>
|
|
|
|
public class ConnectorCache : IConnector
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
/// <summary>Constructs a copri connector object to connect to cache.</summary>
|
2023-11-06 12:23:09 +01:00
|
|
|
/// <remarks>Used for offline scenario to ensure responsiveness of app by preventing hopeless tries to communicate with COPRI. </remarks>
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
|
|
|
|
/// <param name="sessionCookie"> Holds the session cookie.</param>
|
|
|
|
/// <param name="mail">Mail of user.</param>
|
2023-02-22 14:03:35 +01:00
|
|
|
/// <param name="smartDevice">Holds info about smart device.</param>
|
2023-11-06 12:23:09 +01:00
|
|
|
/// <param name="server"> Is null in production and might be a mock in testing context.</param>
|
2022-09-06 16:08:19 +02:00
|
|
|
public ConnectorCache(
|
|
|
|
AppContextInfo appContextInfo,
|
|
|
|
string uiIsoLangugageName,
|
|
|
|
string sessionCookie,
|
|
|
|
string mail,
|
2023-02-22 14:03:35 +01:00
|
|
|
ISmartDevice smartDevice = null,
|
2022-09-06 16:08:19 +02:00
|
|
|
ICopriServer server = null)
|
|
|
|
{
|
2023-02-22 14:03:35 +01:00
|
|
|
Command = Connector.CreateCommand(
|
|
|
|
server ?? new CopriProviderMonkeyStore(appContextInfo.MerchantId, uiIsoLangugageName, sessionCookie, smartDevice),
|
2022-09-06 16:08:19 +02:00
|
|
|
sessionCookie,
|
|
|
|
mail);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
Query = GetQuery(
|
2023-02-22 14:03:35 +01:00
|
|
|
server ?? new CopriProviderMonkeyStore(appContextInfo.MerchantId, uiIsoLangugageName, sessionCookie, smartDevice),
|
2022-09-06 16:08:19 +02:00
|
|
|
sessionCookie,
|
|
|
|
mail);
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2023-11-06 12:23:09 +01:00
|
|
|
/// <summary> Object for querying stations and bikes.</summary>
|
2022-09-06 16:08:19 +02:00
|
|
|
public ICommand Command { get; private set; }
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2023-11-06 12:23:09 +01:00
|
|
|
/// <summary> Object for querying stations and bikes.</summary>
|
2022-09-06 16:08:19 +02:00
|
|
|
public IQuery Query { get; private set; }
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
|
|
|
|
public bool IsConnected => Command.IsConnected;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
/// <summary> Gets a command object to perform copri queries. </summary>
|
|
|
|
private static IQuery GetQuery(ICopriServer copri, string sessioncookie, string mail) => string.IsNullOrEmpty(sessioncookie)
|
|
|
|
? new Query(copri) as IQuery
|
|
|
|
: new QueryLoggedIn(copri, sessioncookie, mail, () => DateTime.Now);
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
}
|