sharee.bike-App/TINKLib/Services/CopriApi/CopriProviderMonkeyStore.cs

121 lines
4.8 KiB
C#
Raw Normal View History

2022-09-20 13:51:55 +02:00
using System;
2021-08-01 17:24:15 +02:00
using System.Collections.Generic;
2021-05-13 20:03:07 +02:00
using System.Threading.Tasks;
2022-09-20 13:51:55 +02:00
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
2022-12-27 21:08:09 +01:00
using TINK.Model.Connector;
2021-06-26 20:57:55 +02:00
using TINK.Model.Device;
using TINK.Repository;
using TINK.Repository.Request;
2021-05-13 20:03:07 +02:00
using TINK.Repository.Response;
2023-04-19 12:14:14 +02:00
using TINK.Repository.Response.Stations;
2022-10-26 20:53:18 +02:00
using TINK.Services.CopriApi.Exception;
2021-05-13 20:03:07 +02:00
namespace TINK.Model.Services.CopriApi
{
2023-02-22 14:03:35 +01:00
/// <summary> Object which manages calls to cache. </summary>
2022-09-06 16:08:19 +02:00
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> 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>
2023-02-22 14:03:35 +01:00
/// <param name="smartDevice">Holds info about smart device.</param>
2022-09-06 16:08:19 +02:00
public CopriProviderMonkeyStore(
string merchantId,
string uiIsoLangugageName,
2023-02-22 14:03:35 +01:00
string sessionCookie,
ISmartDevice smartDevice = null)
2022-09-06 16:08:19 +02:00
{
2023-02-22 14:03:35 +01:00
monkeyStore = new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie, smartDevice);
2022-09-06 16:08:19 +02:00
}
/// <summary> Gets the merchant id.</summary>
public string MerchantId => monkeyStore.MerchantId;
public Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(DoReserveAsync));
2022-09-06 16:08:19 +02:00
public Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string bikeId, Uri operatorUri)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(DoCancelReservationAsync));
2022-09-06 16:08:19 +02:00
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(CalculateAuthKeysAsync));
2022-09-06 16:08:19 +02:00
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,
2022-09-20 13:51:55 +02:00
double batteryLevel,
IVersionInfo versionInfo)
2022-09-06 16:08:19 +02:00
=> await monkeyStore.UpdateLockingStateAsync(
bikeId,
state,
operatorUri,
geolocation,
2022-09-20 13:51:55 +02:00
batteryLevel,
versionInfo);
2022-09-06 16:08:19 +02:00
2022-12-27 21:08:09 +01:00
public async Task<ReservationBookingResponse> DoBookAsync(Uri operatorUri, string bikeId, Guid guid, double batteryPercentage, LockingAction? nextAction = null)
=> await monkeyStore.DoBookAsync(operatorUri, bikeId, guid, batteryPercentage, nextAction);
2022-09-06 16:08:19 +02:00
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<DoReturnResponse> DoReturn(
string bikeId,
LocationDto geolocation,
Uri operatorUri)
2023-02-22 14:03:35 +01:00
=> await monkeyStore.DoReturn(bikeId, geolocation, operatorUri);
2022-09-06 16:08:19 +02:00
public async Task<DoReturnResponse> ReturnAndStartClosingAsync(
string bikeId,
Uri operatorUri)
2023-02-22 14:03:35 +01:00
=> await monkeyStore.ReturnAndStartClosingAsync(bikeId, operatorUri);
2022-09-06 16:08:19 +02:00
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string messge, bool bIsBikeBroke, Uri operatorUri)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(DoSubmitFeedback));
2022-09-06 16:08:19 +02:00
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
public Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
2022-10-26 20:53:18 +02:00
=> throw new RequestNotCachableException(nameof(DoSubmitMiniSurvey));
2022-09-06 16:08:19 +02:00
public async Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
2022-10-26 20:53:18 +02:00
=> await monkeyStore.DoAuthorizationAsync(p_strMailAddress, p_strPassword, p_strDeviceId);
2022-09-06 16:08:19 +02:00
public async Task<AuthorizationoutResponse> DoAuthoutAsync()
2022-10-26 20:53:18 +02:00
=> await monkeyStore.DoAuthoutAsync();
2022-09-06 16:08:19 +02:00
public async Task<BikesAvailableResponse> GetBikesAvailableAsync()
2022-10-26 20:53:18 +02:00
=> await monkeyStore.GetBikesAvailableAsync();
2022-09-06 16:08:19 +02:00
public async Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync()
2022-10-26 20:53:18 +02:00
=> await monkeyStore.GetBikesOccupiedAsync();
2022-09-06 16:08:19 +02:00
public async Task<StationsAvailableResponse> GetStationsAsync()
2022-10-26 20:53:18 +02:00
=> await monkeyStore.GetStationsAsync();
2022-09-06 16:08:19 +02:00
}
2021-05-13 20:03:07 +02:00
}