mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-12 13:36:26 +01:00
57 lines
2.7 KiB
C#
57 lines
2.7 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 Connector : IConnector
|
|
{
|
|
/// <summary>Constructs a copri connector object.</summary>
|
|
/// <param name="activeUri"> Uri to connect to.</param>
|
|
/// <param name="appContextInfo">Provides app related info (app name and version, merchantid) to pass to COPRI.</param>
|
|
/// /// <param name="sessionCookie"> Holds the session cookie.</param>
|
|
/// <param name="p_strMail">Mail of user.</param>
|
|
/// <param name="expiresAfter">Timespan which holds value after which cache expires.</param>
|
|
/// <param name="server"> Provides cached addess to copri.</param>
|
|
public Connector(
|
|
Uri activeUri,
|
|
AppContextInfo appContextInfo,
|
|
string sessionCookie,
|
|
string mail,
|
|
TimeSpan? expiresAfter = null,
|
|
ICachedCopriServer server = null )
|
|
{
|
|
Command = GetCommand(
|
|
server ?? new CopriProviderHttps(activeUri, appContextInfo.MerchantId, appContextInfo, sessionCookie),
|
|
sessionCookie,
|
|
mail);
|
|
|
|
Query = GetQuery(
|
|
server ?? new CopriProviderHttps(activeUri, appContextInfo.MerchantId, appContextInfo, sessionCookie, expiresAfter),
|
|
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 commands. </summary>
|
|
public static ICommand GetCommand(ICopriServerBase copri, string sessioncookie, string mail) => string.IsNullOrEmpty(sessioncookie)
|
|
? new Command(copri)
|
|
: new CommandLoggedIn(copri, sessioncookie, mail, () => DateTime.Now) as ICommand;
|
|
|
|
/// <summary> Gets a command object to perform copri queries. </summary>
|
|
private static IQuery GetQuery(ICachedCopriServer copri, string sessioncookie, string mail) => string.IsNullOrEmpty(sessioncookie)
|
|
? new CachedQuery(copri) as IQuery
|
|
: new CachedQueryLoggedIn(copri, sessioncookie, mail, () => DateTime.Now);
|
|
}
|
|
}
|