Version 3.0.375

This commit is contained in:
Anja 2023-11-06 12:23:09 +01:00
parent 2c790239cb
commit ca080c87c0
194 changed files with 10092 additions and 10464 deletions

View file

@ -21,7 +21,7 @@ namespace TINK.Repository
public class CopriCallsHttps : ICopriServer
{
/// <summary> Builds requests.</summary>
private IRequestBuilder requestBuilder;
private readonly IRequestBuilder requestBuilder;
/// <summary> Initializes a instance of the copri calls https object. </summary>
/// <param name="copriHost">Host to connect to. </param>
@ -49,7 +49,7 @@ namespace TINK.Repository
}
/// <summary> Holds the URL for rest calls.</summary>
private Uri m_oCopriHost;
private readonly Uri m_oCopriHost;
/// <summary> Specifies name and version of app. </summary>
private string UserAgent { get; }
@ -84,9 +84,13 @@ namespace TINK.Repository
=> await DoAuthoutAsync(m_oCopriHost.AbsoluteUri, requestBuilder.DoAuthout(), UserAgent);
/// <summary>Gets bikes available.</summary>
/// <param name="operatorUri">Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host.</param>
/// <returns>Response holding list of bikes.</returns>
public async Task<BikesAvailableResponse> GetBikesAvailableAsync()
=> await GetBikesAvailableAsync(m_oCopriHost.AbsoluteUri, requestBuilder.GetBikesAvailable(), UserAgent);
public async Task<BikesAvailableResponse> GetBikesAvailableAsync(Uri operatorUri = null)
=> await GetBikesAvailableAsync(
operatorUri?.AbsoluteUri ?? m_oCopriHost.AbsoluteUri,
requestBuilder.GetBikesAvailable(),
UserAgent);
/// <summary> Gets a list of bikes reserved/ booked by active user. </summary>
/// <returns>Response holding list of bikes.</returns>

View file

