mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-22 05:47:28 +02:00
Version 3.0.338
This commit is contained in:
parent
573fe77e12
commit
0468955d49
751 changed files with 62747 additions and 60672 deletions
|
@ -10,297 +10,297 @@ using TINK.Repository.Response;
|
|||
|
||||
namespace TINK.Model.Services.CopriApi
|
||||
{
|
||||
/// <summary> Object which manages calls to copri in a thread safe way inclding cache functionality. </summary>
|
||||
public class CopriProviderHttps : ICachedCopriServer
|
||||
{
|
||||
/// <summary> Object which manages stored copri answers. </summary>
|
||||
private ICopriCache CacheServer { get; }
|
||||
/// <summary> Object which manages calls to copri in a thread safe way inclding cache functionality. </summary>
|
||||
public class CopriProviderHttps : ICachedCopriServer
|
||||
{
|
||||
/// <summary> Object which manages stored copri answers. </summary>
|
||||
private ICopriCache CacheServer { get; }
|
||||
|
||||
/// <summary> Communicates whith copri server. </summary>
|
||||
private ICopriServer HttpsServer { get; }
|
||||
/// <summary> Communicates whith copri server. </summary>
|
||||
private ICopriServer HttpsServer { get; }
|
||||
|
||||
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
|
||||
public bool IsConnected => HttpsServer.IsConnected;
|
||||
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
|
||||
public bool IsConnected => HttpsServer.IsConnected;
|
||||
|
||||
/// <summary> Gets the session cookie if user is logged in, an empty string otherwise. </summary>
|
||||
public string SessionCookie => HttpsServer.SessionCookie;
|
||||
/// <summary> Gets the session cookie if user is logged in, an empty string otherwise. </summary>
|
||||
public string SessionCookie => HttpsServer.SessionCookie;
|
||||
|
||||
/// <summary> Gets the merchant id.</summary>
|
||||
public string MerchantId => HttpsServer.MerchantId;
|
||||
/// <summary> Gets the merchant id.</summary>
|
||||
public string MerchantId => HttpsServer.MerchantId;
|
||||
|
||||
/// <summary> Constructs copri provider object to connet to https using a cache objet. </summary>
|
||||
/// <param name="copriHost"></param>
|
||||
/// <param name="appContextInfo">Provides app related info (app name and version, merchantid) to pass to COPRI.</param>
|
||||
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
|
||||
/// <param name="sessionCookie">Cookie of user if a user is logged in, false otherwise.</param>
|
||||
/// <param name="expiresAfter">Timespan which holds value after which cache expires.</param>
|
||||
public CopriProviderHttps(
|
||||
Uri copriHost,
|
||||
string merchantId,
|
||||
AppContextInfo appContextInfo,
|
||||
string uiIsoLangugageName,
|
||||
string sessionCookie = null,
|
||||
TimeSpan? expiresAfter = null,
|
||||
ICopriCache cacheServer = null,
|
||||
ICopriServer httpsServer = null)
|
||||
{
|
||||
CacheServer = cacheServer ?? new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie, expiresAfter);
|
||||
HttpsServer = httpsServer ?? new CopriCallsHttps(copriHost, appContextInfo, uiIsoLangugageName, sessionCookie);
|
||||
}
|
||||
/// <summary> Constructs copri provider object to connet to https using a cache objet. </summary>
|
||||
/// <param name="copriHost"></param>
|
||||
/// <param name="appContextInfo">Provides app related info (app name and version, merchantid) to pass to COPRI.</param>
|
||||
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
|
||||
/// <param name="sessionCookie">Cookie of user if a user is logged in, false otherwise.</param>
|
||||
/// <param name="expiresAfter">Timespan which holds value after which cache expires.</param>
|
||||
public CopriProviderHttps(
|
||||
Uri copriHost,
|
||||
string merchantId,
|
||||
AppContextInfo appContextInfo,
|
||||
string uiIsoLangugageName,
|
||||
string sessionCookie = null,
|
||||
TimeSpan? expiresAfter = null,
|
||||
ICopriCache cacheServer = null,
|
||||
ICopriServer httpsServer = null)
|
||||
{
|
||||
CacheServer = cacheServer ?? new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie, expiresAfter);
|
||||
HttpsServer = httpsServer ?? new CopriCallsHttps(copriHost, appContextInfo, uiIsoLangugageName, sessionCookie);
|
||||
}
|
||||
|
||||
/// <summary>Gets bikes available.</summary>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
public async Task<Result<BikesAvailableResponse>> GetBikesAvailable(bool fromCache = false)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to get bikes available{(fromCache ? " from cache" : "")}...");
|
||||
if (!CacheServer.IsBikesAvailableExpired
|
||||
|| fromCache)
|
||||
{
|
||||
// No need to query because previous answer is not yet outdated.
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Returning bikes available from cache.");
|
||||
var bikesAvailableResponse = await CacheServer.GetBikesAvailableAsync();
|
||||
return new Result<BikesAvailableResponse>(typeof(CopriCallsMonkeyStore), bikesAvailableResponse, bikesAvailableResponse.GetGeneralData());
|
||||
}
|
||||
/// <summary>Gets bikes available.</summary>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
public async Task<Result<BikesAvailableResponse>> GetBikesAvailable(bool fromCache = false)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to get bikes available{(fromCache ? " from cache" : "")}...");
|
||||
if (!CacheServer.IsBikesAvailableExpired
|
||||
|| fromCache)
|
||||
{
|
||||
// No need to query because previous answer is not yet outdated.
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Returning bikes available from cache.");
|
||||
var bikesAvailableResponse = await CacheServer.GetBikesAvailableAsync();
|
||||
return new Result<BikesAvailableResponse>(typeof(CopriCallsMonkeyStore), bikesAvailableResponse, bikesAvailableResponse.GetGeneralData());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Querrying bikes available from copri.");
|
||||
var bikesAvailableResponse = await HttpsServer.GetBikesAvailableAsync();
|
||||
return new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
bikesAvailableResponse.GetIsResponseOk(MultilingualResources.AppResources.ErrorBikesAvailableResponseNotOk),
|
||||
bikesAvailableResponse.GetGeneralData());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Return response from cache.
|
||||
Log.ForContext<CopriProviderHttps>().Debug("An error occurred querrying bikes available. {Exception}.", exception);
|
||||
var bikesAvailableResponse = await CacheServer.GetBikesAvailableAsync();
|
||||
return new Result<BikesAvailableResponse>(typeof(CopriCallsMonkeyStore), bikesAvailableResponse, bikesAvailableResponse.GetGeneralData(), exception);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Querrying bikes available from copri.");
|
||||
var bikesAvailableResponse = await HttpsServer.GetBikesAvailableAsync();
|
||||
return new Result<BikesAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
bikesAvailableResponse.GetIsResponseOk(MultilingualResources.AppResources.ErrorBikesAvailableResponseNotOk),
|
||||
bikesAvailableResponse.GetGeneralData());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Return response from cache.
|
||||
Log.ForContext<CopriProviderHttps>().Debug("An error occurred querrying bikes available. {Exception}.", exception);
|
||||
var bikesAvailableResponse = await CacheServer.GetBikesAvailableAsync();
|
||||
return new Result<BikesAvailableResponse>(typeof(CopriCallsMonkeyStore), bikesAvailableResponse, bikesAvailableResponse.GetGeneralData(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Gets a list of bikes reserved/ booked by acctive user. </summary>
|
||||
/// <param name="sessionCookie">Cookie to authenticate user.</param>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
public async Task<Result<BikesReservedOccupiedResponse>> GetBikesOccupied(bool fromCache = false)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to get bikes occupied{(fromCache ? " from cache" : "")}...");
|
||||
if (!CacheServer.IsBikesOccupiedExpired
|
||||
|| fromCache)
|
||||
{
|
||||
// No need to query because previous answer is not yet outdated.
|
||||
var bikesOccupiedResponse = await CacheServer.GetBikesOccupiedAsync();
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Returning bikes occupied from cache.");
|
||||
return new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsMonkeyStore), bikesOccupiedResponse, bikesOccupiedResponse.GetGeneralData());
|
||||
}
|
||||
/// <summary> Gets a list of bikes reserved/ booked by acctive user. </summary>
|
||||
/// <param name="sessionCookie">Cookie to authenticate user.</param>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
public async Task<Result<BikesReservedOccupiedResponse>> GetBikesOccupied(bool fromCache = false)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to get bikes occupied{(fromCache ? " from cache" : "")}...");
|
||||
if (!CacheServer.IsBikesOccupiedExpired
|
||||
|| fromCache)
|
||||
{
|
||||
// No need to query because previous answer is not yet outdated.
|
||||
var bikesOccupiedResponse = await CacheServer.GetBikesOccupiedAsync();
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Returning bikes occupied from cache.");
|
||||
return new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsMonkeyStore), bikesOccupiedResponse, bikesOccupiedResponse.GetGeneralData());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Querrying bikes occupied from copri.");
|
||||
var bikesOccupiedResponse = await HttpsServer.GetBikesOccupiedAsync();
|
||||
return new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
bikesOccupiedResponse.GetIsResponseOk("Abfrage der reservierten/ gebuchten Räder fehlgeschlagen."),
|
||||
bikesOccupiedResponse.GetGeneralData());
|
||||
try
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Querrying bikes occupied from copri.");
|
||||
var bikesOccupiedResponse = await HttpsServer.GetBikesOccupiedAsync();
|
||||
return new Result<BikesReservedOccupiedResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
bikesOccupiedResponse.GetIsResponseOk("Abfrage der reservierten/ gebuchten Räder fehlgeschlagen."),
|
||||
bikesOccupiedResponse.GetGeneralData());
|
||||
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Return response from cache.
|
||||
Log.ForContext<CopriProviderHttps>().Debug("An error occurred querrying bikes occupied. {Exception}.", exception);
|
||||
var bikesOccupiedResponse = await CacheServer.GetBikesOccupiedAsync();
|
||||
return new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsMonkeyStore), bikesOccupiedResponse, bikesOccupiedResponse.GetGeneralData(), exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Return response from cache.
|
||||
Log.ForContext<CopriProviderHttps>().Debug("An error occurred querrying bikes occupied. {Exception}.", exception);
|
||||
var bikesOccupiedResponse = await CacheServer.GetBikesOccupiedAsync();
|
||||
return new Result<BikesReservedOccupiedResponse>(typeof(CopriCallsMonkeyStore), bikesOccupiedResponse, bikesOccupiedResponse.GetGeneralData(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Get list of stations. </summary>
|
||||
/// <returns>List of files.</returns>
|
||||
public async Task<Result<StationsAvailableResponse>> GetStations(bool fromCache = false)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to get stations{(fromCache ? " from cache" : "")}...");
|
||||
if (!CacheServer.IsStationsExpired
|
||||
|| fromCache)
|
||||
{
|
||||
// No need to query because previous answer is not yet outdated.
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Returning stations from cache.");
|
||||
var stationsResponse = await CacheServer.GetStationsAsync();
|
||||
return new Result<StationsAvailableResponse>(typeof(CopriCallsMonkeyStore), stationsResponse, stationsResponse.GetGeneralData());
|
||||
}
|
||||
/// <summary> Get list of stations. </summary>
|
||||
/// <returns>List of files.</returns>
|
||||
public async Task<Result<StationsAvailableResponse>> GetStations(bool fromCache = false)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to get stations{(fromCache ? " from cache" : "")}...");
|
||||
if (!CacheServer.IsStationsExpired
|
||||
|| fromCache)
|
||||
{
|
||||
// No need to query because previous answer is not yet outdated.
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Returning stations from cache.");
|
||||
var stationsResponse = await CacheServer.GetStationsAsync();
|
||||
return new Result<StationsAvailableResponse>(typeof(CopriCallsMonkeyStore), stationsResponse, stationsResponse.GetGeneralData());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Querrying stations from copri.");
|
||||
try
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Querrying stations from copri.");
|
||||
|
||||
var stations = await HttpsServer.GetStationsAsync();
|
||||
var stations = await HttpsServer.GetStationsAsync();
|
||||
|
||||
return new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
stations.GetIsResponseOk("Abfrage der Stationen fehlsgeschlagen."),
|
||||
stations.GetGeneralData());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Return response from cache.
|
||||
Log.ForContext<CopriProviderHttps>().Debug("An error occurred querrying stations. {Exception}.", exception);
|
||||
var stationsResponse = await CacheServer.GetStationsAsync();
|
||||
return new Result<StationsAvailableResponse>(typeof(CopriCallsMonkeyStore), stationsResponse, stationsResponse.GetGeneralData(), exception);
|
||||
}
|
||||
}
|
||||
return new Result<StationsAvailableResponse>(
|
||||
typeof(CopriCallsHttps),
|
||||
stations.GetIsResponseOk("Abfrage der Stationen fehlsgeschlagen."),
|
||||
stations.GetGeneralData());
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// Return response from cache.
|
||||
Log.ForContext<CopriProviderHttps>().Debug("An error occurred querrying stations. {Exception}.", exception);
|
||||
var stationsResponse = await CacheServer.GetStationsAsync();
|
||||
return new Result<StationsAvailableResponse>(typeof(CopriCallsMonkeyStore), stationsResponse, stationsResponse.GetGeneralData(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
/// <returns></returns>
|
||||
public void AddToCache(Result<StationsAvailableResponse> result)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to add stations all response to cache...");
|
||||
if (result.Source == typeof(CopriCallsMonkeyStore)
|
||||
|| result.Exception != null)
|
||||
{
|
||||
// Do not add responses form cache or invalid responses to cache.
|
||||
return;
|
||||
}
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
/// <returns></returns>
|
||||
public void AddToCache(Result<StationsAvailableResponse> result)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to add stations all response to cache...");
|
||||
if (result.Source == typeof(CopriCallsMonkeyStore)
|
||||
|| result.Exception != null)
|
||||
{
|
||||
// Do not add responses form cache or invalid responses to cache.
|
||||
return;
|
||||
}
|
||||
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Add bikes available response to cache.");
|
||||
CacheServer.AddToCache(result.Response);
|
||||
}
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Add bikes available response to cache.");
|
||||
CacheServer.AddToCache(result.Response);
|
||||
}
|
||||
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
/// <returns></returns>
|
||||
public void AddToCache(Result<BikesAvailableResponse> result)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to add bikes available response to cache...");
|
||||
if (result.Source == typeof(CopriCallsMonkeyStore)
|
||||
|| result.Exception != null)
|
||||
{
|
||||
// Do not add responses form cache or invalid responses to cache.
|
||||
return;
|
||||
}
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
/// <returns></returns>
|
||||
public void AddToCache(Result<BikesAvailableResponse> result)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to add bikes available response to cache...");
|
||||
if (result.Source == typeof(CopriCallsMonkeyStore)
|
||||
|| result.Exception != null)
|
||||
{
|
||||
// Do not add responses form cache or invalid responses to cache.
|
||||
return;
|
||||
}
|
||||
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Add bikes available response to cache.");
|
||||
CacheServer.AddToCache(result.Response);
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Add bikes available response to cache.");
|
||||
CacheServer.AddToCache(result.Response);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
/// <returns></returns>
|
||||
public void AddToCache(Result<BikesReservedOccupiedResponse> result)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to add bikes occupied response to cache...");
|
||||
if (result.Source == typeof(CopriCallsMonkeyStore)
|
||||
|| result.Exception != null)
|
||||
{
|
||||
// Do not add responses form cache or invalid responses to cache.
|
||||
return;
|
||||
}
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
/// <returns></returns>
|
||||
public void AddToCache(Result<BikesReservedOccupiedResponse> result)
|
||||
{
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Request to add bikes occupied response to cache...");
|
||||
if (result.Source == typeof(CopriCallsMonkeyStore)
|
||||
|| result.Exception != null)
|
||||
{
|
||||
// Do not add responses form cache or invalid responses to cache.
|
||||
return;
|
||||
}
|
||||
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Add bikes occupied response to cache.");
|
||||
CacheServer.AddToCache(result.Response);
|
||||
}
|
||||
Log.ForContext<CopriProviderHttps>().Debug($"Add bikes occupied response to cache.");
|
||||
CacheServer.AddToCache(result.Response);
|
||||
}
|
||||
|
||||
public async Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
|
||||
{
|
||||
return await HttpsServer.DoAuthorizationAsync(p_strMailAddress, p_strPassword, p_strDeviceId);
|
||||
}
|
||||
public async Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
|
||||
{
|
||||
return await HttpsServer.DoAuthorizationAsync(p_strMailAddress, p_strPassword, p_strDeviceId);
|
||||
}
|
||||
|
||||
public async Task<AuthorizationoutResponse> DoAuthoutAsync()
|
||||
{
|
||||
return await HttpsServer.DoAuthoutAsync();
|
||||
}
|
||||
public async Task<AuthorizationoutResponse> DoAuthoutAsync()
|
||||
{
|
||||
return await HttpsServer.DoAuthoutAsync();
|
||||
}
|
||||
|
||||
public async Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
return await HttpsServer.DoReserveAsync(bikeId, operatorUri);
|
||||
}
|
||||
public async Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
return await HttpsServer.DoReserveAsync(bikeId, operatorUri);
|
||||
}
|
||||
|
||||
public async Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
return await HttpsServer.DoCancelReservationAsync(bikeId, operatorUri);
|
||||
}
|
||||
public async Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
return await HttpsServer.DoCancelReservationAsync(bikeId, operatorUri);
|
||||
}
|
||||
|
||||
public async Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
return await HttpsServer.CalculateAuthKeysAsync(bikeId, operatorUri);
|
||||
}
|
||||
public async Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
return await HttpsServer.CalculateAuthKeysAsync(bikeId, operatorUri);
|
||||
}
|
||||
|
||||
public async Task<ResponseBase> StartReturningBike(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.StartReturningBike(bikeId, operatorUri);
|
||||
public async Task<ResponseBase> StartReturningBike(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.StartReturningBike(bikeId, operatorUri);
|
||||
|
||||
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
string bikeId,
|
||||
lock_state state,
|
||||
Uri operatorUri,
|
||||
LocationDto location,
|
||||
double batteryLevel)
|
||||
=> await HttpsServer.UpdateLockingStateAsync(
|
||||
bikeId,
|
||||
state,
|
||||
operatorUri,
|
||||
location,
|
||||
batteryLevel);
|
||||
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
string bikeId,
|
||||
lock_state state,
|
||||
Uri operatorUri,
|
||||
LocationDto location,
|
||||
double batteryLevel)
|
||||
=> await HttpsServer.UpdateLockingStateAsync(
|
||||
bikeId,
|
||||
state,
|
||||
operatorUri,
|
||||
location,
|
||||
batteryLevel);
|
||||
|
||||
/// <summary> Books a bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to book.</param>
|
||||
/// <param name="guid">Used to publish GUID from app to copri. Used for initial setup of bike in copri.</param>
|
||||
/// <param name="batteryPercentage">Holds the filling level percentage of the battery.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
public async Task<ReservationBookingResponse> DoBookAsync(string bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
|
||||
=> await HttpsServer.DoBookAsync(bikeId, guid, batteryPercentage, operatorUri);
|
||||
/// <summary> Books a bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to book.</param>
|
||||
/// <param name="guid">Used to publish GUID from app to copri. Used for initial setup of bike in copri.</param>
|
||||
/// <param name="batteryPercentage">Holds the filling level percentage of the battery.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
public async Task<ReservationBookingResponse> DoBookAsync(string bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
|
||||
=> await HttpsServer.DoBookAsync(bikeId, guid, batteryPercentage, operatorUri);
|
||||
|
||||
/// <summary> Books a bike and starts opening bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to book.</param>
|
||||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
public async Task<ReservationBookingResponse> BookAvailableAndStartOpeningAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.BookAvailableAndStartOpeningAsync(bikeId, operatorUri);
|
||||
/// <summary> Books a bike and starts opening bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to book.</param>
|
||||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
public async Task<ReservationBookingResponse> BookAvailableAndStartOpeningAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.BookAvailableAndStartOpeningAsync(bikeId, operatorUri);
|
||||
|
||||
/// <summary> Books a bike and starts opening bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to book.</param>
|
||||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
public async Task<ReservationBookingResponse> BookReservedAndStartOpeningAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.BookReservedAndStartOpeningAsync(bikeId, operatorUri);
|
||||
/// <summary> Books a bike and starts opening bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to book.</param>
|
||||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
public async Task<ReservationBookingResponse> BookReservedAndStartOpeningAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.BookReservedAndStartOpeningAsync(bikeId, operatorUri);
|
||||
|
||||
|
||||
public async Task<DoReturnResponse> DoReturn(
|
||||
string bikeId,
|
||||
LocationDto location,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.DoReturn(bikeId, location, smartDevice, operatorUri);
|
||||
public async Task<DoReturnResponse> DoReturn(
|
||||
string bikeId,
|
||||
LocationDto location,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.DoReturn(bikeId, location, smartDevice, operatorUri);
|
||||
|
||||
/// <summary> Returns a bike and starts closing. </summary>
|
||||
/// <param name="bikeId">Id of the bike to return.</param>
|
||||
/// <param name="smartDevice">Provides info about hard and software.</param>
|
||||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on returning request.</returns>
|
||||
public async Task<DoReturnResponse> ReturnAndStartClosingAsync(
|
||||
string bikeId,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.ReturnAndStartClosingAsync(bikeId, smartDevice, operatorUri);
|
||||
/// <summary> Returns a bike and starts closing. </summary>
|
||||
/// <param name="bikeId">Id of the bike to return.</param>
|
||||
/// <param name="smartDevice">Provides info about hard and software.</param>
|
||||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on returning request.</returns>
|
||||
public async Task<DoReturnResponse> ReturnAndStartClosingAsync(
|
||||
string bikeId,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.ReturnAndStartClosingAsync(bikeId, smartDevice, operatorUri);
|
||||
|
||||
/// <summary>
|
||||
/// Submits feedback to copri server.
|
||||
/// </summary>
|
||||
/// <param name="bikeId">Id of the bike to submit feedback for.</param>
|
||||
/// <param name="message">General purpose message or error description.</param>
|
||||
/// <param name="isBikeBroken">True if bike is broken.</param>
|
||||
public async Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string message, bool isBikeBroken, Uri opertorUri) =>
|
||||
await HttpsServer.DoSubmitFeedback(bikeId, currentChargeBars, message, isBikeBroken, opertorUri);
|
||||
/// <summary>
|
||||
/// Submits feedback to copri server.
|
||||
/// </summary>
|
||||
/// <param name="bikeId">Id of the bike to submit feedback for.</param>
|
||||
/// <param name="message">General purpose message or error description.</param>
|
||||
/// <param name="isBikeBroken">True if bike is broken.</param>
|
||||
public async Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string message, bool isBikeBroken, Uri opertorUri) =>
|
||||
await HttpsServer.DoSubmitFeedback(bikeId, currentChargeBars, message, isBikeBroken, opertorUri);
|
||||
|
||||
/// <summary> Submits mini survey to copri server. </summary>
|
||||
/// <param name="answers">Collection of answers.</param>
|
||||
public async Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
|
||||
=> await HttpsServer.DoSubmitMiniSurvey(answers);
|
||||
/// <summary> Submits mini survey to copri server. </summary>
|
||||
/// <param name="answers">Collection of answers.</param>
|
||||
public async Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
|
||||
=> await HttpsServer.DoSubmitMiniSurvey(answers);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,119 +8,119 @@ using TINK.Repository.Response;
|
|||
|
||||
namespace TINK.Model.Services.CopriApi
|
||||
{
|
||||
public class CopriProviderMonkeyStore : ICopriServer
|
||||
{
|
||||
/// <summary> Object which manages stored copri answers. </summary>
|
||||
private readonly CopriCallsMonkeyStore monkeyStore;
|
||||
public class CopriProviderMonkeyStore : ICopriServer
|
||||
{
|
||||
/// <summary> Object which manages stored copri answers. </summary>
|
||||
private readonly CopriCallsMonkeyStore monkeyStore;
|
||||
|
||||
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
|
||||
public bool IsConnected => monkeyStore.IsConnected;
|
||||
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
|
||||
public bool IsConnected => monkeyStore.IsConnected;
|
||||
|
||||
/// <summary> Gets the session cookie if user is logged in, an empty string otherwise. </summary>
|
||||
public string SessionCookie => monkeyStore.SessionCookie;
|
||||
/// <summary> Gets the session cookie if user is logged in, an empty string otherwise. </summary>
|
||||
public string SessionCookie => monkeyStore.SessionCookie;
|
||||
|
||||
/// <summary> Constructs object which Object which manages stored copri answers in a thread save way. </summary>
|
||||
/// <param name="merchantId">Id of the merchant TINK-App.</param>
|
||||
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
|
||||
public CopriProviderMonkeyStore(
|
||||
string merchantId,
|
||||
string uiIsoLangugageName,
|
||||
string sessionCookie)
|
||||
{
|
||||
monkeyStore = new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie);
|
||||
}
|
||||
/// <summary> Constructs object which Object which manages stored copri answers in a thread save way. </summary>
|
||||
/// <param name="merchantId">Id of the merchant TINK-App.</param>
|
||||
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
|
||||
public CopriProviderMonkeyStore(
|
||||
string merchantId,
|
||||
string uiIsoLangugageName,
|
||||
string sessionCookie)
|
||||
{
|
||||
monkeyStore = new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie);
|
||||
}
|
||||
|
||||
/// <summary> Gets the merchant id.</summary>
|
||||
public string MerchantId => monkeyStore.MerchantId;
|
||||
/// <summary> Gets the merchant id.</summary>
|
||||
public string MerchantId => monkeyStore.MerchantId;
|
||||
|
||||
public Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotSupportedException($"{nameof(DoReserveAsync)} is not cachable.");
|
||||
public Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotSupportedException($"{nameof(DoReserveAsync)} is not cachable.");
|
||||
|
||||
public Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotSupportedException($"{nameof(DoCancelReservationAsync)} is not cachable.");
|
||||
public Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotSupportedException($"{nameof(DoCancelReservationAsync)} is not cachable.");
|
||||
|
||||
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotSupportedException($"{nameof(CalculateAuthKeysAsync)} is not cachable.");
|
||||
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotSupportedException($"{nameof(CalculateAuthKeysAsync)} is not cachable.");
|
||||
|
||||
public async Task<ResponseBase> StartReturningBike(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.StartReturningBike(bikeId, operatorUri);
|
||||
public async Task<ResponseBase> StartReturningBike(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.StartReturningBike(bikeId, operatorUri);
|
||||
|
||||
|
||||
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
string bikeId,
|
||||
lock_state state,
|
||||
Uri operatorUri,
|
||||
LocationDto geolocation,
|
||||
double batteryLevel)
|
||||
=> await monkeyStore.UpdateLockingStateAsync(
|
||||
bikeId,
|
||||
state,
|
||||
operatorUri,
|
||||
geolocation,
|
||||
batteryLevel);
|
||||
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
string bikeId,
|
||||
lock_state state,
|
||||
Uri operatorUri,
|
||||
LocationDto geolocation,
|
||||
double batteryLevel)
|
||||
=> await monkeyStore.UpdateLockingStateAsync(
|
||||
bikeId,
|
||||
state,
|
||||
operatorUri,
|
||||
geolocation,
|
||||
batteryLevel);
|
||||
|
||||
public async Task<ReservationBookingResponse> DoBookAsync(string bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
|
||||
{
|
||||
return await monkeyStore.DoBookAsync(bikeId, guid, batteryPercentage, operatorUri);
|
||||
}
|
||||
public async Task<ReservationBookingResponse> DoBookAsync(string bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
|
||||
{
|
||||
return await monkeyStore.DoBookAsync(bikeId, guid, batteryPercentage, operatorUri);
|
||||
}
|
||||
|
||||
public async Task<ReservationBookingResponse> BookAvailableAndStartOpeningAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.BookAvailableAndStartOpeningAsync(bikeId, operatorUri);
|
||||
public async Task<ReservationBookingResponse> BookAvailableAndStartOpeningAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.BookAvailableAndStartOpeningAsync(bikeId, operatorUri);
|
||||
|
||||
public async Task<ReservationBookingResponse> BookReservedAndStartOpeningAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.BookReservedAndStartOpeningAsync(bikeId, operatorUri);
|
||||
public async Task<ReservationBookingResponse> BookReservedAndStartOpeningAsync(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.BookReservedAndStartOpeningAsync(bikeId, operatorUri);
|
||||
|
||||
public async Task<DoReturnResponse> DoReturn(
|
||||
string bikeId,
|
||||
LocationDto geolocation,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.DoReturn(bikeId, geolocation, smartDevice, operatorUri);
|
||||
public async Task<DoReturnResponse> DoReturn(
|
||||
string bikeId,
|
||||
LocationDto geolocation,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.DoReturn(bikeId, geolocation, smartDevice, operatorUri);
|
||||
|
||||
public async Task<DoReturnResponse> ReturnAndStartClosingAsync(
|
||||
string bikeId,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.ReturnAndStartClosingAsync(bikeId, smartDevice, operatorUri);
|
||||
public async Task<DoReturnResponse> ReturnAndStartClosingAsync(
|
||||
string bikeId,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.ReturnAndStartClosingAsync(bikeId, smartDevice, operatorUri);
|
||||
|
||||
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string messge, bool bIsBikeBroke, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string messge, bool bIsBikeBroke, Uri operatorUri)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
/// <summary> Submits mini survey to copri server. </summary>
|
||||
/// <param name="answers">Collection of answers.</param>
|
||||
public Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
|
||||
=> throw new NotSupportedException();
|
||||
/// <summary> Submits mini survey to copri server. </summary>
|
||||
/// <param name="answers">Collection of answers.</param>
|
||||
public Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
|
||||
public async Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
|
||||
{
|
||||
return await monkeyStore.DoAuthorizationAsync(p_strMailAddress, p_strPassword, p_strDeviceId);
|
||||
}
|
||||
public async Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
|
||||
{
|
||||
return await monkeyStore.DoAuthorizationAsync(p_strMailAddress, p_strPassword, p_strDeviceId);
|
||||
}
|
||||
|
||||
public async Task<AuthorizationoutResponse> DoAuthoutAsync()
|
||||
{
|
||||
return await monkeyStore.DoAuthoutAsync();
|
||||
}
|
||||
public async Task<AuthorizationoutResponse> DoAuthoutAsync()
|
||||
{
|
||||
return await monkeyStore.DoAuthoutAsync();
|
||||
}
|
||||
|
||||
public async Task<BikesAvailableResponse> GetBikesAvailableAsync()
|
||||
{
|
||||
return await monkeyStore.GetBikesAvailableAsync();
|
||||
}
|
||||
public async Task<BikesAvailableResponse> GetBikesAvailableAsync()
|
||||
{
|
||||
return await monkeyStore.GetBikesAvailableAsync();
|
||||
}
|
||||
|
||||
public async Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync()
|
||||
{
|
||||
return await monkeyStore.GetBikesOccupiedAsync();
|
||||
}
|
||||
public async Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync()
|
||||
{
|
||||
return await monkeyStore.GetBikesOccupiedAsync();
|
||||
}
|
||||
|
||||
public async Task<StationsAvailableResponse> GetStationsAsync()
|
||||
{
|
||||
return await monkeyStore.GetStationsAsync();
|
||||
}
|
||||
}
|
||||
public async Task<StationsAvailableResponse> GetStationsAsync()
|
||||
{
|
||||
return await monkeyStore.GetStationsAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
namespace TINK.Services.CopriApi.Exception
|
||||
{
|
||||
public class BikeStillInStationException : System.Exception
|
||||
{
|
||||
public BikeStillInStationException(string message) : base(message) { }
|
||||
}
|
||||
public class BikeStillInStationException : System.Exception
|
||||
{
|
||||
public BikeStillInStationException(string message) : base(message) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,34 +4,34 @@ using TINK.Model.Map;
|
|||
|
||||
namespace TINK.Services.CopriApi
|
||||
{
|
||||
/// <summary> Holds general purpose data returned from COPRI. </summary>
|
||||
public class GeneralData
|
||||
{
|
||||
/// <summary> Constructs an empty general data object. </summary>
|
||||
public GeneralData() : this(null, null, null, null) { }
|
||||
/// <summary> Holds general purpose data returned from COPRI. </summary>
|
||||
public class GeneralData
|
||||
{
|
||||
/// <summary> Constructs an empty general data object. </summary>
|
||||
public GeneralData() : this(null, null, null, null) { }
|
||||
|
||||
public GeneralData(
|
||||
IMapSpan initialMapSpan,
|
||||
string merachantMessage,
|
||||
Version apiVersion,
|
||||
ResourceUrls resourceUrls)
|
||||
{
|
||||
InitialMapSpan = initialMapSpan ?? MapSpanFactory.Create();
|
||||
MerchantMessage = merachantMessage ?? string.Empty;
|
||||
ApiVersion = apiVersion ?? new Version(0, 0);
|
||||
ResourceUrls = resourceUrls ?? new ResourceUrls();
|
||||
}
|
||||
public GeneralData(
|
||||
IMapSpan initialMapSpan,
|
||||
string merachantMessage,
|
||||
Version apiVersion,
|
||||
ResourceUrls resourceUrls)
|
||||
{
|
||||
InitialMapSpan = initialMapSpan ?? MapSpanFactory.Create();
|
||||
MerchantMessage = merachantMessage ?? string.Empty;
|
||||
ApiVersion = apiVersion ?? new Version(0, 0);
|
||||
ResourceUrls = resourceUrls ?? new ResourceUrls();
|
||||
}
|
||||
|
||||
/// <summary> Initial map display area.</summary>
|
||||
public IMapSpan InitialMapSpan { get; private set; }
|
||||
/// <summary> Initial map display area.</summary>
|
||||
public IMapSpan InitialMapSpan { get; private set; }
|
||||
|
||||
/// <summary> Message to be shown to user.</summary>
|
||||
public string MerchantMessage { get; private set; }
|
||||
/// <summary> Message to be shown to user.</summary>
|
||||
public string MerchantMessage { get; private set; }
|
||||
|
||||
/// <summary> Version of COPRI api. 0.0 if version is not set</summary>
|
||||
public Version ApiVersion { get; private set; }
|
||||
/// <summary> Version of COPRI api. 0.0 if version is not set</summary>
|
||||
public Version ApiVersion { get; private set; }
|
||||
|
||||
/// <summary> Resources (html pages) to be displayed provided by COPRI.</summary>
|
||||
public IResourceUrls ResourceUrls { get; private set; }
|
||||
}
|
||||
/// <summary> Resources (html pages) to be displayed provided by COPRI.</summary>
|
||||
public IResourceUrls ResourceUrls { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,32 +5,32 @@ using TINK.Repository.Response;
|
|||
|
||||
namespace TINK.Model.Services.CopriApi
|
||||
{
|
||||
/// <summary> Manages cache which holds copri data.</summary>
|
||||
public interface ICachedCopriServer : ICopriServerBase
|
||||
{
|
||||
/// <summary> Get list of stations. </summary>
|
||||
/// <returns>List of all stations.</returns>
|
||||
Task<Result<StationsAvailableResponse>> GetStations(bool fromCache = false);
|
||||
/// <summary> Manages cache which holds copri data.</summary>
|
||||
public interface ICachedCopriServer : ICopriServerBase
|
||||
{
|
||||
/// <summary> Get list of stations. </summary>
|
||||
/// <returns>List of all stations.</returns>
|
||||
Task<Result<StationsAvailableResponse>> GetStations(bool fromCache = false);
|
||||
|
||||
/// <summary> Gets a list of bikes from Copri. </summary>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
Task<Result<BikesAvailableResponse>> GetBikesAvailable(bool fromCache = false);
|
||||
/// <summary> Gets a list of bikes from Copri. </summary>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
Task<Result<BikesAvailableResponse>> GetBikesAvailable(bool fromCache = false);
|
||||
|
||||
/// <summary> Gets a list of bikes reserved/ booked by acctive user from Copri.</summary>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
Task<Result<BikesReservedOccupiedResponse>> GetBikesOccupied(bool fromCache = false);
|
||||
/// <summary> Gets a list of bikes reserved/ booked by acctive user from Copri.</summary>
|
||||
/// <returns>Response holding list of bikes.</returns>
|
||||
Task<Result<BikesReservedOccupiedResponse>> GetBikesOccupied(bool fromCache = false);
|
||||
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
void AddToCache(Result<StationsAvailableResponse> result);
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
void AddToCache(Result<StationsAvailableResponse> result);
|
||||
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
void AddToCache(Result<BikesAvailableResponse> result);
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
void AddToCache(Result<BikesAvailableResponse> result);
|
||||
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
/// <returns></returns>
|
||||
void AddToCache(Result<BikesReservedOccupiedResponse> result);
|
||||
}
|
||||
/// <summary>Adds https--response to cache if response is ok. </summary>
|
||||
/// <param name="response">Response to add to cache.</param>
|
||||
/// <returns></returns>
|
||||
void AddToCache(Result<BikesReservedOccupiedResponse> result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,27 +3,27 @@ using TINK.Repository.Response;
|
|||
|
||||
namespace TINK.Model.Services.CopriApi
|
||||
{
|
||||
public interface ICopriCache : ICopriServer
|
||||
{
|
||||
/// <summary> Gets a value indicating whether stations are expired or not.</summary>
|
||||
bool IsStationsExpired { get; }
|
||||
public interface ICopriCache : ICopriServer
|
||||
{
|
||||
/// <summary> Gets a value indicating whether stations are expired or not.</summary>
|
||||
bool IsStationsExpired { get; }
|
||||
|
||||
/// <summary> Adds a stations all response to cache.</summary>
|
||||
/// <param name="stations">Stations to add.</param>
|
||||
void AddToCache(StationsAvailableResponse stations);
|
||||
/// <summary> Adds a stations all response to cache.</summary>
|
||||
/// <param name="stations">Stations to add.</param>
|
||||
void AddToCache(StationsAvailableResponse stations);
|
||||
|
||||
/// <summary> Gets a value indicating whether stations are expired or not.</summary>
|
||||
bool IsBikesAvailableExpired { get; }
|
||||
/// <summary> Gets a value indicating whether stations are expired or not.</summary>
|
||||
bool IsBikesAvailableExpired { get; }
|
||||
|
||||
/// <summary> Adds a bikes response to cache.</summary>
|
||||
/// <param name="bikes">Bikes to add.</param>
|
||||
void AddToCache(BikesAvailableResponse bikes);
|
||||
/// <summary> Adds a bikes response to cache.</summary>
|
||||
/// <param name="bikes">Bikes to add.</param>
|
||||
void AddToCache(BikesAvailableResponse bikes);
|
||||
|
||||
/// <summary> Gets a value indicating whether stations are expired or not.</summary>
|
||||
bool IsBikesOccupiedExpired { get; }
|
||||
/// <summary> Gets a value indicating whether stations are expired or not.</summary>
|
||||
bool IsBikesOccupiedExpired { get; }
|
||||
|
||||
/// <summary> Adds a bikes response to cache.</summary>
|
||||
/// <param name="bikes">Bikes to add.</param>
|
||||
void AddToCache(BikesReservedOccupiedResponse bikes);
|
||||
}
|
||||
/// <summary> Adds a bikes response to cache.</summary>
|
||||
/// <param name="bikes">Bikes to add.</param>
|
||||
void AddToCache(BikesReservedOccupiedResponse bikes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,230 +15,230 @@ using TINK.Services.CopriApi.Exception;
|
|||
|
||||
namespace TINK.Services.CopriApi
|
||||
{
|
||||
public static class Polling
|
||||
{
|
||||
/// <summary> Timeout for open/ close operations.</summary>
|
||||
private const int OPEN_CLOSE_TIMEOUT_MS = 50000;
|
||||
public static class Polling
|
||||
{
|
||||
/// <summary> Timeout for open/ close operations.</summary>
|
||||
private const int OPEN_CLOSE_TIMEOUT_MS = 50000;
|
||||
|
||||
/// <summary> Opens lock.</summary>
|
||||
/// <param name="corpiServer"> Instance to communicate with backend.</param>
|
||||
/// <param name="bike">Bike object holding id of bike to open. Lock state of object is updated after open request.</param>
|
||||
public static async Task OpenAync(
|
||||
this ICopriServerBase corpiServer,
|
||||
IBikeInfoMutable bike)
|
||||
{
|
||||
if (!(corpiServer is ICachedCopriServer cachedServer))
|
||||
throw new ArgumentNullException(nameof(corpiServer));
|
||||
/// <summary> Opens lock.</summary>
|
||||
/// <param name="corpiServer"> Instance to communicate with backend.</param>
|
||||
/// <param name="bike">Bike object holding id of bike to open. Lock state of object is updated after open request.</param>
|
||||
public static async Task OpenAync(
|
||||
this ICopriServerBase corpiServer,
|
||||
IBikeInfoMutable bike)
|
||||
{
|
||||
if (!(corpiServer is ICachedCopriServer cachedServer))
|
||||
throw new ArgumentNullException(nameof(corpiServer));
|
||||
|
||||
// Send command to close lock
|
||||
await corpiServer.UpdateLockingStateAsync(
|
||||
bike.Id,
|
||||
Repository.Request.lock_state.unlocking,
|
||||
bike.OperatorUri);
|
||||
// Send command to close lock
|
||||
await corpiServer.UpdateLockingStateAsync(
|
||||
bike.Id,
|
||||
Repository.Request.lock_state.unlocking,
|
||||
bike.OperatorUri);
|
||||
|
||||
var lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
var lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
while (lockingState != LockingState.Open
|
||||
&& lockingState != LockingState.UnknownDisconnected
|
||||
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
|
||||
{
|
||||
// Delay a litte to reduce load on backend.
|
||||
await Task.Delay(3000);
|
||||
while (lockingState != LockingState.Open
|
||||
&& lockingState != LockingState.UnknownDisconnected
|
||||
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
|
||||
{
|
||||
// Delay a litte to reduce load on backend.
|
||||
await Task.Delay(3000);
|
||||
|
||||
lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
Log.Information($"Current lock state is {lockingState}.");
|
||||
}
|
||||
lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
Log.Information($"Current lock state is {lockingState}.");
|
||||
}
|
||||
|
||||
// Update locking state.
|
||||
bike.LockInfo.State = lockingState;
|
||||
}
|
||||
// Update locking state.
|
||||
bike.LockInfo.State = lockingState;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Books a bike and opens the lock.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer"> Instance to communicate with backend.</param>
|
||||
/// <param name="bike">Bike to book and open.</param>
|
||||
/// <param name="mailAddress">Mail address of user which books bike.</param>
|
||||
public static async Task BookAndOpenAync(
|
||||
this ICopriServerBase corpiServer,
|
||||
IBikeInfoMutable bike,
|
||||
string mailAddress)
|
||||
{
|
||||
if (bike == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(bike), "Can not book bike and open lock. No bike object available.");
|
||||
}
|
||||
/// <summary>
|
||||
/// Books a bike and opens the lock.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer"> Instance to communicate with backend.</param>
|
||||
/// <param name="bike">Bike to book and open.</param>
|
||||
/// <param name="mailAddress">Mail address of user which books bike.</param>
|
||||
public static async Task BookAndOpenAync(
|
||||
this ICopriServerBase corpiServer,
|
||||
IBikeInfoMutable bike,
|
||||
string mailAddress)
|
||||
{
|
||||
if (bike == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(bike), "Can not book bike and open lock. No bike object available.");
|
||||
}
|
||||
|
||||
if (!(corpiServer is ICachedCopriServer cachedServer))
|
||||
throw new ArgumentNullException(nameof(corpiServer));
|
||||
if (!(corpiServer is ICachedCopriServer cachedServer))
|
||||
throw new ArgumentNullException(nameof(corpiServer));
|
||||
|
||||
// Send command to open lock
|
||||
var response = bike.State.Value == Model.State.InUseStateEnum.Disposable
|
||||
? (await corpiServer.BookAvailableAndStartOpeningAsync(bike.Id, bike.OperatorUri)).GetIsBookingResponseOk(bike.Id)
|
||||
: (await corpiServer.BookReservedAndStartOpeningAsync(bike.Id, bike.OperatorUri)).GetIsBookingResponseOk(bike.Id);
|
||||
// Send command to open lock
|
||||
var response = bike.State.Value == Model.State.InUseStateEnum.Disposable
|
||||
? (await corpiServer.BookAvailableAndStartOpeningAsync(bike.Id, bike.OperatorUri)).GetIsBookingResponseOk(bike.Id)
|
||||
: (await corpiServer.BookReservedAndStartOpeningAsync(bike.Id, bike.OperatorUri)).GetIsBookingResponseOk(bike.Id);
|
||||
|
||||
// Upated locking state.
|
||||
var lockingState = await cachedServer.GetOccupiedBikeLockStateAsync(bike.Id);
|
||||
// Upated locking state.
|
||||
var lockingState = await cachedServer.GetOccupiedBikeLockStateAsync(bike.Id);
|
||||
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
while (lockingState.HasValue /* if null bike is no more occupied*/ &&
|
||||
lockingState.Value != LockingState.Open
|
||||
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
|
||||
{
|
||||
// Delay a litte to reduce load on backend.
|
||||
await Task.Delay(3000);
|
||||
while (lockingState.HasValue /* if null bike is no more occupied*/ &&
|
||||
lockingState.Value != LockingState.Open
|
||||
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
|
||||
{
|
||||
// Delay a litte to reduce load on backend.
|
||||
await Task.Delay(3000);
|
||||
|
||||
lockingState = await cachedServer.GetOccupiedBikeLockStateAsync(bike.Id);
|
||||
Log.Debug($"Current lock state of bike {bike.Id} is {(lockingState.HasValue ? lockingState.Value.ToString() : "-")}.");
|
||||
}
|
||||
lockingState = await cachedServer.GetOccupiedBikeLockStateAsync(bike.Id);
|
||||
Log.Debug($"Current lock state of bike {bike.Id} is {(lockingState.HasValue ? lockingState.Value.ToString() : "-")}.");
|
||||
}
|
||||
|
||||
// Check if bike is still occupied.
|
||||
if (lockingState == null)
|
||||
{
|
||||
// User did not take bike out of the station
|
||||
throw new BikeStillInStationException("Booking was cancelled because bike is still in station.");
|
||||
}
|
||||
// Check if bike is still occupied.
|
||||
if (lockingState == null)
|
||||
{
|
||||
// User did not take bike out of the station
|
||||
throw new BikeStillInStationException("Booking was cancelled because bike is still in station.");
|
||||
}
|
||||
|
||||
// Upate booking state.
|
||||
bike.Load(
|
||||
response,
|
||||
mailAddress,
|
||||
Model.Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.None);
|
||||
// Upate booking state.
|
||||
bike.Load(
|
||||
response,
|
||||
mailAddress,
|
||||
Model.Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.None);
|
||||
|
||||
// Update locking state.
|
||||
bike.LockInfo.State = lockingState.Value;
|
||||
}
|
||||
// Update locking state.
|
||||
bike.LockInfo.State = lockingState.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a bike and closes the lock.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer"> Instance to communicate with backend.</param>
|
||||
/// <param name="bike">Bike to close.</param>
|
||||
public static async Task CloseAync(
|
||||
this ICopriServerBase corpiServer,
|
||||
IBikeInfoMutable bike)
|
||||
{
|
||||
if (!(corpiServer is ICachedCopriServer cachedServer))
|
||||
throw new ArgumentNullException(nameof(corpiServer));
|
||||
/// <summary>
|
||||
/// Returns a bike and closes the lock.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer"> Instance to communicate with backend.</param>
|
||||
/// <param name="bike">Bike to close.</param>
|
||||
public static async Task CloseAync(
|
||||
this ICopriServerBase corpiServer,
|
||||
IBikeInfoMutable bike)
|
||||
{
|
||||
if (!(corpiServer is ICachedCopriServer cachedServer))
|
||||
throw new ArgumentNullException(nameof(corpiServer));
|
||||
|
||||
// Send command to close lock
|
||||
await corpiServer.UpdateLockingStateAsync(
|
||||
bike.Id,
|
||||
Repository.Request.lock_state.locking,
|
||||
bike.OperatorUri);
|
||||
// Send command to close lock
|
||||
await corpiServer.UpdateLockingStateAsync(
|
||||
bike.Id,
|
||||
Repository.Request.lock_state.locking,
|
||||
bike.OperatorUri);
|
||||
|
||||
var lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
var lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
while (lockingState != LockingState.Closed
|
||||
&& lockingState != LockingState.UnknownDisconnected
|
||||
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
|
||||
{
|
||||
// Delay a litte to reduce load on backend.
|
||||
await Task.Delay(3000);
|
||||
while (lockingState != LockingState.Closed
|
||||
&& lockingState != LockingState.UnknownDisconnected
|
||||
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
|
||||
{
|
||||
// Delay a litte to reduce load on backend.
|
||||
await Task.Delay(3000);
|
||||
|
||||
lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
Log.Information($"Current lock state is {lockingState}.");
|
||||
}
|
||||
lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
Log.Information($"Current lock state is {lockingState}.");
|
||||
}
|
||||
|
||||
// Update locking state.
|
||||
bike.LockInfo.State = lockingState;
|
||||
}
|
||||
// Update locking state.
|
||||
bike.LockInfo.State = lockingState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a bike and closes the lock.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer"> Instance to communicate with backend.</param>
|
||||
/// <param name="smartDevice">Smart device on which app runs on.</param>
|
||||
/// <param name="mailAddress">Mail address of user which books bike.</param>
|
||||
public static async Task<BookingFinishedModel> ReturnAndCloseAync(
|
||||
this ICopriServerBase corpiServer,
|
||||
ISmartDevice smartDevice,
|
||||
IBikeInfoMutable bike)
|
||||
{
|
||||
if (!(corpiServer is ICachedCopriServer cachedServer))
|
||||
throw new ArgumentNullException(nameof(corpiServer));
|
||||
/// <summary>
|
||||
/// Returns a bike and closes the lock.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer"> Instance to communicate with backend.</param>
|
||||
/// <param name="smartDevice">Smart device on which app runs on.</param>
|
||||
/// <param name="mailAddress">Mail address of user which books bike.</param>
|
||||
public static async Task<BookingFinishedModel> ReturnAndCloseAync(
|
||||
this ICopriServerBase corpiServer,
|
||||
ISmartDevice smartDevice,
|
||||
IBikeInfoMutable bike)
|
||||
{
|
||||
if (!(corpiServer is ICachedCopriServer cachedServer))
|
||||
throw new ArgumentNullException(nameof(corpiServer));
|
||||
|
||||
// Send command to open lock
|
||||
DoReturnResponse response =
|
||||
await corpiServer.ReturnAndStartClosingAsync(bike.Id, smartDevice, bike.OperatorUri);
|
||||
// Send command to open lock
|
||||
DoReturnResponse response =
|
||||
await corpiServer.ReturnAndStartClosingAsync(bike.Id, smartDevice, bike.OperatorUri);
|
||||
|
||||
// Upate booking state
|
||||
bike.Load(Model.Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.None);
|
||||
// Upate booking state
|
||||
bike.Load(Model.Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.None);
|
||||
|
||||
var lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
var lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
var watch = new Stopwatch();
|
||||
watch.Start();
|
||||
|
||||
while (lockingState != LockingState.Closed
|
||||
&& lockingState != LockingState.UnknownDisconnected
|
||||
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
|
||||
{
|
||||
// Delay a litte to reduce load on backend.
|
||||
await Task.Delay(3000);
|
||||
while (lockingState != LockingState.Closed
|
||||
&& lockingState != LockingState.UnknownDisconnected
|
||||
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
|
||||
{
|
||||
// Delay a litte to reduce load on backend.
|
||||
await Task.Delay(3000);
|
||||
|
||||
lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
Log.Information($"Current lock state is {lockingState}.");
|
||||
}
|
||||
lockingState = await cachedServer.GetLockStateAsync(bike.Id);
|
||||
Log.Information($"Current lock state is {lockingState}.");
|
||||
}
|
||||
|
||||
// Update locking state.
|
||||
bike.LockInfo.State = lockingState;
|
||||
// Update locking state.
|
||||
bike.LockInfo.State = lockingState;
|
||||
|
||||
return response?.Create() ?? new BookingFinishedModel();
|
||||
}
|
||||
return response?.Create() ?? new BookingFinishedModel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queries the locking state from copri.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer">Service to use.</param>
|
||||
/// <param name="bikeId">Bike id to query lock state for.</param>
|
||||
/// <returns>Locking state</returns>
|
||||
private static async Task<LockingState> GetLockStateAsync(
|
||||
this ICachedCopriServer corpiServer,
|
||||
string bikeId)
|
||||
{
|
||||
// Querry reserved or booked bikes first for performance reasons.
|
||||
var bikeReservedOrBooked = (await corpiServer.GetBikesOccupied(false))?.Response.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
|
||||
if (bikeReservedOrBooked != null)
|
||||
{
|
||||
return bikeReservedOrBooked.GetCopriLockingState();
|
||||
}
|
||||
/// <summary>
|
||||
/// Queries the locking state from copri.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer">Service to use.</param>
|
||||
/// <param name="bikeId">Bike id to query lock state for.</param>
|
||||
/// <returns>Locking state</returns>
|
||||
private static async Task<LockingState> GetLockStateAsync(
|
||||
this ICachedCopriServer corpiServer,
|
||||
string bikeId)
|
||||
{
|
||||
// Querry reserved or booked bikes first for performance reasons.
|
||||
var bikeReservedOrBooked = (await corpiServer.GetBikesOccupied(false))?.Response.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
|
||||
if (bikeReservedOrBooked != null)
|
||||
{
|
||||
return bikeReservedOrBooked.GetCopriLockingState();
|
||||
}
|
||||
|
||||
var bikeAvailable = (await corpiServer.GetBikesAvailable(false))?.Response.bikes?.Values?.FirstOrDefault(x => x.bike == bikeId);
|
||||
if (bikeAvailable != null)
|
||||
{
|
||||
return bikeAvailable.GetCopriLockingState();
|
||||
}
|
||||
var bikeAvailable = (await corpiServer.GetBikesAvailable(false))?.Response.bikes?.Values?.FirstOrDefault(x => x.bike == bikeId);
|
||||
if (bikeAvailable != null)
|
||||
{
|
||||
return bikeAvailable.GetCopriLockingState();
|
||||
}
|
||||
|
||||
return LockingState.UnknownDisconnected;
|
||||
}
|
||||
return LockingState.UnknownDisconnected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queries the locking state of a occupied bike from copri.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer">Service to use.</param>
|
||||
/// <param name="bikeId">Bike id to query lock state for.</param>
|
||||
/// <returns>Locking state if bike is still occupied, null otherwise.</returns>
|
||||
private static async Task<LockingState?> GetOccupiedBikeLockStateAsync(
|
||||
this ICachedCopriServer corpiServer,
|
||||
string bikeId)
|
||||
{
|
||||
var bikeReservedOrBooked = (await corpiServer.GetBikesOccupied(false))?.Response.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
|
||||
if (bikeReservedOrBooked != null)
|
||||
{
|
||||
return bikeReservedOrBooked.GetCopriLockingState();
|
||||
}
|
||||
/// <summary>
|
||||
/// Queries the locking state of a occupied bike from copri.
|
||||
/// </summary>
|
||||
/// <param name="corpiServer">Service to use.</param>
|
||||
/// <param name="bikeId">Bike id to query lock state for.</param>
|
||||
/// <returns>Locking state if bike is still occupied, null otherwise.</returns>
|
||||
private static async Task<LockingState?> GetOccupiedBikeLockStateAsync(
|
||||
this ICachedCopriServer corpiServer,
|
||||
string bikeId)
|
||||
{
|
||||
var bikeReservedOrBooked = (await corpiServer.GetBikesOccupied(false))?.Response.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
|
||||
if (bikeReservedOrBooked != null)
|
||||
{
|
||||
return bikeReservedOrBooked.GetCopriLockingState();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,36 +3,36 @@ using TINK.Services.CopriApi;
|
|||
|
||||
namespace TINK.Model.Services.CopriApi
|
||||
{
|
||||
public class Result<T> where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a result object.
|
||||
/// </summary>
|
||||
/// <param name="source">Type of source (data provider).</param>
|
||||
/// <param name="response">Requested data (bikes, station).</param>
|
||||
/// <param name="generalData">General data (common to all respones).</param>
|
||||
public Result(
|
||||
Type source,
|
||||
T response,
|
||||
GeneralData generalData,
|
||||
Exception exception = null)
|
||||
{
|
||||
Source = source ?? throw new ArgumentException(nameof(source));
|
||||
Response = response ?? throw new ArgumentException(nameof(response));
|
||||
GeneralData = generalData ?? new GeneralData();
|
||||
Exception = exception;
|
||||
}
|
||||
public class Result<T> where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a result object.
|
||||
/// </summary>
|
||||
/// <param name="source">Type of source (data provider).</param>
|
||||
/// <param name="response">Requested data (bikes, station).</param>
|
||||
/// <param name="generalData">General data (common to all respones).</param>
|
||||
public Result(
|
||||
Type source,
|
||||
T response,
|
||||
GeneralData generalData,
|
||||
Exception exception = null)
|
||||
{
|
||||
Source = source ?? throw new ArgumentException(nameof(source));
|
||||
Response = response ?? throw new ArgumentException(nameof(response));
|
||||
GeneralData = generalData ?? new GeneralData();
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
/// <summary> Holds the requested data (bikes, stations and bikes).</summary>
|
||||
public T Response { get; }
|
||||
/// <summary> Holds the requested data (bikes, stations and bikes).</summary>
|
||||
public T Response { get; }
|
||||
|
||||
/// <summary> Holds the general purpose data (common to all responses).</summary>
|
||||
public GeneralData GeneralData { get; }
|
||||
/// <summary> Holds the general purpose data (common to all responses).</summary>
|
||||
public GeneralData GeneralData { get; }
|
||||
|
||||
/// <summary> Specifies the source (type of provider) of the copri response.</summary>
|
||||
public Type Source { get; }
|
||||
/// <summary> Specifies the source (type of provider) of the copri response.</summary>
|
||||
public Type Source { get; }
|
||||
|
||||
/// <summary> Holds the exception if a communication error occurred.</summary>
|
||||
public Exception Exception { get; private set; }
|
||||
}
|
||||
/// <summary> Holds the exception if a communication error occurred.</summary>
|
||||
public Exception Exception { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,15 @@ using TINK.Model.Services.CopriApi.ServerUris;
|
|||
|
||||
namespace TINK.Services.CopriApi.ServerUris
|
||||
{
|
||||
public static class CopriHelper
|
||||
{
|
||||
public const string SHAREE_SILTEFOLDERNAME = "site";
|
||||
public static class CopriHelper
|
||||
{
|
||||
public const string SHAREE_SILTEFOLDERNAME = "site";
|
||||
|
||||
/// <summary> Gets a value indicating whether a host is copri or not. </summary>
|
||||
/// <param name="hostName">Host name.</param>
|
||||
/// <returns>True if server is copri, fals if not.</returns>
|
||||
public static bool GetIsCopri(this string hostName)
|
||||
=> new Uri(CopriServerUriList.TINK_DEVEL).Host == hostName
|
||||
|| new Uri(CopriServerUriList.TINK_LIVE).Host == hostName;
|
||||
}
|
||||
/// <summary> Gets a value indicating whether a host is copri or not. </summary>
|
||||
/// <param name="hostName">Host name.</param>
|
||||
/// <returns>True if server is copri, fals if not.</returns>
|
||||
public static bool GetIsCopri(this string hostName)
|
||||
=> new Uri(CopriServerUriList.TINK_DEVEL).Host == hostName
|
||||
|| new Uri(CopriServerUriList.TINK_LIVE).Host == hostName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,88 +5,88 @@ using Newtonsoft.Json;
|
|||
|
||||
namespace TINK.Model.Services.CopriApi.ServerUris
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
sealed public class CopriServerUriList
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the rest resource root name.
|
||||
/// </summary>
|
||||
public const string REST_RESOURCE_ROOT = "APIjsonserver";
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
sealed public class CopriServerUriList
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the rest resource root name.
|
||||
/// </summary>
|
||||
public const string REST_RESOURCE_ROOT = "APIjsonserver";
|
||||
|
||||
/// <summary> Holds the URL of the TINK/Konrad test server.</summary>
|
||||
public const string TINK_DEVEL = @"https://tinkwwp.copri-bike.de/APIjsonserver";
|
||||
/// <summary> Holds the URL of the TINK/Konrad test server.</summary>
|
||||
public const string TINK_DEVEL = @"https://tinkwwp.copri-bike.de/APIjsonserver";
|
||||
|
||||
/// <summary> Holds the URL the TINK/Konrad productive server.</summary>
|
||||
public const string TINK_LIVE = @"https://app.tink-konstanz.de/APIjsonserver";
|
||||
/// <summary> Holds the URL the TINK/Konrad productive server.</summary>
|
||||
public const string TINK_LIVE = @"https://app.tink-konstanz.de/APIjsonserver";
|
||||
|
||||
/// <summary> Holds the URL the Sharee server.</summary>
|
||||
public const string SHAREE_DEVEL = @"https://shareeapp-primary.copri-bike.de/APIjsonserver";
|
||||
/// <summary> Holds the URL the Sharee server.</summary>
|
||||
public const string SHAREE_DEVEL = @"https://shareeapp-primary.copri-bike.de/APIjsonserver";
|
||||
|
||||
/// <summary> Holds the URL the Sharee server.</summary>
|
||||
public const string SHAREE_LIVE = @"https://shareeapp-primary.copri.eu/APIjsonserver";
|
||||
/// <summary> Holds the URL the Sharee server.</summary>
|
||||
public const string SHAREE_LIVE = @"https://shareeapp-primary.copri.eu/APIjsonserver";
|
||||
|
||||
/// <summary>Constructs default uri list.</summary>
|
||||
public CopriServerUriList(Uri activeUri = null) : this(
|
||||
new List<Uri>
|
||||
{
|
||||
new Uri(SHAREE_LIVE),
|
||||
new Uri(TINK_LIVE),
|
||||
new Uri(SHAREE_DEVEL),
|
||||
new Uri(TINK_DEVEL)
|
||||
}.ToArray(),
|
||||
activeUri ?? new Uri(SHAREE_LIVE)) // Default URi which is used after install of app
|
||||
{
|
||||
}
|
||||
/// <summary>Constructs default uri list.</summary>
|
||||
public CopriServerUriList(Uri activeUri = null) : this(
|
||||
new List<Uri>
|
||||
{
|
||||
new Uri(SHAREE_LIVE),
|
||||
new Uri(TINK_LIVE),
|
||||
new Uri(SHAREE_DEVEL),
|
||||
new Uri(TINK_DEVEL)
|
||||
}.ToArray(),
|
||||
activeUri ?? new Uri(SHAREE_LIVE)) // Default URi which is used after install of app
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary> Constructs uris object. </summary>
|
||||
/// <param name="p_oSource">Object to copy from.</param>
|
||||
public CopriServerUriList(CopriServerUriList p_oSource) : this(
|
||||
p_oSource.Uris.ToArray(),
|
||||
p_oSource.ActiveUri)
|
||||
{
|
||||
}
|
||||
/// <summary> Constructs uris object. </summary>
|
||||
/// <param name="p_oSource">Object to copy from.</param>
|
||||
public CopriServerUriList(CopriServerUriList p_oSource) : this(
|
||||
p_oSource.Uris.ToArray(),
|
||||
p_oSource.ActiveUri)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary> Constructs a valid uris object. </summary>
|
||||
/// <param name="uris">Known uris.</param>
|
||||
/// <param name="p_oActiveUri">Zero based index of active uri.</param>
|
||||
/// <param name="p_oDevelUri">Uri of the development server.</param>
|
||||
public CopriServerUriList(
|
||||
Uri[] uris,
|
||||
Uri p_oActiveUri)
|
||||
{
|
||||
if (uris == null || uris.Length < 1)
|
||||
{
|
||||
throw new ArgumentException($"Can not construct {typeof(CopriServerUriList)}- object. Array of uris must not be null and contain at least one element.");
|
||||
}
|
||||
/// <summary> Constructs a valid uris object. </summary>
|
||||
/// <param name="uris">Known uris.</param>
|
||||
/// <param name="p_oActiveUri">Zero based index of active uri.</param>
|
||||
/// <param name="p_oDevelUri">Uri of the development server.</param>
|
||||
public CopriServerUriList(
|
||||
Uri[] uris,
|
||||
Uri p_oActiveUri)
|
||||
{
|
||||
if (uris == null || uris.Length < 1)
|
||||
{
|
||||
throw new ArgumentException($"Can not construct {typeof(CopriServerUriList)}- object. Array of uris must not be null and contain at least one element.");
|
||||
}
|
||||
|
||||
if (!uris.Contains(p_oActiveUri))
|
||||
{
|
||||
throw new ArgumentException($"Active uri {p_oActiveUri} not contained in ({string.Join("; ", uris.Select(x => x.AbsoluteUri))}).");
|
||||
}
|
||||
if (!uris.Contains(p_oActiveUri))
|
||||
{
|
||||
throw new ArgumentException($"Active uri {p_oActiveUri} not contained in ({string.Join("; ", uris.Select(x => x.AbsoluteUri))}).");
|
||||
}
|
||||
|
||||
Uris = new List<Uri>(uris);
|
||||
ActiveUri = p_oActiveUri;
|
||||
}
|
||||
Uris = new List<Uri>(uris);
|
||||
ActiveUri = p_oActiveUri;
|
||||
}
|
||||
|
||||
/// <summary> Gets the active uri. </summary>
|
||||
[JsonProperty]
|
||||
public Uri ActiveUri { get; }
|
||||
/// <summary> Gets the active uri. </summary>
|
||||
[JsonProperty]
|
||||
public Uri ActiveUri { get; }
|
||||
|
||||
/// <summary> Gets the active uri. </summary>
|
||||
/// <summary> Gets the active uri. </summary>
|
||||
#if USCSHARP9
|
||||
public static Uri DevelopUri => new (TINK_DEVEL);
|
||||
#else
|
||||
public static Uri DevelopUri => new Uri(TINK_DEVEL);
|
||||
public static Uri DevelopUri => new Uri(TINK_DEVEL);
|
||||
#endif
|
||||
|
||||
/// <summary> Gets the known uris. </summary>
|
||||
[JsonProperty]
|
||||
public IList<Uri> Uris { get; }
|
||||
/// <summary> Gets the known uris. </summary>
|
||||
[JsonProperty]
|
||||
public IList<Uri> Uris { get; }
|
||||
|
||||
/// <summary> Gets the default uri which is active after first installation. </summary>
|
||||
public static Uri DefaultActiveUri
|
||||
{
|
||||
get { return new CopriServerUriList().ActiveUri; }
|
||||
}
|
||||
}
|
||||
/// <summary> Gets the default uri which is active after first installation. </summary>
|
||||
public static Uri DefaultActiveUri
|
||||
{
|
||||
get { return new CopriServerUriList().ActiveUri; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,15 @@ using TINK.Model.Station;
|
|||
|
||||
namespace TINK.Model.Services.CopriApi
|
||||
{
|
||||
public class StationsAndBikesContainer
|
||||
{
|
||||
public StationsAndBikesContainer(StationDictionary stations, BikeCollection bikes)
|
||||
{
|
||||
StationsAll = stations;
|
||||
Bikes = bikes;
|
||||
}
|
||||
public StationDictionary StationsAll { get; }
|
||||
public class StationsAndBikesContainer
|
||||
{
|
||||
public StationsAndBikesContainer(StationDictionary stations, BikeCollection bikes)
|
||||
{
|
||||
StationsAll = stations;
|
||||
Bikes = bikes;
|
||||
}
|
||||
public StationDictionary StationsAll { get; }
|
||||
|
||||
public BikeCollection Bikes { get; }
|
||||
}
|
||||
public BikeCollection Bikes { get; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue