Version 3.0.360

This commit is contained in:
Anja 2023-02-22 14:03:35 +01:00
parent 5c0b2e70c9
commit faf68061f4
160 changed files with 2114 additions and 1932 deletions

View file

@ -26,12 +26,14 @@ namespace TINK.Repository
/// <param name="copriHost">Host to connect to. </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="smartDevice">Holds info about smart device.</param>
/// <param name="sessionCookie">Session cookie if user is logged in, null otherwise.</param>
public CopriCallsHttps(
Uri copriHost,
AppContextInfo appContextInfo,
string uiIsoLangugageName,
string sessionCookie = null)
string sessionCookie = null,
ISmartDevice smartDevice = null)
{
m_oCopriHost = copriHost
?? throw new System.Exception($"Can not construct {GetType()}- object. Uri of copri host must not be null.");
@ -41,8 +43,8 @@ namespace TINK.Repository
: throw new System.Exception($"Can not construct {GetType()}- object. User agent must not be null or empty.");
requestBuilder = string.IsNullOrEmpty(sessionCookie)
? new RequestBuilder(appContextInfo.MerchantId, uiIsoLangugageName) as IRequestBuilder
: new RequestBuilderLoggedIn(appContextInfo.MerchantId, uiIsoLangugageName, sessionCookie);
? new RequestBuilder(appContextInfo.MerchantId, uiIsoLangugageName, smartDevice) as IRequestBuilder
: new RequestBuilderLoggedIn(appContextInfo.MerchantId, uiIsoLangugageName, sessionCookie, smartDevice);
}
/// <summary> Holds the URL for rest calls.</summary>
@ -226,31 +228,27 @@ namespace TINK.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<DoReturnResponse> DoReturn(
string bikeId,
LocationDto location,
ISmartDevice smartDevice,
Uri operatorUri)
=> await DoReturn(
operatorUri?.AbsoluteUri ?? m_oCopriHost.AbsoluteUri,
requestBuilder.DoReturn(bikeId, location, smartDevice),
requestBuilder.DoReturn(bikeId, location),
UserAgent);
/// <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 DoReturn(
operatorUri?.AbsoluteUri ?? m_oCopriHost.AbsoluteUri,
requestBuilder.ReturnAndStartClosing(bikeId, smartDevice),
requestBuilder.ReturnAndStartClosing(bikeId),
UserAgent);
/// <summary> Submits feedback to copri server. </summary>
@ -325,15 +323,15 @@ namespace TINK.Repository
/// <param name="copriHost">Host to connect to. </param>
/// <param name="command">Command to log user out.</param>
public static async Task<AuthorizationoutResponse> DoAuthoutAsync(
string p_strCopriHost,
string p_oCommand,
string copriHost,
string command,
string userAgent = null)
{
#if !WINDOWS_UWP
string l_oLogoutResponse;
string logoutResponse;
try
{
l_oLogoutResponse = await PostAsync(p_strCopriHost, p_oCommand, userAgent);
logoutResponse = await PostAsync(copriHost, command, userAgent);
}
catch (System.Exception l_oException)
@ -352,7 +350,7 @@ namespace TINK.Repository
}
/// Extract session cookie from response.
return CopriCallsStatic.DeserializeResponse<AuthorizationoutResponse>(l_oLogoutResponse, (version) => new UnsupportedCopriVersionDetectedException());
return CopriCallsStatic.DeserializeResponse<AuthorizationoutResponse>(logoutResponse, (version) => new UnsupportedCopriVersionDetectedException());
#else
return null;
#endif
@ -361,19 +359,19 @@ namespace TINK.Repository
/// <summary>
/// Get list of stations from file.
/// </summary>
/// <param name="p_strCopriHost">URL of the copri host to connect to.</param>
/// <param name="p_oCommand">Command to get stations.</param>
/// <param name="copriHost">URL of the copri host to connect to.</param>
/// <param name="command">Command to get stations.</param>
/// <returns>List of files.</returns>
public static async Task<StationsAvailableResponse> GetStationsAsync(
string p_strCopriHost,
string p_oCommand,
string copriHost,
string command,
string userAgent = null)
{
#if !WINDOWS_UWP
string response;
try
{
response = await PostAsync(p_strCopriHost, p_oCommand, userAgent);
response = await PostAsync(copriHost, command, userAgent);
}
catch (System.Exception l_oException)
{
@ -401,7 +399,7 @@ namespace TINK.Repository
/// <summary> Gets a list of bikes from Copri. </summary>
/// <param name="copriHost">URL of the copri host to connect to.</param>
/// <param name="p_oCommand">Command to get bikes.</param>
/// <param name="command">Command to get bikes.</param>
/// <returns>Response holding list of bikes.</returns>
public static async Task<BikesAvailableResponse> GetBikesAvailableAsync(
string copriHost,
@ -440,19 +438,19 @@ namespace TINK.Repository
}
/// <summary> Gets a list of bikes reserved/ booked by acctive user from Copri.</summary>
/// <param name="p_strCopriHost">URL of the copri host to connect to.</param>
/// <param name="p_oCommand">Command to post.</param>
/// <param name="copriHost">URL of the copri host to connect to.</param>
/// <param name="command">Command to post.</param>
/// <returns>Response holding list of bikes.</returns>
public static async Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync(
string p_strCopriHost,
string p_oCommand,
string copriHost,
string command,
string userAgent = null)
{
#if !WINDOWS_UWP
string response;
try
{
response = await PostAsync(p_strCopriHost, p_oCommand, userAgent);
response = await PostAsync(copriHost, command, userAgent);
}
catch (System.Exception l_oException)
{

View file

@ -1296,8 +1296,8 @@ namespace TINK.Repository
SessionCookie = sessionCookie;
requestBuilder = string.IsNullOrEmpty(sessionCookie)
? new RequestBuilder(MerchantId, null /*UI language */) as IRequestBuilder
: new RequestBuilderLoggedIn(MerchantId, null /*UI language */, sessionCookie);
? new RequestBuilder(MerchantId, null /*UI language */, null /* smart device */) as IRequestBuilder
: new RequestBuilderLoggedIn(MerchantId, null /*UI language */, sessionCookie, null /* smart device */);
}
@ -1358,7 +1358,7 @@ namespace TINK.Repository
/// <summary>
/// Get list of stations from file.
/// </summary>
/// <param name="p_strCookie">Auto cookie of user if user is logged in.</param>
/// <param name="cookie">Auto cookie of user if user is logged in.</param>
/// <returns>List of files.</returns>
public async Task<StationsAvailableResponse> GetStationsAsync()
{
@ -1379,7 +1379,7 @@ namespace TINK.Repository
/// Gets canel booking request response.
/// </summary>
/// <param name="bikeId">Id of the bike to book.</param>
/// <param name="p_strCookie">Cookie of the logged in user.</param>
/// <param name="cookie">Cookie of the logged in user.</param>
/// <returns>Response on cancel booking request.</returns>
public async Task<ReservationCancelReturnResponse> DoCancelReservationAsync(string bikeId, Uri operatorUri)
{
@ -1546,14 +1546,14 @@ namespace TINK.Repository
/// <summary>
/// Gets stations response.
/// </summary>
/// <param name="p_strMerchantId">Id of the merchant.</param>
/// <param name="p_strCookie">Auto cookie of user if user is logged in.</param>
/// <param name="merchantId">Id of the merchant.</param>
/// <param name="cookie">Auto cookie of user if user is logged in.</param>
/// <param name="p_eSampleSet"></param>
/// <param name="p_lStageIndex"></param>
/// <returns></returns>
public static StationsAvailableResponse GetStationsAll(
string p_strMerchantId,
string p_strCookie = null,
string merchantId,
string cookie = null,
SampleSets p_eSampleSet = DEFAULT_SAMPLE_SET,
long p_lStageIndex = DEFAULT_STAGE_INDEX)
{
@ -1657,13 +1657,11 @@ namespace TINK.Repository
public Task<DoReturnResponse> DoReturn(
string bikeId,
LocationDto geolocation,
ISmartDevice smartDevice,
Uri operatorUri)
=> null;
public Task<DoReturnResponse> ReturnAndStartClosingAsync(
string bikeId,
ISmartDevice smartDevice,
Uri operatorUri)
=> throw new NotImplementedException();

View file

@ -117,20 +117,22 @@ namespace TINK.Repository
public string SessionCookie => requestBuilder.SessionCookie;
/// <summary> Initializes a instance of the copri monkey store object. </summary>
/// <param name="p_strMerchantId">Id of the merchant.</param>
/// <param name="merchantId">Id of the merchant.</param>
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
/// <param name="sessionCookie">Session cookie if user is logged in, null otherwise.</param>
/// <param name="smartDevice">Holds info about smart device.</param>
public CopriCallsMonkeyStore(
string merchantId,
string uiIsoLangugageName,
string sessionCookie = null,
ISmartDevice smartDevice = null,
TimeSpan? expiresAfter = null)
{
ExpiresAfter = expiresAfter ?? TimeSpan.FromSeconds(1);
requestBuilder = string.IsNullOrEmpty(sessionCookie)
? new RequestBuilder(merchantId, uiIsoLangugageName) as IRequestBuilder
: new RequestBuilderLoggedIn(merchantId, uiIsoLangugageName, sessionCookie);
? new RequestBuilder(merchantId, uiIsoLangugageName, smartDevice) as IRequestBuilder
: new RequestBuilderLoggedIn(merchantId, uiIsoLangugageName, sessionCookie, smartDevice);
// Ensure that store holds valid entries.
if (!Barrel.Current.Exists(requestBuilder.GetBikesAvailable()))
@ -201,18 +203,15 @@ namespace TINK.Repository
public Task<DoReturnResponse> DoReturn(
string bikeId,
LocationDto geolocation,
ISmartDevice smartDevice,
Uri operatorUri)
=> throw new System.Exception("Rückgabe im Offlinemodus nicht möglich!");
/// <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 Task<DoReturnResponse> ReturnAndStartClosingAsync(
string bikeId,
ISmartDevice smartDevice,
Uri operatorUri)
=> throw new System.Exception("Rückgabe mit Schloss schließen Befehl im Offlinemodus nicht möglich!");

View file

@ -107,13 +107,11 @@ namespace TINK.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<DoReturnResponse> DoReturn(
string bikeId,
LocationDto location,
ISmartDevice smartDevice,
Uri operatorUri);
/// <summary> Returns a bike and starts closing. </summary>
@ -123,7 +121,6 @@ namespace TINK.Repository
/// <returns>Response on returning request.</returns>
Task<DoReturnResponse> ReturnAndStartClosingAsync(
string bikeId,
ISmartDevice smartDevice,
Uri operatorUri);
/// <summary>

View file

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Model.Connector;
using TINK.Model.Device;
namespace TINK.Repository.Request
{
@ -26,7 +25,7 @@ namespace TINK.Repository.Request
string deviceId);
/// <summary> Logs user out. </summary>
/// <param name="p_strMerchantId">Id of the merchant.</param>
/// <param name="merchantId">Id of the merchant.</param>
/// <param name="p_strSessionCookie"> Cookie which identifies user.</param>
string DoAuthout();
@ -98,13 +97,13 @@ namespace TINK.Repository.Request
/// <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(string bikeId, LocationDto location, ISmartDevice smartDevice);
string DoReturn(string bikeId, LocationDto location);
/// <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>
/// <returns>Response to send to corpi.</returns>
string ReturnAndStartClosing(string bikeId, ISmartDevice smartDevice);
string ReturnAndStartClosing(string bikeId);
/// <summary>
/// Gets request for submiting feedback to copri server.

View file

@ -14,9 +14,11 @@ namespace TINK.Repository.Request
/// <summary> Constructs a object for building requests. </summary>
/// <param name="merchantId">Holds the id denoting the merchant.</param>
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
/// <param name="smartDevice">Holds info about smart device.</param>
public RequestBuilder(
string merchantId,
string uiIsoLangugageName)
string uiIsoLangugageName,
ISmartDevice smartDevice = null)
{
MerchantId = !string.IsNullOrEmpty(merchantId)
? merchantId
@ -25,6 +27,8 @@ namespace TINK.Repository.Request
UiIsoLanguageNameParameter = RequestBuilderHelper.GetLanguageParameter(WebUtility.UrlEncode(uiIsoLangugageName));
AuthCookieParameter = $"&authcookie={WebUtility.UrlEncode(MerchantId)}";
SmartDevice = smartDevice;
}
/// <summary>Holds the id denoting the merchant.</summary>
@ -39,6 +43,9 @@ namespace TINK.Repository.Request
/// <summary> Auth cookie parameter. </summary>
private string AuthCookieParameter { get; }
/// <summary>Holds info about smart device.</summary>
private ISmartDevice SmartDevice { get; }
/// <summary> Gets request to log user in. </summary>
/// <param name="mailAddress">Mailaddress of user to log in.</param>
/// <param name="password">Password to log in.</param>
@ -71,6 +78,7 @@ namespace TINK.Repository.Request
public string GetStations()
=> "request=stations_available" +
AuthCookieParameter +
SmartDevice.GetSmartDeviceParameters() +
UiIsoLanguageNameParameter;
/// <summary> Gets a list of bikes reserved/ booked by acctive user from Copri.</summary>
@ -125,14 +133,14 @@ namespace TINK.Repository.Request
public string BookReservedAndStartOpening(string bikeId)
=> throw new NotSupportedException();
public string DoReturn(string bikeId, LocationDto geolocation, ISmartDevice smartDevice)
public string DoReturn(string bikeId, LocationDto geolocation)
=> throw new NotSupportedException();
/// <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>
/// <returns>Response to send to corpi.</returns>
public string ReturnAndStartClosing(string bikeId, ISmartDevice smartDevice)
public string ReturnAndStartClosing(string bikeId)
=> throw new NotSupportedException();
/// <summary> Gets submit feedback request. </summary>

View file

@ -1,5 +1,7 @@
using System.Net;
using TINK.Model.Connector;
using TINK.Model.Device;
namespace TINK.Repository.Request
{
@ -29,5 +31,16 @@ namespace TINK.Repository.Request
return null;
}
}
/// <summary> Gets the smart device parameters. </summary>
/// <returns>in a format which is urlencode invariant.</returns>
public static string GetSmartDeviceParameters(this ISmartDevice smartDevice)
=> smartDevice != null
? $"{(!string.IsNullOrEmpty(smartDevice.Manufacturer) ? $"&user_device_manufacturer={WebUtility.UrlEncode(smartDevice.Manufacturer)}" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.Model) ? $"&user_device_model={WebUtility.UrlEncode(smartDevice.Model)}" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.Platform.ToString()) ? $"&user_device_platform={WebUtility.UrlEncode(smartDevice.Platform.ToString())}" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.VersionText) ? $"&user_device_version={WebUtility.UrlEncode(smartDevice.VersionText)}" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.Identifier) ? $"&user_device_id={WebUtility.UrlEncode(smartDevice.Identifier)}" : string.Empty)}"
: string.Empty;
}
}

View file

@ -17,10 +17,12 @@ namespace TINK.Repository.Request
/// <summary> Constructs a object for building requests. </summary>
/// <param name="merchantId">Holds the id denoting the merchant.</param>
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
/// <param name="smartDevice">Holds info about smart device.</param>
public RequestBuilderLoggedIn(
string merchantId,
string uiIsoLangugageName,
string sessionCookie)
string sessionCookie,
ISmartDevice smartDevice = null)
{
MerchantId = !string.IsNullOrEmpty(merchantId)
? merchantId
@ -33,6 +35,8 @@ namespace TINK.Repository.Request
UiIsoLanguageNameParameter = RequestBuilderHelper.GetLanguageParameter(WebUtility.UrlEncode(uiIsoLangugageName));
AuthCookieParameter = $"&authcookie={WebUtility.UrlEncode(SessionCookie)}{WebUtility.UrlEncode(MerchantId)}";
SmartDevice = smartDevice;
}
/// <summary> Holds the id denoting the merchant. </summary>
@ -47,6 +51,9 @@ namespace TINK.Repository.Request
/// <summary> Auth cookie parameter. </summary>
private string AuthCookieParameter { get; }
/// <summary>Holds info about smart device.</summary>
private ISmartDevice SmartDevice { get; }
/// <summary> Gets request to log user in. </summary>
/// <param name="mailAddress">Mailaddress of user to log in.</param>
/// <param name="password">Password to log in.</param>
@ -83,6 +90,7 @@ namespace TINK.Repository.Request
public string GetStations()
=> "request=stations_available" +
AuthCookieParameter +
SmartDevice.GetSmartDeviceParameters() +
UiIsoLanguageNameParameter;
/// <summary> Gets reservation request (synonym: reservation == request == reservieren). </summary>
@ -93,6 +101,7 @@ namespace TINK.Repository.Request
=> "request=booking_request" +
GetBikeIdParameter(bikeId) +
AuthCookieParameter +
SmartDevice.GetSmartDeviceParameters() +
UiIsoLanguageNameParameter;
/// <summary> Gets request to cancel reservation. </summary>
@ -175,6 +184,7 @@ namespace TINK.Repository.Request
AuthCookieParameter +
"&state=occupied" +
GetLockStateParameter(lock_state.unlocking) +
SmartDevice.GetSmartDeviceParameters() +
UiIsoLanguageNameParameter;
/// <summary> Gets the request to book and start opening the bike (synonym: booking == renting == mieten). </summary>
@ -193,14 +203,14 @@ namespace TINK.Repository.Request
/// <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(string bikeId, LocationDto geolocation, ISmartDevice smartDevice)
public string DoReturn(string bikeId, LocationDto geolocation)
=> "request=booking_update" +
GetBikeIdParameter(bikeId) +
AuthCookieParameter +
"&state=available" +
GetLocationParameters(geolocation) +
GetLockStateParameter(lock_state.locked) +
GetSmartDeviceParameters(smartDevice) +
SmartDevice.GetSmartDeviceParameters() +
GetLog() +
UiIsoLanguageNameParameter;
@ -209,13 +219,13 @@ namespace TINK.Repository.Request
/// <param name="bikeId">Id of the bike to return.</param>
/// <param name="smartDevice">Provides info about hard and software.</param>
/// <returns>Response to send to corpi.</returns>
public string ReturnAndStartClosing(string bikeId, ISmartDevice smartDevice)
public string ReturnAndStartClosing(string bikeId)
=> "request=booking_update" +
GetBikeIdParameter(bikeId) +
AuthCookieParameter +
"&state=available" +
GetLockStateParameter(lock_state.locking) +
GetSmartDeviceParameters(smartDevice) +
SmartDevice.GetSmartDeviceParameters() +
UiIsoLanguageNameParameter;
/// <summary> Gets submit feedback request. </summary>
@ -315,17 +325,6 @@ namespace TINK.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>
/// <returns>in a format which is urlencode invariant.</returns>
private static string GetSmartDeviceParameters(ISmartDevice smartDevice)
=> smartDevice != null
? $"{(!string.IsNullOrEmpty(smartDevice.Manufacturer) ? $"&user_device_manufaturer={WebUtility.UrlEncode(smartDevice.Manufacturer)})" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.Model) ? $"&user_device_model={WebUtility.UrlEncode(smartDevice.Model)}" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.Platform.ToString()) ? $"&user_device_platform={WebUtility.UrlEncode(smartDevice.Platform.ToString())}" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.VersionText) ? $"&user_device_version={WebUtility.UrlEncode(smartDevice.VersionText)}" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.Identifier) ? $"&user_device_id={WebUtility.UrlEncode(smartDevice.Identifier)}" : string.Empty)}"
: string.Empty;
/// <summary>
/// Gets logging entries from serilog.
/// </summary>