mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-21 21:46:27 +02:00
Code updated to 3.0.238
This commit is contained in:
parent
3302d80678
commit
9c6a1fa92b
257 changed files with 7763 additions and 2861 deletions
|
@ -5,13 +5,13 @@ using System.IO;
|
|||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Repository.Exception;
|
||||
using TINK.Model.Repository.Request;
|
||||
using TINK.Model.Repository.Response;
|
||||
using TINK.Model.Logging;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Model.Logging;
|
||||
using TINK.Model.Device;
|
||||
|
||||
namespace TINK.Model.Repository
|
||||
namespace TINK.Repository
|
||||
{
|
||||
/// <summary> Object which manages calls to copri. </summary>
|
||||
public class CopriCallsHttps : ICopriServer
|
||||
|
@ -20,17 +20,17 @@ namespace TINK.Model.Repository
|
|||
private IRequestBuilder requestBuilder;
|
||||
|
||||
/// <summary> Initializes a instance of the copri calls https object. </summary>
|
||||
/// <param name="p_oCopriHost">Host to connect to. </param>
|
||||
/// <param name="p_strMerchantId">Id of the merchant.</param>
|
||||
/// <param name="copriHost">Host to connect to. </param>
|
||||
/// <param name="merchantId">Id of the merchant.</param>
|
||||
/// <param name="userAgent">Holds the name and version of the TINKApp.</param>
|
||||
/// <param name="sessionCookie">Session cookie if user is logged in, null otherwise.</param>
|
||||
public CopriCallsHttps(
|
||||
Uri p_oCopriHost,
|
||||
string p_strMerchantId,
|
||||
Uri copriHost,
|
||||
string merchantId,
|
||||
string userAgent,
|
||||
string sessionCookie = null)
|
||||
{
|
||||
m_oCopriHost = p_oCopriHost
|
||||
m_oCopriHost = copriHost
|
||||
?? throw new System.Exception($"Can not construct {GetType().ToString()}- object. Uri of copri host must not be null.");
|
||||
|
||||
UserAgent = !string.IsNullOrEmpty(userAgent)
|
||||
|
@ -38,8 +38,8 @@ namespace TINK.Model.Repository
|
|||
: throw new System.Exception($"Can not construct {GetType().ToString()}- object. User agent must not be null or empty.");
|
||||
|
||||
requestBuilder = string.IsNullOrEmpty(sessionCookie)
|
||||
? new RequestBuilder(p_strMerchantId) as IRequestBuilder
|
||||
: new RequestBuilderLoggedIn(p_strMerchantId, sessionCookie);
|
||||
? new RequestBuilder(merchantId) as IRequestBuilder
|
||||
: new RequestBuilderLoggedIn(merchantId, sessionCookie);
|
||||
}
|
||||
|
||||
/// <summary> Holds the URL for rest calls.</summary>
|
||||
|
@ -108,14 +108,15 @@ namespace TINK.Model.Repository
|
|||
/// <returns>List of files.</returns>
|
||||
public async Task<StationsAllResponse> GetStationsAsync()
|
||||
{
|
||||
return await GetStationsAsync(m_oCopriHost.AbsoluteUri, requestBuilder.GetStations(), UserAgent);
|
||||
var stations = await GetStationsAsync(m_oCopriHost.AbsoluteUri, requestBuilder.GetStations(), UserAgent);
|
||||
return stations;
|
||||
}
|
||||
|
||||
/// <summary> Get authentication keys. </summary>
|
||||
/// <param name="bikeId">Id of the bike to get keys for.</param>
|
||||
/// <returns>Response holding authentication keys.</returns>
|
||||
public async Task<ReservationBookingResponse> GetAuthKeys(int bikeId)
|
||||
=> await GetAuthKeysAsync(m_oCopriHost.AbsoluteUri, requestBuilder.CalculateAuthKeys(bikeId), UserAgent);
|
||||
public async Task<ReservationBookingResponse> GetAuthKeys(string bikeId)
|
||||
=> await GetAuthKeysAsync(m_oCopriHost.AbsoluteUri, requestBuilder.CalculateAuthParameters(bikeId), UserAgent);
|
||||
|
||||
|
||||
/// <summary> Gets booking request response.</summary>
|
||||
|
@ -123,7 +124,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Booking response.</returns>
|
||||
public async Task<ReservationBookingResponse> DoReserveAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
{
|
||||
return await DoReserveAsync(
|
||||
|
@ -137,7 +138,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on cancel booking request.</returns>
|
||||
public async Task<ReservationCancelReturnResponse> DoCancelReservationAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
{
|
||||
return await DoCancelReservationAsync(
|
||||
|
@ -151,11 +152,11 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response holding authentication keys.</returns>
|
||||
public async Task<ReservationBookingResponse> CalculateAuthKeysAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await GetAuthKeysAsync(
|
||||
operatorUri?.AbsoluteUri ?? m_oCopriHost.AbsoluteUri,
|
||||
requestBuilder.CalculateAuthKeys(bikeId),
|
||||
requestBuilder.CalculateAuthParameters(bikeId),
|
||||
UserAgent);
|
||||
|
||||
/// <summary> Updates lock state for a booked bike. </summary>
|
||||
|
@ -166,7 +167,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on updating locking state.</returns>
|
||||
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
LocationDto location,
|
||||
lock_state state,
|
||||
double batteryLevel,
|
||||
|
@ -185,7 +186,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Requst on booking request.</returns>
|
||||
public async Task<ReservationBookingResponse> DoBookAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
Guid guid,
|
||||
double batteryPercentage,
|
||||
Uri operatorUri)
|
||||
|
@ -199,31 +200,35 @@ namespace TINK.Model.Repository
|
|||
/// <summary> Returns a bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to return.</param>
|
||||
/// <param name="location">Geolocation of lock.</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<ReservationCancelReturnResponse> DoReturn(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
LocationDto location,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
{
|
||||
return await DoReturn(
|
||||
operatorUri?.AbsoluteUri ?? m_oCopriHost.AbsoluteUri,
|
||||
requestBuilder.DoReturn(bikeId, location),
|
||||
requestBuilder.DoReturn(bikeId, location, smartDevice),
|
||||
UserAgent);
|
||||
}
|
||||
|
||||
/// <summary> Submits feedback to copri server. </summary>
|
||||
/// <param name="bikeId">Id of the bike to which the feedback is related to.</param>
|
||||
/// <param name="isBikeBroken">True if bike is broken.</param>
|
||||
/// <param name="message">General purpose message or error description.</param>
|
||||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on submitting feedback request.</returns>
|
||||
public async Task<SubmitFeedbackResponse> DoSubmitFeedback(
|
||||
string bikeId,
|
||||
string message,
|
||||
bool isBikeBroken,
|
||||
Uri operatorUri) =>
|
||||
await DoSubmitFeedback(
|
||||
operatorUri?.AbsoluteUri ?? m_oCopriHost.AbsoluteUri,
|
||||
requestBuilder.DoSubmitFeedback(message, isBikeBroken),
|
||||
requestBuilder.DoSubmitFeedback(bikeId, message, isBikeBroken),
|
||||
UserAgent);
|
||||
|
||||
/// <summary> Logs user in. </summary>
|
||||
|
@ -238,10 +243,10 @@ namespace TINK.Model.Repository
|
|||
{
|
||||
#if !WINDOWS_UWP
|
||||
/// Extract session cookie from response.
|
||||
string l_oResponseText = string.Empty;
|
||||
string response = string.Empty;
|
||||
try
|
||||
{
|
||||
l_oResponseText = await PostAsync(
|
||||
response = await PostAsync(
|
||||
copriHost,
|
||||
command,
|
||||
userAgent,
|
||||
|
@ -262,7 +267,7 @@ namespace TINK.Model.Repository
|
|||
throw;
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<AuthorizationResponse>>(l_oResponseText)?.tinkjson;
|
||||
return CopriCallsStatic.DeserializeResponse<AuthorizationResponse>(response, (version) => new UnsupportedCopriVersionDetectedException());
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -299,7 +304,7 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
/// Extract session cookie from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<AuthorizationoutResponse>>(l_oLogoutResponse)?.tinkjson;
|
||||
return CopriCallsStatic.DeserializeResponse<AuthorizationoutResponse>(l_oLogoutResponse, (version) => new UnsupportedCopriVersionDetectedException());
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -317,10 +322,10 @@ namespace TINK.Model.Repository
|
|||
string userAgent = null)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
string l_oStationsAllResponse;
|
||||
string response;
|
||||
try
|
||||
{
|
||||
l_oStationsAllResponse = await PostAsync(p_strCopriHost, p_oCommand, userAgent);
|
||||
response = await PostAsync(p_strCopriHost, p_oCommand, userAgent);
|
||||
}
|
||||
catch (System.Exception l_oException)
|
||||
{
|
||||
|
@ -338,7 +343,9 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<StationsAllResponse>>(l_oStationsAllResponse)?.tinkjson;
|
||||
return CopriCallsStatic.DeserializeResponse(
|
||||
response,
|
||||
(version) => CopriCallsMonkeyStore.GetEmptyStationsAllResponse(version));
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -354,10 +361,10 @@ namespace TINK.Model.Repository
|
|||
string userAgent = null)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
string l_oBikesAvaialbeResponse;
|
||||
string response;
|
||||
try
|
||||
{
|
||||
l_oBikesAvaialbeResponse = await PostAsync(p_strCopriHost, l_oCommand, userAgent);
|
||||
response = await PostAsync(p_strCopriHost, l_oCommand, userAgent);
|
||||
}
|
||||
catch (System.Exception l_oException)
|
||||
{
|
||||
|
@ -375,7 +382,10 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return CopriCallsStatic.DeserializeBikesAvailableResponse(l_oBikesAvaialbeResponse);
|
||||
return CopriCallsStatic.DeserializeResponse(
|
||||
response,
|
||||
(version) => CopriCallsMonkeyStore.GetEmptyBikesAvailableResponse(version));
|
||||
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -391,10 +401,10 @@ namespace TINK.Model.Repository
|
|||
string userAgent = null)
|
||||
{
|
||||
#if !WINDOWS_UWP
|
||||
string l_oBikesOccupiedResponse;
|
||||
string response;
|
||||
try
|
||||
{
|
||||
l_oBikesOccupiedResponse = await PostAsync(p_strCopriHost, p_oCommand, userAgent);
|
||||
response = await PostAsync(p_strCopriHost, p_oCommand, userAgent);
|
||||
}
|
||||
catch (System.Exception l_oException)
|
||||
{
|
||||
|
@ -412,7 +422,9 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return CopriCallsStatic.DeserializeBikesOccupiedResponse(l_oBikesOccupiedResponse);
|
||||
return CopriCallsStatic.DeserializeResponse(
|
||||
response,
|
||||
(version) => CopriCallsMonkeyStore.GetEmptyBikesReservedOccupiedResponse(version));
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -449,7 +461,7 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.tinkjson;
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -485,7 +497,7 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.tinkjson;
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -522,7 +534,7 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<ReservationCancelReturnResponse>>(l_oBikesAvaialbeResponse)?.tinkjson;
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ReservationCancelReturnResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -555,7 +567,7 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.tinkjson;
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -588,7 +600,7 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.tinkjson;
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ReservationBookingResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -621,7 +633,7 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<ReservationCancelReturnResponse>>(l_oBikesAvaialbeResponse)?.tinkjson;
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ReservationCancelReturnResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -654,7 +666,7 @@ namespace TINK.Model.Repository
|
|||
}
|
||||
|
||||
// Extract bikes from response.
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<SubmitFeedbackResponse>>(userFeedbackResponse)?.tinkjson;
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<SubmitFeedbackResponse>>(userFeedbackResponse)?.shareejson;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
|
@ -775,9 +787,9 @@ namespace TINK.Model.Repository
|
|||
return null;
|
||||
#endif
|
||||
}
|
||||
catch (System.Exception l_oException)
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
Log.ForContext<CopriCallsHttps>().InformationOrError("Posting command {DisplayCommand} to host {URL} failed. {Exception}.", displayCommandFunc(), uRL, l_oException);
|
||||
Log.ForContext<CopriCallsHttps>().InformationOrError("Posting command {DisplayCommand} to host {URL} failed. {Exception}.", displayCommandFunc(), uRL, exception);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
1314
TINKLib/Repository/CopriCallsMemory.cs
Normal file
1314
TINKLib/Repository/CopriCallsMemory.cs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,13 +1,12 @@
|
|||
using MonkeyCache.FileStore;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Model.Repository.Request;
|
||||
using TINK.Model.Repository.Response;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Model.Services.CopriApi;
|
||||
using TINK.Model.Device;
|
||||
|
||||
namespace TINK.Model.Repository
|
||||
namespace TINK.Repository
|
||||
{
|
||||
public class CopriCallsMonkeyStore : ICopriCache
|
||||
{
|
||||
|
@ -18,7 +17,7 @@ namespace TINK.Model.Repository
|
|||
private IRequestBuilder requestBuilder;
|
||||
|
||||
public const string BIKESAVAILABLE = @"{
|
||||
""copri_version"" : ""3.0.0.0"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""bikes"" : {},
|
||||
""response_state"" : ""OK"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
|
@ -26,26 +25,78 @@ namespace TINK.Model.Repository
|
|||
""response"" : ""bikes_available""
|
||||
}";
|
||||
|
||||
/// <summary> Gets an empty response. </summary>
|
||||
/// <param name="copriVersion">Version of empty response.</param>
|
||||
/// <returns>Response.</returns>
|
||||
public static BikesAvailableResponse GetEmptyBikesAvailableResponse(string copriVersion)
|
||||
=> JsonConvertRethrow.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE.Replace("4.1.0.0", copriVersion));
|
||||
|
||||
#if !COPRIVERSION41
|
||||
public const string BIKESOCCUPIED = @"{
|
||||
""debuglevel"" : ""1"",
|
||||
""user_id"" : """",
|
||||
""response"" : ""user_bikes_occupied"",
|
||||
""user_group"" : ""Konrad,TINK"",
|
||||
""user_group"" : [ ""Konrad"", ""TINK"" ],
|
||||
""authcookie"" : """",
|
||||
""response_state"" : ""OK"",
|
||||
""bikes_occupied"" : {},
|
||||
""copri_version"" : ""3.0.0.0"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""apiserver"" : ""https://app.tink-konstanz.de""
|
||||
}";
|
||||
#endif
|
||||
|
||||
public const string STATIONS = @"{
|
||||
""apiserver"" : ""https://app.tink-konstanz.de"",
|
||||
/// <summary> Gets an empty response. </summary>
|
||||
/// <param name="copriVersion">Version of empty response.</param>
|
||||
/// <returns>Response.</returns>
|
||||
public static BikesReservedOccupiedResponse GetEmptyBikesReservedOccupiedResponse(string copriVersion)
|
||||
=> JsonConvertRethrow.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED.Replace("4.1.0.0", copriVersion));
|
||||
|
||||
#if !COPRIVERSION41
|
||||
/// <summary> Version COPRI 4.0. or earlier</summary>
|
||||
public const string STATIONSALL = @"{
|
||||
""apiserver"" : """",
|
||||
""authcookie"" : """",
|
||||
""response"" : ""stations_all"",
|
||||
""copri_version"" : ""3.0.0.0"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {},
|
||||
""response_state"" : ""OK""
|
||||
}";
|
||||
#else
|
||||
/// <summary> Version COPRI 4.1 or later. </summary>
|
||||
public const string STATIONSALL = @"{
|
||||
""uri_primary"": """"
|
||||
""uri_operator_array"": [ ]
|
||||
""authcookie"" : """",
|
||||
""response"" : ""stations_all"",
|
||||
""copri_version"" : ""4.1.0.0"",
|
||||
""stations"" : {},
|
||||
""response_state"" : ""OK""
|
||||
}";
|
||||
#endif
|
||||
|
||||
#if !COPRIVERSION41
|
||||
/// <summary> Version COPRI 4.0. or earlier</summary>
|
||||
public const string AUTHORIZATION = @"{
|
||||
""user_group"" : [ """" ],
|
||||
""response"" : ""authorization"",
|
||||
""response_state"" : ""OK"",
|
||||
""copri_version"" : ""4.1.0.0""
|
||||
}";
|
||||
#else
|
||||
/// <summary> Version COPRI 4.0. or earlier</summary>
|
||||
public const string AUTHORIZATION = @"{
|
||||
""user_group"" : [],
|
||||
""response"" : ""authorization"",
|
||||
""response_state"" : ""OK"",
|
||||
""copri_version"" : ""4.1.0.0""
|
||||
}";
|
||||
#endif
|
||||
|
||||
/// <summary> Gets an empty response. </summary>
|
||||
/// <param name="copriVersion">Version of empty response.</param>
|
||||
/// <returns>Response.</returns>
|
||||
public static StationsAllResponse GetEmptyStationsAllResponse(string copriVersion)
|
||||
=> JsonConvertRethrow.DeserializeObject<StationsAllResponse>(STATIONSALL.Replace("4.1.0.0", copriVersion));
|
||||
|
||||
/// <summary>
|
||||
/// Holds the seconds after which station and bikes info is considered to be invalid.
|
||||
|
@ -79,53 +130,57 @@ namespace TINK.Model.Repository
|
|||
// Ensure that store holds valid entries.
|
||||
if (!Barrel.Current.Exists(requestBuilder.GetBikesAvailable()))
|
||||
{
|
||||
AddToCache(JsonConvert.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE), new TimeSpan(0));
|
||||
AddToCache(JsonConvertRethrow.DeserializeObject<BikesAvailableResponse>(BIKESAVAILABLE), new TimeSpan(0));
|
||||
}
|
||||
|
||||
// Do not query bikes occupied if no user is logged in (leads to not implemented exception)
|
||||
if (!string.IsNullOrEmpty(sessionCookie) && !Barrel.Current.Exists(requestBuilder.GetBikesOccupied()))
|
||||
{
|
||||
AddToCache(JsonConvert.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED), new TimeSpan(0));
|
||||
AddToCache(JsonConvertRethrow.DeserializeObject<BikesReservedOccupiedResponse>(BIKESOCCUPIED), new TimeSpan(0));
|
||||
}
|
||||
|
||||
if (!Barrel.Current.Exists(requestBuilder.GetStations()))
|
||||
{
|
||||
AddToCache(JsonConvert.DeserializeObject<StationsAllResponse>(STATIONS), new TimeSpan(0));
|
||||
AddToCache(JsonConvertRethrow.DeserializeObject<StationsAllResponse>(STATIONSALL), new TimeSpan(0));
|
||||
}
|
||||
}
|
||||
|
||||
public Task<ReservationBookingResponse> DoReserveAsync(int bikeId, Uri operatorUri)
|
||||
public Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
throw new System.Exception("Reservierung im Offlinemodus nicht möglich!");
|
||||
}
|
||||
|
||||
public Task<ReservationCancelReturnResponse> DoCancelReservationAsync(int p_iBikeId, Uri operatorUri)
|
||||
public Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string bikeId, Uri operatorUri)
|
||||
{
|
||||
throw new System.Exception("Abbrechen einer Reservierung im Offlinemodus nicht möglich!");
|
||||
}
|
||||
|
||||
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(int bikeId, Uri operatorUri)
|
||||
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new System.Exception("Schlosssuche im Offlinemodus nicht möglich!");
|
||||
|
||||
public Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
LocationDto geolocation,
|
||||
lock_state state,
|
||||
double batteryLevel,
|
||||
Uri operatorUri)
|
||||
=> throw new System.Exception("Aktualisierung des Schlossstatuses im Offlinemodus nicht möglich!");
|
||||
|
||||
public Task<ReservationBookingResponse> DoBookAsync(int bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
|
||||
public Task<ReservationBookingResponse> DoBookAsync(string bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
|
||||
{
|
||||
throw new System.Exception("Buchung im Offlinemodus nicht möglich!");
|
||||
}
|
||||
|
||||
public Task<ReservationCancelReturnResponse> DoReturn(int bikeId, LocationDto geolocation, Uri operatorUri)
|
||||
public Task<ReservationCancelReturnResponse> DoReturn(
|
||||
string bikeId,
|
||||
LocationDto geolocation,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri)
|
||||
{
|
||||
throw new System.Exception("Rückgabe im Offlinemodus nicht möglich!");
|
||||
}
|
||||
|
||||
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string message, bool isBikeBroken, Uri operatorUri) =>
|
||||
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, string message, bool isBikeBroken, Uri operatorUri) =>
|
||||
throw new System.Exception("Übermittlung von Feedback im Offlinemodus nicht möglich!");
|
||||
|
||||
public Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
|
||||
|
@ -207,7 +262,7 @@ namespace TINK.Model.Repository
|
|||
{
|
||||
Barrel.Current.Add(
|
||||
requestBuilder.GetStations(),
|
||||
JsonConvert.SerializeObject(stations),
|
||||
JsonConvertRethrow.SerializeObject(stations),
|
||||
expiresAfter);
|
||||
}
|
||||
}
|
||||
|
@ -239,8 +294,8 @@ namespace TINK.Model.Repository
|
|||
lock (monkeyLock)
|
||||
{
|
||||
Barrel.Current.Add(
|
||||
requestBuilder.GetBikesAvailable(),
|
||||
JsonConvert.SerializeObject(bikes),
|
||||
requestBuilder.GetBikesAvailable(),
|
||||
JsonConvertRethrow.SerializeObject(bikes),
|
||||
expiresAfter);
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +328,7 @@ namespace TINK.Model.Repository
|
|||
{
|
||||
Barrel.Current.Add(
|
||||
requestBuilder.GetBikesOccupied(),
|
||||
JsonConvert.SerializeObject(bikes),
|
||||
JsonConvertRethrow.SerializeObject(bikes),
|
||||
expiresAfter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,65 @@
|
|||
using TINK.Model.Repository.Response;
|
||||
using Serilog;
|
||||
using System;
|
||||
using TINK.Model.Connector;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TINK.Model.Repository
|
||||
namespace TINK.Repository
|
||||
{
|
||||
public static class CopriCallsStatic
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializes JSON from response string.
|
||||
/// </summary>
|
||||
/// <param name="p_strResponse">Response to deserialize.</param>
|
||||
/// <returns></returns>
|
||||
public static BikesAvailableResponse DeserializeBikesAvailableResponse(string p_strResponse)
|
||||
#if !USCSHARP9
|
||||
private static Version UNSUPPORTEDFUTURECOPRIVERSIONLOWER = new Version(4, 1);
|
||||
#else
|
||||
private static Version UNSUPPORTEDFUTURECOPRIVERSIONLOWER = new(4, 1);
|
||||
#endif
|
||||
|
||||
#if !USCSHARP9
|
||||
private static Version UNSUPPORTEDFUTURECOPRIVERSIONUPPER = new Version(4, 2);
|
||||
#else
|
||||
private static Version UNSUPPORTEDFUTURECOPRIVERSIONUPPER = new(4, 2);
|
||||
#endif
|
||||
public static Version UnsupportedVersionLower => UNSUPPORTEDFUTURECOPRIVERSIONLOWER;
|
||||
|
||||
public static Version UnsupportedVersionUpper => UNSUPPORTEDFUTURECOPRIVERSIONUPPER;
|
||||
|
||||
/// <summary> Deserializes reponse JSON if response is of supported version or provides default response otherwise. </summary>
|
||||
/// <typeparam name="T">Type of response object.</typeparam>
|
||||
/// <param name="response">Response JSON.</param>
|
||||
/// <param name="emptyResponseFactory">Factory providing default delegate.</param>
|
||||
/// <returns>Response object.</returns>
|
||||
public static T DeserializeResponse<T>(this string response, Func<string, T> emptyResponseFactory) where T: class
|
||||
{
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<BikesAvailableResponse>>(p_strResponse)?.tinkjson;
|
||||
// Get COPRI version from respone.
|
||||
var bikeInfoBase = JsonConvertRethrow.DeserializeObject<VersionindependentResponse>(response)?.shareejson;
|
||||
|
||||
if (bikeInfoBase.GetCopriVersion() < UNSUPPORTEDFUTURECOPRIVERSIONLOWER
|
||||
|| bikeInfoBase.GetCopriVersion() >= UNSUPPORTEDFUTURECOPRIVERSIONUPPER)
|
||||
{
|
||||
return emptyResponseFactory?.Invoke(bikeInfoBase.copri_version) ?? null;
|
||||
}
|
||||
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<T>>(response)?.shareejson;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes JSON from response string.
|
||||
/// </summary>
|
||||
/// <param name="p_strResponse">Response to deserialize.</param>
|
||||
/// <returns></returns>
|
||||
public static BikesReservedOccupiedResponse DeserializeBikesOccupiedResponse(string p_strResponse)
|
||||
/// <summary> Deserializes reponse JSON if response is of supported version or throws an exception. </summary>
|
||||
/// <typeparam name="T">Type of response object.</typeparam>
|
||||
/// <param name="response">Response JSON.</param>
|
||||
/// <param name="unsupportedVersionExectpion">Exception to fire.</param>
|
||||
/// <returns>Response object.</returns>
|
||||
public static T DeserializeResponse<T>(this string response, Func<string, System.Exception> unsupportedVersionExectpion = null) where T : class
|
||||
{
|
||||
return JsonConvert.DeserializeObject<ResponseContainer<BikesReservedOccupiedResponse>>(p_strResponse)?.tinkjson;
|
||||
|
||||
// Get COPRI version from respone.
|
||||
var bikeInfoBase = JsonConvertRethrow.DeserializeObject<VersionindependentResponse>(response)?.shareejson;
|
||||
|
||||
if (bikeInfoBase.GetCopriVersion() < UNSUPPORTEDFUTURECOPRIVERSIONLOWER
|
||||
|| bikeInfoBase.GetCopriVersion() >= UNSUPPORTEDFUTURECOPRIVERSIONUPPER)
|
||||
{
|
||||
Log.Error($"Unsupported copri version {bikeInfoBase.copri_version} detected on attempt to log in.");
|
||||
throw unsupportedVersionExectpion?.Invoke(bikeInfoBase.copri_version) ?? new System.Exception($"Unsupported COPRI version {bikeInfoBase.copri_version} detected.");
|
||||
}
|
||||
|
||||
return JsonConvertRethrow.DeserializeObject<ResponseContainer<T>>(response)?.shareejson;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Is fired with reqest used a cookie which is not defined.
|
||||
|
@ -15,11 +15,25 @@
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether authcookie is defined or not.
|
||||
/// </summary>
|
||||
/// <param name="reponse">Response to check</param>
|
||||
/// <param name="actionText">Text holding contectin in which authcookie is checked.</param>
|
||||
/// <param name="exception">Exception thrown if cookie is not defined.</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsAuthcookieNotDefined(
|
||||
Response.ResponseBase reponse,
|
||||
string actionText,
|
||||
out AuthcookieNotDefinedException exception)
|
||||
{
|
||||
if (reponse == null || reponse.response_state == null)
|
||||
{
|
||||
// Empty response or response withoud response state is no authcookie not defined exeception.
|
||||
exception = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!reponse.response_state.ToUpper().Contains(AUTH_FAILURE_QUERY_AUTHCOOKIENOTDEFIED.ToUpper())
|
||||
&& !reponse.response_state.ToUpper().Contains(AUTH_FAILURE_BOOK_AUTICOOKIENOTDEFIED.ToUpper())
|
||||
&& !reponse.response_state.ToUpper().Contains(AUTH_FAILURE_BIKESOCCUPIED_AUTICOOKIENOTDEFIED.ToUpper())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class InvalidAuthorizationResponseException : InvalidResponseException<Response.ResponseBase>
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
/// <summary> Handles booking request which fail due to too many bikes requested/ booked.</summary>
|
||||
public class BookingDeclinedException : InvalidResponseException
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class CallNotRequiredException : System.Exception
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class CommunicationException : System.Exception
|
||||
{
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using TINK.Model.Repository.Exception;
|
||||
|
||||
namespace TINK.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class DeserializationException : CommunicationException
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class InvalidResponseException<T> : InvalidResponseException
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using TINK.Model.Repository.Exception;
|
||||
|
||||
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class NoGPSDataException : InvalidResponseException
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class NotAtStationException : InvalidResponseException
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using TINK.Model.Repository.Response;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using TINK.Model.Repository.Response;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class UnsupportedCopriVersionDetectedException : System.Exception
|
||||
{
|
||||
public UnsupportedCopriVersionDetectedException() : base("Unsupported app version detected.")
|
||||
{}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class WebConnectFailureException : CommunicationException
|
||||
{
|
||||
|
|
|
@ -1,42 +1,53 @@
|
|||
using System.Net;
|
||||
|
||||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public static class WebExceptionHelper
|
||||
{
|
||||
/// <summary> Gets if a exception is caused by an error connecting to copri (LAN or mobile data off/ not reachable, proxy, ...).</summary>
|
||||
/// <param name="p_oException">Expection to check.</param>
|
||||
/// <param name="exception">Expection to check.</param>
|
||||
/// <returns>True if exception if caused by an connection error. </returns>
|
||||
public static bool GetIsConnectFailureException(this System.Exception p_oException)
|
||||
public static bool GetIsConnectFailureException(this System.Exception exception)
|
||||
{
|
||||
var l_oException = p_oException as WebException;
|
||||
if (l_oException == null)
|
||||
#if !USCSHARP9
|
||||
if (!(exception is WebException webException))
|
||||
#else
|
||||
if (exception is not WebException webException)
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return l_oException.Status == WebExceptionStatus.ConnectFailure // Happens if WLAN and mobile data is off/ Router denies internet access/ ...
|
||||
|| l_oException.Status == WebExceptionStatus.NameResolutionFailure // Happens sometimes when not WLAN and no mobil connection are available (bad connection in lift).
|
||||
|| l_oException.Status == WebExceptionStatus.ReceiveFailure; // Happened when modile was connected to WLAN
|
||||
return webException.Status == WebExceptionStatus.ConnectFailure // Happens if WLAN and mobile data is off/ Router denies internet access/ ...
|
||||
|| webException.Status == WebExceptionStatus.NameResolutionFailure // Happens sometimes when not WLAN and no mobil connection are available (bad connection in lift).
|
||||
|| webException.Status == WebExceptionStatus.ReceiveFailure; // Happened when modile was connected to WLAN
|
||||
}
|
||||
|
||||
/// <summary> Gets if a exception is caused by clicking too fast.</summary>
|
||||
/// <param name="p_oException">Expection to check.</param>
|
||||
/// <param name="exception">Expection to check.</param>
|
||||
/// <returns>True if exception if caused by a fast click sequence. </returns>
|
||||
public static bool GetIsForbiddenException(this System.Exception p_oException)
|
||||
public static bool GetIsForbiddenException(this System.Exception exception)
|
||||
{
|
||||
if (!(p_oException is WebException l_oException))
|
||||
#if !USCSHARP9
|
||||
if (!(exception is WebException webException))
|
||||
#else
|
||||
if (exception is not WebException webException)
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(l_oException?.Response is HttpWebResponse l_oResponse))
|
||||
#if !USCSHARP9
|
||||
if (!(webException?.Response is HttpWebResponse response))
|
||||
#else
|
||||
if (webException?.Response is not HttpWebResponse response)
|
||||
#endif
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return l_oException.Status == WebExceptionStatus.ProtocolError
|
||||
&& l_oResponse.StatusCode == HttpStatusCode.Forbidden;
|
||||
return webException.Status == WebExceptionStatus.ProtocolError
|
||||
&& response.StatusCode == HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace TINK.Model.Repository.Exception
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class WebForbiddenException : CommunicationException
|
||||
{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Repository.Request;
|
||||
using TINK.Model.Repository.Response;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Repository.Request;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TINK.Model.Repository
|
||||
namespace TINK.Repository
|
||||
{
|
||||
/// <summary> Interface to communicate with copri server.</summary>
|
||||
public interface ICopriServerBase
|
||||
|
@ -28,7 +28,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on reserving request.</returns>
|
||||
Task<ReservationBookingResponse> DoReserveAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
Uri operatorUri);
|
||||
|
||||
/// <summary> Cancels reservation of bik. </summary>
|
||||
|
@ -36,7 +36,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on cancel reservation request.</returns>
|
||||
Task<ReservationCancelReturnResponse> DoCancelReservationAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
Uri operatorUri);
|
||||
|
||||
/// <summary> Get authentication keys. </summary>
|
||||
|
@ -44,7 +44,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response holding authentication keys.</returns>
|
||||
Task<ReservationBookingResponse> CalculateAuthKeysAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
Uri operatorUri);
|
||||
|
||||
/// <summary> Updates COPRI lock state for a booked bike. </summary>
|
||||
|
@ -55,7 +55,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on updating locking state.</returns>
|
||||
Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
LocationDto location,
|
||||
lock_state state,
|
||||
double batteryPercentage,
|
||||
|
@ -68,7 +68,7 @@ namespace TINK.Model.Repository
|
|||
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
Task<ReservationBookingResponse> DoBookAsync(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
Guid guid,
|
||||
double batteryPercentage,
|
||||
Uri operatorUri);
|
||||
|
@ -76,19 +76,23 @@ namespace TINK.Model.Repository
|
|||
/// <summary> Returns a bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to return.</param>
|
||||
/// <param name="location">Geolocation of lock.</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>
|
||||
Task<ReservationCancelReturnResponse> DoReturn(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
LocationDto location,
|
||||
ISmartDevice smartDevice,
|
||||
Uri operatorUri);
|
||||
|
||||
/// <summary>
|
||||
/// Submits feedback to copri server.
|
||||
/// </summary>
|
||||
/// <param name="bikeId">Id of the bike to submit feedback for.</param>
|
||||
/// <param name="isBikeBroken">True if bike is broken.</param>
|
||||
/// <param name="message">General purpose message or error description.</param>
|
||||
Task<SubmitFeedbackResponse> DoSubmitFeedback(
|
||||
string bikeId,
|
||||
string message,
|
||||
bool isBikeBroken,
|
||||
Uri operatorUri);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using TINK.Model.Device;
|
||||
|
||||
namespace TINK.Model.Repository.Request
|
||||
namespace TINK.Repository.Request
|
||||
{
|
||||
/// <summary> Defines members to create requests.</summary>
|
||||
public interface IRequestBuilder
|
||||
|
@ -41,17 +42,17 @@ namespace TINK.Model.Repository.Request
|
|||
/// <summary> Gets reservation request (synonym: reservation == request == reservieren). </summary>
|
||||
/// <param name="bikeId">Id of the bike to reserve.</param>
|
||||
/// <returns>Requst to reserve bike.</returns>
|
||||
string DoReserve(int bikeId);
|
||||
string DoReserve(string bikeId);
|
||||
|
||||
/// <summary> Gets request to cancel reservation. </summary>
|
||||
/// <param name="bikeId">Id of the bike to cancel reservation for.</param>
|
||||
/// <returns>Requst on cancel booking request.</returns>
|
||||
string DoCancelReservation(int bikeId);
|
||||
string DoCancelReservation(string bikeId);
|
||||
|
||||
/// <summary> Request to get keys. </summary>
|
||||
/// <param name="bikeId">Id of the bike to get keys for.</param>
|
||||
/// <returns>Request to get keys.</returns>
|
||||
string CalculateAuthKeys(int bikeId);
|
||||
string CalculateAuthParameters(string bikeId);
|
||||
|
||||
/// <summary> Gets the request for updating lock state for a booked bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to update locking state for.</param>
|
||||
|
@ -59,7 +60,7 @@ namespace TINK.Model.Repository.Request
|
|||
/// <param name="state">New locking state.</param>
|
||||
/// <returns>Request to update locking state.</returns>
|
||||
string UpateLockingState(
|
||||
int bikeId,
|
||||
string bikeId,
|
||||
LocationDto location,
|
||||
lock_state state,
|
||||
double batteryPercentage);
|
||||
|
@ -69,20 +70,21 @@ namespace TINK.Model.Repository.Request
|
|||
/// <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>Request to booking bike.</returns>
|
||||
string DoBook(int bikeId, Guid guid, double batteryPercentage);
|
||||
string DoBook(string bikeId, Guid guid, double batteryPercentage);
|
||||
|
||||
/// <summary> Gets request for returning the bike. </summary>
|
||||
/// <param name="bikeId">Id of the bike to return.</param>
|
||||
/// <param name="location">Geolocation of lock when returning bike.</param>
|
||||
/// <returns>Requst on returning request.</returns>
|
||||
string DoReturn(int bikeId, LocationDto location);
|
||||
string DoReturn(string bikeId, LocationDto location, ISmartDevice smartDevice);
|
||||
|
||||
/// <summary>
|
||||
/// Gets request for submiting feedback to copri server.
|
||||
/// </summary>
|
||||
/// <param name="bikeId">Id of the bike to which the feedback is related to.</param>
|
||||
/// <param name="message">General purpose message or error description.</param>
|
||||
/// <param name="isBikeBroken">True if bike is broken.</param>
|
||||
string DoSubmitFeedback(string message = null, bool isBikeBroken = false);
|
||||
string DoSubmitFeedback(string bikeId, string message = null, bool isBikeBroken = false);
|
||||
}
|
||||
|
||||
/// <summary> Copri locking states</summary>
|
||||
|
@ -92,6 +94,7 @@ namespace TINK.Model.Repository.Request
|
|||
unlocked
|
||||
}
|
||||
|
||||
/// <summary> Holds lockation info.</summary>
|
||||
public class LocationDto
|
||||
{
|
||||
public double Latitude { get; private set; }
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using TINK.Model.Repository.Exception;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Repository.Exception;
|
||||
|
||||
namespace TINK.Model.Repository.Request
|
||||
namespace TINK.Repository.Request
|
||||
{
|
||||
/// <summary> Creates requests if no user is logged in.</summary>
|
||||
public class RequestBuilder : IRequestBuilder
|
||||
|
@ -80,32 +81,34 @@ namespace TINK.Model.Repository.Request
|
|||
public string GetBikesOccupied() => throw new NotSupportedException();
|
||||
|
||||
/// <summary> Gets booking request response. </summary>
|
||||
/// <param name="p_iBikeId">Id of the bike to book.</param>
|
||||
/// <param name="bikeId">Id of the bike to book.</param>
|
||||
/// <returns>Response on booking request.</returns>
|
||||
public string DoReserve(int p_iBikeId) => throw new NotSupportedException();
|
||||
public string DoReserve(string bikeId) => throw new NotSupportedException();
|
||||
|
||||
/// <summary> Gets cancel booking request response. </summary>
|
||||
/// <param name="p_iBikeId">Id of the bike to book.</param>
|
||||
/// <returns>Response on cancel booking request.</returns>
|
||||
public string DoCancelReservation(int p_iBikeId) => throw new NotSupportedException();
|
||||
public string DoCancelReservation(string p_iBikeId) => throw new NotSupportedException();
|
||||
|
||||
/// <summary> Request to calculate authentication keys. </summary>
|
||||
/// <param name="bikeId">Id of the bike to get keys for.</param>
|
||||
/// <returns>Response on request.</returns>
|
||||
public string CalculateAuthKeys(int bikeId) => throw new NotSupportedException();
|
||||
public string CalculateAuthParameters(string bikeId) => throw new NotSupportedException();
|
||||
|
||||
public string UpateLockingState(int bikeId, LocationDto geolocation, lock_state state, double batteryPercentage)
|
||||
public string UpateLockingState(string bikeId, LocationDto geolocation, lock_state state, double batteryPercentage)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
public string DoBook(int bikeId, Guid guid, double batteryPercentage) => throw new NotSupportedException();
|
||||
public string DoBook(string bikeId, Guid guid, double batteryPercentage) => throw new NotSupportedException();
|
||||
|
||||
public string DoReturn(int bikeId, LocationDto geolocation) => throw new NotSupportedException();
|
||||
public string DoReturn(string bikeId, LocationDto geolocation, ISmartDevice smartDevice) => throw new NotSupportedException();
|
||||
|
||||
/// <summary> Gets submit feedback request. </summary>
|
||||
/// <param name="bikeId">Id of the bike to which the feedback is related to.</param>
|
||||
/// <param name="message">General purpose message or error description.</param>
|
||||
/// <param name="isBikeBroken">True if bike is broken.</param>
|
||||
/// <returns>Submit feedback request.</returns>
|
||||
public string DoSubmitFeedback(
|
||||
string bikeId,
|
||||
string message = null,
|
||||
bool isBikeBroken = false) => throw new NotSupportedException();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using TINK.Model.Repository.Exception;
|
||||
using TINK.Model.Device;
|
||||
using TINK.Repository.Exception;
|
||||
|
||||
namespace TINK.Model.Repository.Request
|
||||
namespace TINK.Repository.Request
|
||||
{
|
||||
/// <summary> Creates requests if a user is logged in.</summary>
|
||||
public class RequestBuilderLoggedIn : IRequestBuilder
|
||||
|
@ -75,21 +76,21 @@ namespace TINK.Model.Repository.Request
|
|||
/// <remarks> Operator specific call.</remarks>
|
||||
/// <param name="bikeId">Id of the bike to reserve.</param>
|
||||
/// <returns>Requst to reserve bike.</returns>
|
||||
public string DoReserve(int bikeId)
|
||||
public string DoReserve(string bikeId)
|
||||
=> $"request=booking_request&bike={bikeId}&authcookie={SessionCookie}{MerchantId}";
|
||||
|
||||
/// <summary> Gets request to cancel reservation. </summary>
|
||||
/// <remarks> Operator specific call.</remarks>
|
||||
/// <param name="bikeId">Id of the bike to cancel reservation for.</param>
|
||||
/// <returns>Requst on cancel booking request.</returns>
|
||||
public string DoCancelReservation(int p_iBikeId)
|
||||
public string DoCancelReservation(string p_iBikeId)
|
||||
=> $"request=booking_cancel&bike={p_iBikeId}&authcookie={SessionCookie}{MerchantId}";
|
||||
|
||||
/// <summary> Request to get keys. </summary>
|
||||
/// <remarks> Operator specific call.</remarks>
|
||||
/// <param name="bikeId">Id of the bike to get keys for.</param>
|
||||
/// <returns>Request to get keys.</returns>
|
||||
public string CalculateAuthKeys(int bikeId)
|
||||
public string CalculateAuthParameters(string bikeId)
|
||||
=> $"request=booking_update&bike={bikeId}&authcookie={SessionCookie}{MerchantId}&genkey=1";
|
||||
|
||||
/// <summary> Gets the request for updating lock state for a booked bike. </summary>
|
||||
|
@ -97,9 +98,9 @@ namespace TINK.Model.Repository.Request
|
|||
/// <param name="bikeId">Id of the bike to update locking state for.</param>
|
||||
/// <param name="state">New locking state.</param>
|
||||
/// <returns>Request to update locking state.</returns>
|
||||
public string UpateLockingState(int bikeId, LocationDto geolocation, lock_state state, double batteryPercentage)
|
||||
public string UpateLockingState(string bikeId, LocationDto geolocation, lock_state state, double batteryPercentage)
|
||||
{
|
||||
return $"request=booking_update&bike={bikeId}{GetLocationKey(geolocation)}&lock_state={state}{GetBatteryPercentageKey(batteryPercentage)}&authcookie={SessionCookie}{MerchantId}";
|
||||
return $"request=booking_update&bike={bikeId}{GetLocationParameters(geolocation)}&lock_state={state}{GetBatteryPercentageParameters(batteryPercentage)}&authcookie={SessionCookie}{MerchantId}";
|
||||
}
|
||||
|
||||
/// <summary> Gets booking request request (synonym: booking == renting == mieten). </summary>
|
||||
|
@ -108,55 +109,65 @@ namespace TINK.Model.Repository.Request
|
|||
/// <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>Request to booking bike.</returns>
|
||||
public string DoBook(int bikeId, Guid guid, double batteryPercentage)
|
||||
=> $"request=booking_update&bike={bikeId}&authcookie={SessionCookie}{MerchantId}&Ilockit_GUID={guid}&state=occupied&lock_state=unlocked{GetBatteryPercentageKey(batteryPercentage)}";
|
||||
public string DoBook(string bikeId, Guid guid, double batteryPercentage)
|
||||
=> $"request=booking_update&bike={bikeId}&authcookie={SessionCookie}{MerchantId}&Ilockit_GUID={guid}&state=occupied&lock_state=unlocked{GetBatteryPercentageParameters(batteryPercentage)}";
|
||||
|
||||
/// <summary> Gets request for returning the bike. </summary>
|
||||
/// <remarks> Operator specific call.</remarks>
|
||||
/// <param name="bikeId">Id of bike to return.</param>
|
||||
/// <param name="geolocation">Geolocation of lock when returning bike.</param>
|
||||
/// <returns>Requst on returning request.</returns>
|
||||
public string DoReturn(int bikeId, LocationDto geolocation)
|
||||
public string DoReturn(string bikeId, LocationDto geolocation, ISmartDevice smartDevice)
|
||||
{
|
||||
return $"request=booking_update&bike={bikeId}&authcookie={SessionCookie}{MerchantId}&state=available{GetLocationKey(geolocation)}&lock_state=locked";
|
||||
return $"request=booking_update" +
|
||||
$"&bike={bikeId}" +
|
||||
$"&authcookie={SessionCookie}{MerchantId}" +
|
||||
$"&state=available" +
|
||||
$"{GetLocationParameters(geolocation)}" +
|
||||
$"&lock_state=locked" +
|
||||
$"{GetSmartDeviceParameters(smartDevice)}";
|
||||
}
|
||||
|
||||
/// <summary> Gets submit feedback request. </summary>
|
||||
/// <param name="bikeId">Id of the bike to return.</param>
|
||||
/// <param name="message">General purpose message or error description.</param>
|
||||
/// <param name="isBikeBroken">True if bike is broken.</param>
|
||||
/// <returns>Submit feedback request.</returns>
|
||||
public string DoSubmitFeedback(
|
||||
string bikeId,
|
||||
string message = null,
|
||||
bool isBikeBroken = false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message) && !isBikeBroken)
|
||||
{
|
||||
// User just acknoledged biked returned message.
|
||||
return "request=user_feedback";
|
||||
return $"request=user_feedback&bike={bikeId}&authcookie={SessionCookie}{MerchantId}";
|
||||
}
|
||||
|
||||
if (isBikeBroken == false)
|
||||
{
|
||||
// Bike is ok and user entered a feedback message.
|
||||
return $"request=user_feedback&message={WebUtility.UrlEncode(message)}";
|
||||
return $"request=user_feedback&bike={bikeId}&message={WebUtility.UrlEncode(message)}&authcookie={SessionCookie}{MerchantId}";
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
// User just marked bike as broken without comment.
|
||||
return $"request=user_feedback&bike_broken=1";
|
||||
return $"request=user_feedback&bike={bikeId}&bike_broken=1&authcookie={SessionCookie}{MerchantId}";
|
||||
}
|
||||
|
||||
// Bike is marked as broken and user added a comment.
|
||||
return $"request=user_feedback&bike_broken=1&message={WebUtility.UrlEncode(message)}";
|
||||
return $"request=user_feedback&bike={bikeId}&bike_broken=1&message={WebUtility.UrlEncode(message)}&authcookie={SessionCookie}{MerchantId}";
|
||||
}
|
||||
|
||||
private string GetBatteryPercentageKey(double batteryPercentage) => !double.IsNaN(batteryPercentage)
|
||||
private string GetBatteryPercentageParameters(double batteryPercentage) => !double.IsNaN(batteryPercentage)
|
||||
? $"&voltage={batteryPercentage.ToString(CultureInfo.InvariantCulture)}"
|
||||
: string.Empty;
|
||||
|
||||
private string GetLocationKey(LocationDto geolocation)
|
||||
/// <summary> Gets the geolocation parameter. </summary>
|
||||
/// <param name="geolocation">Geolocation or null.</param>
|
||||
private string GetLocationParameters(LocationDto geolocation)
|
||||
{
|
||||
if (geolocation == null)
|
||||
return string.Empty;
|
||||
|
@ -166,5 +177,16 @@ namespace TINK.Model.Repository.Request
|
|||
|
||||
return $"&gps={geolocation.Latitude.ToString(CultureInfo.InvariantCulture)},{geolocation.Longitude.ToString(CultureInfo.InvariantCulture)}&gps_accuracy={geolocation.Accuracy.Value.ToString(CultureInfo.InvariantCulture)}&gps_age={geolocation.Age.TotalSeconds}";
|
||||
}
|
||||
|
||||
/// <summary> Gets the geolocation parameter. </summary>
|
||||
/// <param name="geolocation">Geolocation or null.</param>
|
||||
private string GetSmartDeviceParameters(ISmartDevice smartDevice)
|
||||
=> smartDevice != null
|
||||
? $"{(!string.IsNullOrEmpty(smartDevice.Manufacturer) ? $"&user_device_manufaturer={smartDevice.Manufacturer})" : string.Empty)}" +
|
||||
$"{(!string.IsNullOrEmpty(smartDevice.Model) ? $"&user_device_model={smartDevice.Model}" : string.Empty)}" +
|
||||
$"{(!string.IsNullOrEmpty(smartDevice.PlatformText) ? $"&user_device_platform={smartDevice.PlatformText}" : string.Empty)}" +
|
||||
$"{(!string.IsNullOrEmpty(smartDevice.VersionText) ? $"&user_device_version={smartDevice.VersionText}" : string.Empty)}" +
|
||||
$"{(!string.IsNullOrEmpty(smartDevice.Identifier) ? $"&user_device_id={smartDevice.Identifier}" : string.Empty)}"
|
||||
: string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
[DataContract]
|
||||
public class AuthorizationResponse : ResponseBase
|
||||
|
@ -10,6 +10,6 @@ namespace TINK.Model.Repository.Response
|
|||
|
||||
/// <summary> Holds the group of the bike (TINK, Konrad, ...).</summary>
|
||||
[DataMember]
|
||||
public string user_group { get; private set; }
|
||||
public string[] user_group { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
[DataContract]
|
||||
public class AuthorizationoutResponse : ResponseBase
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
[DataContract]
|
||||
public class BikeInfoAvailable : BikeInfoBase
|
||||
|
@ -9,7 +9,7 @@ namespace TINK.Model.Repository.Response
|
|||
/// Position of the bike.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string gps { get; private set; }
|
||||
public GpsInfo gps { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
/// <summary> Full advertisement name.</summary>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System.Runtime.Serialization;
|
||||
using TINK.Repository.Response;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds info about a single bike.
|
||||
|
@ -13,13 +12,13 @@ namespace TINK.Model.Repository.Response
|
|||
/// Id of the bike.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int bike { get; private set; }
|
||||
public string bike { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id of the station.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int? station { get; private set; }
|
||||
public string station { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the localized (german) description of the bike.
|
||||
|
@ -32,7 +31,7 @@ namespace TINK.Model.Repository.Response
|
|||
/// Copri returns values "TINK", "Konrad".
|
||||
/// </remarks>
|
||||
[DataMember]
|
||||
public string bike_group { get; private set; }
|
||||
public string[] bike_group { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rental state.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
[DataContract]
|
||||
public class BikeInfoReservedOrBooked : BikeInfoAvailable
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the information about all bikes and is used for deserialization of copri answer.
|
||||
|
@ -13,6 +13,6 @@ namespace TINK.Model.Repository.Response
|
|||
/// Dictionary of bikes.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public Dictionary<int, BikeInfoAvailable> bikes { get; private set; }
|
||||
public Dictionary<string, BikeInfoAvailable> bikes { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
public class BikesReservedOccupiedResponse : ResponseBase
|
||||
{
|
||||
|
@ -9,6 +9,6 @@ namespace TINK.Model.Repository.Response
|
|||
/// Dictionary of bikes.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public Dictionary<int, BikeInfoReservedOrBooked> bikes_occupied { get; private set; }
|
||||
public Dictionary<string, BikeInfoReservedOrBooked> bikes_occupied { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
11
TINKLib/Repository/Response/CopriVersion.cs
Normal file
11
TINKLib/Repository/Response/CopriVersion.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
[DataContract]
|
||||
public class CopriVersion
|
||||
{
|
||||
[DataMember]
|
||||
public string copri_version { get; private set; }
|
||||
}
|
||||
}
|
23
TINKLib/Repository/Response/GpsInfo.cs
Normal file
23
TINKLib/Repository/Response/GpsInfo.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds info about a single bike.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class GpsInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Latitude position of the bike.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string latitude { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Longitude position of the bike.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string longitude { get; private set; }
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
public static class JsonConvert
|
||||
public static class JsonConvertRethrow
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializes COPRI responses in a consitent way for entire app.
|
|
@ -1,6 +1,6 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the information about a booking request and is used for deserialization of copri answer.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the information about a cancel booking request and is used for deserialization of copri answer.
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
[DataContract]
|
||||
public class ResponseBase
|
||||
public class ResponseBase : CopriVersion
|
||||
{
|
||||
[DataMember]
|
||||
public string response_state { get; private set; }
|
||||
|
@ -17,9 +17,6 @@ namespace TINK.Model.Repository.Response
|
|||
[DataMember]
|
||||
public string authcookie { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string copri_version { get; private set; }
|
||||
|
||||
/// <summary> Textual description of response. </summary>
|
||||
public new string ToString()
|
||||
{
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
[DataContract]
|
||||
public class ResponseContainer<T>
|
||||
{
|
||||
[DataMember]
|
||||
public T tinkjson { get; private set; }
|
||||
public T shareejson { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Serializes object to string.
|
||||
|
@ -14,12 +14,12 @@ namespace TINK.Model.Repository.Response
|
|||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
if (tinkjson == null)
|
||||
if (shareejson == null)
|
||||
{
|
||||
return "Response container does not hold no entry.";
|
||||
}
|
||||
|
||||
return tinkjson.ToString();
|
||||
return shareejson.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
using System.Linq;
|
||||
using TINK.Model.Repository.Exception;
|
||||
using TINK.MultilingualResources;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.MultilingualResources;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
public static class ResponseHelper
|
||||
{
|
||||
|
@ -83,7 +82,7 @@ namespace TINK.Model.Repository.Response
|
|||
/// <returns></returns>
|
||||
public static BikeInfoReservedOrBooked GetIsReserveResponseOk(
|
||||
this ReservationBookingResponse bookingResponse,
|
||||
int bikeId)
|
||||
string bikeId)
|
||||
{
|
||||
GetIsResponseOk(bookingResponse, string.Format(AppResources.ExceptionTextReservationBikeFailedGeneral, bikeId));
|
||||
|
||||
|
@ -111,7 +110,7 @@ namespace TINK.Model.Repository.Response
|
|||
/// <returns></returns>
|
||||
public static BikeInfoReservedOrBooked GetIsBookingResponseOk(
|
||||
this ReservationBookingResponse bookingResponse,
|
||||
int bikeId)
|
||||
string bikeId)
|
||||
{
|
||||
GetIsResponseOk(bookingResponse, string.Format(AppResources.ExceptionTextRentingBikeFailedGeneral, bikeId));
|
||||
|
||||
|
@ -134,7 +133,7 @@ namespace TINK.Model.Repository.Response
|
|||
/// <returns>Verified response.</returns>
|
||||
public static T GetIsResponseOk<T>(this T response, string textOfAction) where T : ResponseBase
|
||||
{
|
||||
if (response == null)
|
||||
if (response == null || response.response_state == null)
|
||||
{
|
||||
throw new InvalidResponseException<T>(textOfAction, null);
|
||||
}
|
||||
|
@ -161,7 +160,7 @@ namespace TINK.Model.Repository.Response
|
|||
/// <returns>Verified response.</returns>
|
||||
public static ReservationCancelReturnResponse GetIsCancelReservationResponseOk(
|
||||
this ReservationCancelReturnResponse cancelBookingResponse,
|
||||
int bikeId)
|
||||
string bikeId)
|
||||
{
|
||||
GetIsResponseOk<ResponseBase>(cancelBookingResponse, BIKES_CANCELREQUEST_ACTIONTEXT);
|
||||
|
||||
|
@ -184,7 +183,7 @@ namespace TINK.Model.Repository.Response
|
|||
/// <returns>Verified response.</returns>
|
||||
public static ReservationCancelReturnResponse GetIsReturnBikeResponseOk(
|
||||
this ReservationCancelReturnResponse returnBikeResponse,
|
||||
int bikeId)
|
||||
string bikeId)
|
||||
{
|
||||
// Check if bike is at station.
|
||||
if (NotAtStationException.IsNotAtStation(returnBikeResponse.response_state.ToUpper(), out NotAtStationException notAtStationException))
|
||||
|
@ -219,22 +218,8 @@ namespace TINK.Model.Repository.Response
|
|||
/// <returns></returns>
|
||||
public static BikesReservedOccupiedResponse GetBikesOccupiedNone(string p_strSesstionCookie = null)
|
||||
{
|
||||
var l_oJson = BIKES_OCCUPIED_REQUEST_NONE_FILE.Replace(@"""authcookie"": """"", @"""authcookie"": """ + (p_strSesstionCookie ?? string.Empty) + @"""");
|
||||
return CopriCallsStatic.DeserializeBikesOccupiedResponse(l_oJson);
|
||||
var l_oJson = CopriCallsMonkeyStore.BIKESOCCUPIED.Replace(@"""authcookie"": """"", @"""authcookie"": """ + (p_strSesstionCookie ?? string.Empty) + @"""");
|
||||
return CopriCallsStatic.DeserializeResponse(@"{ ""shareejson"" : " + l_oJson + "}", (version) => new BikesReservedOccupiedResponse());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds an empty bikes occupied response.
|
||||
/// </summary>
|
||||
private const string BIKES_OCCUPIED_REQUEST_NONE_FILE = @"
|
||||
{
|
||||
""tinkjson"": {
|
||||
""response_state"": ""OK"",
|
||||
""bikes_occupied"": { },
|
||||
""authcookie"": """",
|
||||
""response"": ""user_bikes_occupied"",
|
||||
""apiserver"": ""https://tinkwwp.copri-bike.de""
|
||||
}
|
||||
}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the information about all stations and is used for deserialization of copri answer.
|
||||
|
@ -19,10 +19,10 @@ namespace TINK.Model.Repository.Response
|
|||
/// Unique id of the station.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public int station { get; private set; }
|
||||
public string station { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string station_group { get; private set; }
|
||||
public string[] station_group { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string description { get; private set; }
|
||||
|
@ -31,13 +31,13 @@ namespace TINK.Model.Repository.Response
|
|||
/// Position of the station.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public string gps { get; private set; }
|
||||
public GpsInfo gps { get; private set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary of bikes.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public Dictionary<int, StationInfo> stations { get; private set; }
|
||||
public Dictionary<string, StationInfo> stations { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using TINK.Model.Repository.Response;
|
||||
|
||||
namespace TINK.Repository.Response
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
public class SubmitFeedbackResponse : ResponseBase
|
||||
{
|
||||
|
|
|
@ -6,7 +6,11 @@ namespace TINK.Repository.Response
|
|||
/// Holds tariff info for a single bike.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
#if USCSHARP9
|
||||
public record TariffDescription
|
||||
#else
|
||||
public class TariffDescription
|
||||
#endif
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the tariff.
|
||||
|
|
22
TINKLib/Repository/Response/VersionindependentResponse.cs
Normal file
22
TINKLib/Repository/Response/VersionindependentResponse.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Repository.Response
|
||||
{
|
||||
[DataContract]
|
||||
public class VersionindependentResponse
|
||||
{
|
||||
private CopriVersion _shareejson;
|
||||
|
||||
/// <summary> Root element for versions 4.0 and older. </summary>
|
||||
[DataMember]
|
||||
public CopriVersion tinkjson { get; private set; }
|
||||
|
||||
/// <summary> Root element from 4.1 and later. </summary>
|
||||
[DataMember]
|
||||
public CopriVersion shareejson
|
||||
{
|
||||
get => _shareejson ?? tinkjson;
|
||||
private set { _shareejson = value; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue