mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-12 05:26:28 +01:00
47 lines
1.9 KiB
C#
47 lines
1.9 KiB
C#
using System;
|
|
using TINK.Model.Services.CopriApi;
|
|
using TINK.Repository;
|
|
|
|
namespace TINK.Model.Connector
|
|
{
|
|
/// <summary>
|
|
/// Connects tink app to copri by getting data from copri and updating tink app model (i.e. bikes, user, ...)
|
|
/// </summary>
|
|
public class ConnectorCache : IConnector
|
|
{
|
|
/// <summary>Constructs a copri connector object.</summary>
|
|
/// <param name="p_strSessionCookie"> Holds the session cookie.</param>
|
|
/// <param name="p_strMail">Mail of user.</param>
|
|
/// <param name="server"> Provides addess to copri.</param>
|
|
public ConnectorCache(
|
|
string sessionCookie,
|
|
string mail,
|
|
ICopriServer server = null)
|
|
{
|
|
|
|
Command = Connector.GetCommand(
|
|
server ?? new CopriProviderMonkeyStore(TinkApp.MerchantId, sessionCookie),
|
|
sessionCookie,
|
|
mail);
|
|
|
|
Query = GetQuery(
|
|
server ?? new CopriProviderMonkeyStore(TinkApp.MerchantId, sessionCookie),
|
|
sessionCookie,
|
|
mail);
|
|
}
|
|
|
|
/// <summary> Object for queriying stations and bikes.</summary>
|
|
public ICommand Command { get; private set; }
|
|
|
|
/// <summary> Object for queriying stations and bikes.</summary>
|
|
public IQuery Query { get; private set; }
|
|
|
|
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
|
|
public bool IsConnected => Command.IsConnected;
|
|
|
|
/// <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);
|
|
}
|
|
}
|