2021-05-13 20:03:07 +02:00
|
|
|
|
using Serilog;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using TINK.Model.Bike;
|
2021-06-26 20:57:55 +02:00
|
|
|
|
using TINK.Repository.Exception;
|
|
|
|
|
using TINK.Repository.Response;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
using TINK.Model.Services.CopriApi.ServerUris;
|
|
|
|
|
using TINK.Model.State;
|
|
|
|
|
|
|
|
|
|
namespace TINK.Model.Connector
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Conversion helper functionality.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class TextToTypeHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Holds the text for demo bikes. </summary>
|
|
|
|
|
private const string DEMOBIKEMARKER = "DEMO";
|
|
|
|
|
|
|
|
|
|
/// <summary> Part text denoting two wheel cargo bike.. </summary>
|
|
|
|
|
private const string TWOWHEELCARGOMARKERFRAGMENT = "LONG";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the position from StationInfo object.
|
|
|
|
|
/// </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="stationInfo">Object to get information from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>Position information.</returns>
|
2022-01-22 18:16:10 +01:00
|
|
|
|
public static IPosition GetPosition(this StationsAvailableResponse.StationInfo stationInfo)
|
|
|
|
|
=> GetPosition(stationInfo.gps);
|
|
|
|
|
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <summary> Gets the position from StationInfo object. </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="authorizationResponse">Object to get information from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>Position information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static IEnumerable<string> GetGroup(this AuthorizationResponse authorizationResponse)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return authorizationResponse.user_group.GetGroup();
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception l_oException)
|
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
throw new Exception($"Can not get group of user from text \"{authorizationResponse.user_group}\".", l_oException);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets the position from StationInfo object. </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="group">Object to get information from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>Position information.</returns>
|
2021-06-26 20:57:55 +02:00
|
|
|
|
public static IEnumerable<string> GetGroup(this string[] group)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2021-06-26 20:57:55 +02:00
|
|
|
|
if (group == null || group.Length == 0)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2021-06-26 20:57:55 +02:00
|
|
|
|
// If not logged in stations groups are empty form COPRI version v4.1.
|
|
|
|
|
Log.Debug("Can not get goup form string. Group text can not be null.");
|
|
|
|
|
return new List<string>();
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 20:57:55 +02:00
|
|
|
|
return new HashSet<string>(group).ToList();
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <summary> Gets if user acknowldged ags or not. </summary>
|
|
|
|
|
/// <param name="authorizationResponse">Object to get information from.</param>
|
|
|
|
|
/// <returns>Position information.</returns>
|
|
|
|
|
public static bool GetIsAgbAcknowledged(this AuthorizationResponse authorizationResponse)
|
|
|
|
|
=> int.TryParse(authorizationResponse?.agb_checked, out int result)
|
|
|
|
|
&& result != 0;
|
|
|
|
|
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <summary> Gets the position from StationInfo object. </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="group">Object to get information from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>Position information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static string GetGroup(this IEnumerable<string> group)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return string.Join(",", group);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets the position from StationInfo object. </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="stationInfo">Object to get information from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>Position information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static IEnumerable<string> GetGroup(this StationsAvailableResponse.StationInfo stationInfo)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return stationInfo.station_group.GetGroup();
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
2021-06-26 20:57:55 +02:00
|
|
|
|
catch (Exception l_oException)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
throw new Exception($"Can not get group of stations from text \"{stationInfo.station_group}\".", l_oException);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the position from StationInfo object.
|
|
|
|
|
/// </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="bikeInfo">Object to get information from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>Position information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static InUseStateEnum GetState(this BikeInfoBase bikeInfo)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
var l_oState = bikeInfo.state;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(l_oState))
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidResponseException<BikeInfoBase>(
|
|
|
|
|
string.Format("Unknown reservation state detected. Member {0}.{1}.", typeof(BikeInfoBase), nameof(BikeInfoBase.state)),
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bikeInfo);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (l_oState == "available")
|
|
|
|
|
{
|
|
|
|
|
return InUseStateEnum.Disposable;
|
|
|
|
|
}
|
|
|
|
|
else if (l_oState == "reserved" ||
|
|
|
|
|
l_oState == "requested")
|
|
|
|
|
{
|
|
|
|
|
return InUseStateEnum.Reserved;
|
|
|
|
|
}
|
|
|
|
|
else if (l_oState == "booked" ||
|
|
|
|
|
l_oState == "occupied")
|
|
|
|
|
{
|
|
|
|
|
return InUseStateEnum.Booked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new CommunicationException(string.Format("Unknown bike state detected. State is {0}.", l_oState));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the from date information from JSON.
|
|
|
|
|
/// </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="bikeInfo">JSON to get information from..</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>From information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static DateTime GetFrom(this BikeInfoReservedOrBooked bikeInfo)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return DateTime.Parse(bikeInfo.start_time);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets whether the bike is a trike or not.
|
|
|
|
|
/// </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="bikeInfo">JSON to get information from..</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>From information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static bool? GetIsDemo(this BikeInfoBase bikeInfo)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return bikeInfo?.description != null
|
|
|
|
|
? bikeInfo.description.ToUpper().Contains(DEMOBIKEMARKER)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
: (bool?) null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets whether the bike is a trike or not.
|
|
|
|
|
/// </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="bikeInfo">JSON to get information from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>From information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static IEnumerable<string> GetGroup(this BikeInfoBase bikeInfo)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return bikeInfo?.bike_group?.GetGroup()?.ToList() ?? new List<string>();
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
2022-01-22 18:16:10 +01:00
|
|
|
|
catch (Exception l_oException)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-01-22 18:16:10 +01:00
|
|
|
|
throw new Exception($"Can not get group of user from text \"{bikeInfo.bike_group}\".", l_oException);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets whether the bike has a bord computer or not. </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="bikeInfo">JSON to get information from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>From information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static bool GetIsManualLockBike(this BikeInfoBase bikeInfo)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return !string.IsNullOrEmpty(bikeInfo.system)
|
|
|
|
|
&& bikeInfo.system.ToUpper().StartsWith("LOCK");
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets whether the bike has a bord computer or not. </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="bikeInfo">JSON to get information from..</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>From information.</returns>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public static bool GetIsBluetoothLockBike(this BikeInfoBase bikeInfo)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return !string.IsNullOrEmpty(bikeInfo.system)
|
|
|
|
|
&& bikeInfo.system.ToUpper().StartsWith("ILOCKIT");
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 22:15:15 +02:00
|
|
|
|
/// <summary> Gets whether the bike Is a Sigo bike or not. </summary>
|
|
|
|
|
/// <param name="bikeInfo">JSON to get information from..</param>
|
|
|
|
|
/// <returns>True if bike is a Sigo.</returns>
|
|
|
|
|
public static bool GetIsSigoBike(this BikeInfoBase bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
return !string.IsNullOrEmpty(bikeInfo.system)
|
|
|
|
|
&& bikeInfo.system.ToUpper().StartsWith("SIGO");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static LockModel? GetLockModel(this BikeInfoBase bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
if (GetIsBluetoothLockBike(bikeInfo))
|
|
|
|
|
return LockModel.ILockIt;
|
|
|
|
|
|
|
|
|
|
if (GetIsManualLockBike(bikeInfo))
|
|
|
|
|
return LockModel.BordComputer;
|
|
|
|
|
|
|
|
|
|
if (GetIsSigoBike(bikeInfo))
|
|
|
|
|
return LockModel.Sigo;
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <summary> Gets whether the bike has a bord computer or not. </summary>
|
|
|
|
|
/// <param name="bikeInfo">JSON to get information from..</param>
|
|
|
|
|
/// <returns>From information.</returns>
|
|
|
|
|
public static int GetBluetoothLockId(this BikeInfoAvailable bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
return TextToLockItTypeHelper.GetBluetoothLockId(bikeInfo?.Ilockit_ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets whether the bike has a bord computer or not. </summary>
|
|
|
|
|
/// <param name="bikeInfo">JSON to get information from..</param>
|
|
|
|
|
/// <returns>From information.</returns>
|
|
|
|
|
public static Guid GetBluetoothLockGuid(this BikeInfoAvailable bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
// return new Guid("00000000-0000-0000-0000-e57e6b9aee16");
|
|
|
|
|
return Guid.TryParse(bikeInfo?.Ilockit_GUID, out Guid lockGuid)
|
|
|
|
|
? lockGuid
|
|
|
|
|
: TextToLockItTypeHelper.INVALIDLOCKGUID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] GetUserKey(this BikeInfoReservedOrBooked bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
return GetKey(bikeInfo.K_u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] GetAdminKey(this BikeInfoReservedOrBooked bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
return GetKey(bikeInfo.K_a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] GetSeed(this BikeInfoReservedOrBooked bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
return GetKey(bikeInfo.K_seed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get array of keys from string of format "[12, -9, 5]"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="keyArrayText"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static byte[] GetKey(string keyArrayText)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(keyArrayText))
|
|
|
|
|
return new byte[0];
|
|
|
|
|
|
|
|
|
|
return Regex.Replace(keyArrayText, @"\[(.*)\]", "$1").Split(',').Select(x => (byte)sbyte.Parse(x)).ToArray();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
Log.Error("Can not extract K_u/ K_a/ or K_seed. Key {ArrayText} does not is not of expected format. {Exception}", keyArrayText, exception);
|
|
|
|
|
return new byte[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets whether the bike is a trike or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bikeInfo">JSON to get information from..</param>
|
|
|
|
|
/// <returns>From information.</returns>
|
|
|
|
|
public static WheelType? GetWheelType(this BikeInfoBase bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
var l_oDescription = bikeInfo.description;
|
|
|
|
|
|
|
|
|
|
if (l_oDescription == null)
|
|
|
|
|
{
|
|
|
|
|
// Can not get type of wheel if description text is empty.
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (WheelType l_oWheelType in Enum.GetValues(typeof(WheelType)))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (l_oDescription.ToUpper().Contains(l_oWheelType.ToString().ToUpper()))
|
|
|
|
|
{
|
|
|
|
|
return l_oWheelType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for custom value "Long".
|
|
|
|
|
if (l_oDescription.ToUpper().Contains(TWOWHEELCARGOMARKERFRAGMENT))
|
|
|
|
|
{
|
|
|
|
|
return WheelType.Two;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for Stadrad.
|
|
|
|
|
if (GetTypeOfBike(bikeInfo) == TypeOfBike.Citybike)
|
|
|
|
|
{
|
|
|
|
|
return WheelType.Two;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the type of bike.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bikeInfo">Object to get bike type from.</param>
|
|
|
|
|
/// <returns>Type of bike.</returns>
|
|
|
|
|
public static TypeOfBike? GetTypeOfBike(this BikeInfoBase bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
var l_oDescription = bikeInfo?.description;
|
|
|
|
|
|
|
|
|
|
if (l_oDescription == null)
|
|
|
|
|
{
|
|
|
|
|
// Can not get type of wheel if description text is empty.
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (TypeOfBike l_oTypeOfBike in Enum.GetValues(typeof(TypeOfBike)))
|
|
|
|
|
{
|
|
|
|
|
if (l_oDescription.ToUpper().Contains(l_oTypeOfBike.GetCopriText().ToUpper()))
|
|
|
|
|
{
|
|
|
|
|
return l_oTypeOfBike;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-22 18:16:10 +01:00
|
|
|
|
/// <summary> Get position from a ,- separated string. </summary>
|
|
|
|
|
/// <param name="gps">Text to extract positon from.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <returns>Position object.</returns>
|
2022-01-22 18:16:10 +01:00
|
|
|
|
public static IPosition GetPosition(Repository.Response.Position gps)
|
|
|
|
|
=> PositionFactory.Create(
|
|
|
|
|
double.TryParse(gps?.latitude, NumberStyles.Float, CultureInfo.InvariantCulture, out double latitude) ? latitude : double.NaN,
|
|
|
|
|
double.TryParse(gps?.longitude, NumberStyles.Float, CultureInfo.InvariantCulture, out double longitude) ? longitude : double.NaN);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
2022-01-22 18:16:10 +01:00
|
|
|
|
/// <summary> Get position from a ,- separated string. </summary>
|
|
|
|
|
/// <param name="gps">Text to extract positon from.</param>
|
|
|
|
|
/// <returns>Position object.</returns>
|
|
|
|
|
public static Map.IMapSpan GetMapSpan(this MapSpan mapSpan)
|
|
|
|
|
=> Map.MapSpanFactory.Create(
|
|
|
|
|
GetPosition(mapSpan?.center),
|
|
|
|
|
double.TryParse(mapSpan?.radius, NumberStyles.Float, CultureInfo.InvariantCulture, out double radius) ? radius: double.NaN);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
|
|
|
2022-01-22 18:16:10 +01:00
|
|
|
|
/// <summary> Gets text of bike from. </summary>
|
|
|
|
|
/// <param name="p_eType">Type to get text for.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetCopriText(this TypeOfBike p_eType)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
|
|
|
|
switch (p_eType)
|
|
|
|
|
{
|
|
|
|
|
case TypeOfBike.Citybike:
|
|
|
|
|
return "Stadtrad";
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return p_eType.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 22:15:15 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the locking state from response.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bikeInfo"> Response locking state from.</param>
|
|
|
|
|
/// <returns>Locking state</returns>
|
|
|
|
|
public static Bikes.Bike.CopriLock.LockingState GetCopriLockingState(this BikeInfoBase bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(bikeInfo?.lock_state))
|
|
|
|
|
return Bikes.Bike.CopriLock.LockingState.UnknownDisconnected;
|
|
|
|
|
|
|
|
|
|
if (bikeInfo.lock_state.ToUpper().Trim() == "locked".ToUpper())
|
|
|
|
|
return Bikes.Bike.CopriLock.LockingState.Closed;
|
|
|
|
|
|
|
|
|
|
if (bikeInfo.lock_state.ToUpper().Trim() == "locking".ToUpper())
|
|
|
|
|
return Bikes.Bike.CopriLock.LockingState.Closing;
|
|
|
|
|
|
|
|
|
|
if (bikeInfo.lock_state.ToUpper().Trim() == "unlocked".ToUpper())
|
|
|
|
|
return Bikes.Bike.CopriLock.LockingState.Open;
|
|
|
|
|
|
|
|
|
|
if (bikeInfo.lock_state.ToUpper().Trim() == "unlocking".ToUpper())
|
|
|
|
|
return Bikes.Bike.CopriLock.LockingState.Opening;
|
|
|
|
|
|
|
|
|
|
return Bikes.Bike.CopriLock.LockingState.UnknownDisconnected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the operator Uri from response.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bikeInfo"> Response to get uri from.</param>
|
|
|
|
|
/// <returns>Operatore Uri</returns>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
public static Uri GetOperatorUri(this BikeInfoBase bikeInfo)
|
|
|
|
|
{
|
|
|
|
|
return bikeInfo?.uri_operator != null && !string.IsNullOrEmpty(bikeInfo?.uri_operator)
|
|
|
|
|
? new Uri($"{bikeInfo.uri_operator}/{CopriServerUriList.REST_RESOURCE_ROOT}")
|
|
|
|
|
: null;
|
|
|
|
|
}
|
2021-06-26 20:57:55 +02:00
|
|
|
|
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <summary> Tries to get the copriversion from response.</summary>
|
|
|
|
|
/// <param name="response">Response to get version info from.</param>
|
|
|
|
|
/// <returns>COPRI version</returns>
|
|
|
|
|
public static bool TryGetCopriVersion(this CopriVersion response, out Version copriVersion)
|
|
|
|
|
{
|
|
|
|
|
copriVersion = new Version(0, 0);
|
|
|
|
|
return response != null
|
|
|
|
|
&& !string.IsNullOrEmpty(response.copri_version)
|
|
|
|
|
&& Version.TryParse(response.copri_version, out copriVersion);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 20:57:55 +02:00
|
|
|
|
/// <summary> Gets the copriversion from.</summary>
|
|
|
|
|
/// <param name="response">Response to get version info from.</param>
|
|
|
|
|
/// <returns>COPRI version</returns>
|
|
|
|
|
public static Version GetCopriVersion(this CopriVersion response)
|
2022-01-04 18:59:16 +01:00
|
|
|
|
=> response.TryGetCopriVersion(out Version copriVersion)
|
2021-06-26 20:57:55 +02:00
|
|
|
|
? copriVersion
|
|
|
|
|
: throw new InvalidResponseException($"Can not get version info from copri response {response?.copri_version}.");
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|