@ -1326,13 +1326,14 @@ namespace TINK.Repository
return await Task.Run(() => DoAuthout(SessionCookie));
}
/// <summary>
/// Gets list of bikes from memory.
/// </summary>
/// <returns></returns>
public async Task<BikesAvailableResponse> GetBikesAvailableAsync()
/// <summary>
/// Gets list of bikes from memory.
/// <param name="operatorUri">Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host.</param>
/// </summary>
/// <returns></returns>
public async Task<BikesAvailableResponse> GetBikesAvailableAsync(Uri operatorUri = null)
{
return await Task.Run(() => GetBikesAvailable(null, SessionCookie, ActiveSampleSet, ActiveStageIndex));
return await Task.Run(() => GetBikesAvailable(null, SessionCookie, operatorUri, ActiveSampleSet, ActiveStageIndex));
}
/// <summary>
@ -1487,18 +1488,20 @@ namespace TINK.Repository
}
}
/// <summary>
/// Gets list of bikes from memory.
/// </summary>
/// <param name="merchantId">Id of the merchant.</param>
/// <param name="sessionCookie">Auto cookie of user if user is logged in.</param>
/// <param name="sampleSet">Set of samples.</param>
/// <param name="stageIndex">Index of the stage.</param>
/// <returns></returns>
public static BikesAvailableResponse GetBikesAvailable(
/// <summary>
/// Gets list of bikes from memory.
/// </summary>
/// <param name="merchantId">Id of the merchant.</param>
/// <param name="sessionCookie">Auto cookie of user if user is logged in.</param>
/// <param name="operatorUri">Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host.</param>
/// <param name="sampleSet">Set of samples.</param>
/// <param name="stageIndex">Index of the stage.</param>
/// <returns></returns>
public static BikesAvailableResponse GetBikesAvailable(
string merchantId,
string sessionCookie = null,
SampleSets sampleSet = DEFAULT_SAMPLE_SET,
Uri operatorUri = null,
SampleSets sampleSet = DEFAULT_SAMPLE_SET,
long stageIndex = DEFAULT_STAGE_INDEX)
{
switch (sampleSet)

View file

@ -15,7 +15,7 @@ namespace TINK.Repository
{
public class CopriCallsMonkeyStore : ICopriCache
{
/// <summary> Prevents concurrent communictation. </summary>
/// <summary> Prevents concurrent communication. </summary>
private object monkeyLock = new object();
/// <summary> Builds requests.</summary>
@ -235,14 +235,15 @@ namespace TINK.Repository
throw new System.Exception(AppResources.ErrorNoWeb);
}
public async Task<BikesAvailableResponse> GetBikesAvailableAsync()
/// <param name="operatorUri">Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host.</param>
public async Task<BikesAvailableResponse> GetBikesAvailableAsync(Uri operatorUri = null)
{
var l_oBikesAvailableTask = new TaskCompletionSource<BikesAvailableResponse>();
var bikesAvailableTask = new TaskCompletionSource<BikesAvailableResponse>();
lock (monkeyLock)
{
l_oBikesAvailableTask.SetResult(Barrel.Current.Get<BikesAvailableResponse>(requestBuilder.GetBikesAvailable()));
bikesAvailableTask.SetResult(Barrel.Current.Get<BikesAvailableResponse>($"{operatorUri?.AbsoluteUri ?? string.Empty}{requestBuilder.GetBikesAvailable()}"));
}
return await l_oBikesAvailableTask.Task;
return await bikesAvailableTask.Task;
}
public async Task<BikesReservedOccupiedResponse> GetBikesOccupiedAsync()
@ -322,21 +323,21 @@ namespace TINK.Repository
}
/// <summary> Adds a bikes response to cache.</summary>
/// <param name="operatorUri">Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host.</param>
/// <param name="bikes">Bikes to add.</param>
public void AddToCache(BikesAvailableResponse bikes)
{
AddToCache(bikes, ExpiresAfter);
}
public void AddToCache(BikesAvailableResponse bikes, Uri operatorUri = null)
=> AddToCache(bikes, ExpiresAfter, operatorUri);
/// <summary> Adds a bikes response to cache.</summary>
/// <param name="bikes">Bikes to add.</param>
/// <param name="expiresAfter">Time after which anser is considered to be expired.</param>
private void AddToCache(BikesAvailableResponse bikes, TimeSpan expiresAfter)
/// <param name="operatorUri">Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host.</param>
/// <param name="expiresAfter">Time after which answer is considered to be expired.</param>
private void AddToCache(BikesAvailableResponse bikes, TimeSpan expiresAfter, Uri operatorUri = null)
{
lock (monkeyLock)
{
Barrel.Current.Add(
requestBuilder.GetBikesAvailable(),
$"{operatorUri?.AbsoluteUri ?? string.Empty}{requestBuilder.GetBikesAvailable()}",
JsonConvertRethrow.SerializeObject(bikes),
expiresAfter);
}

View file

@ -159,8 +159,9 @@ namespace TINK.Repository
Task<StationsAvailableResponse> GetStationsAsync();
/// <summary> Gets a list of bikes from Copri. </summary>
/// <param name="operatorUri">Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host.</param>
/// <returns>Response holding list of bikes.</returns>
Task<BikesAvailableResponse> GetBikesAvailableAsync();
Task<BikesAvailableResponse> GetBikesAvailableAsync(Uri operatorUri = null);
/// <summary> Gets a list of bikes reserved/ booked by active user from Copri.</summary>
/// <returns>Response holding list of bikes.</returns>

View file

@ -104,7 +104,7 @@ namespace TINK.Repository.Response
/// Textual description of response.
/// </summary>
/// <returns>Object as text.</returns>
public new string ToString()
public override string ToString()
{
return $"Bike {bike}{(station != null ? $", at station {station}" : string.Empty)}{(!string.IsNullOrEmpty(description) ? $", {description}" : string.Empty)}{(!string.IsNullOrEmpty(state) ? $", status={state}" : string.Empty)}.";
}

View file

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace TINK.Repository.Response
@ -10,9 +10,15 @@ namespace TINK.Repository.Response
public class BikesAvailableResponse : ResponseBase
{
/// <summary>
/// Dictionary of bikes.
/// Dictionary of bikes available.
/// </summary>
[DataMember]
public Dictionary<string, BikeInfoAvailable> bikes { get; private set; }
/// <summary>
/// Dictionary of bikes reserved or booked.
/// </summary>
[DataMember]
public Dictionary<string, BikeInfoReservedOrBooked> bikes_occupied { get; private set; }
}
}

View file

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace TINK.Repository.Response

View file

@ -1,4 +1,4 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization;
namespace TINK.Repository.Response
{
@ -46,7 +46,7 @@ namespace TINK.Repository.Response
public string tariff_info_html { get; private set; }
/// <summary> Textual description of response. </summary>
public new string ToString()
public override string ToString()
{
return $"Response state is \"{response_state ?? string.Empty}\", " +
$"auth cookie is \"{authcookie ?? string.Empty}\" and response is \"{response_text ?? string.Empty}\", " +

View file

@ -41,5 +41,11 @@ namespace TINK.Repository.Response.Stations.Station
/// </summary>
[DataMember]
public Dictionary<string, BikeGroup> station_type { get; private set; }
/// <summary>
/// Holds the uri of the operator which manages the bikes at station/ the station.
/// </summary>
[DataMember]
public string uri_operator { get; private set; }
}
}