Version 3.0.270

This commit is contained in:
Oliver Hauff 2022-01-04 18:59:16 +01:00
parent 67999ef4ae
commit e0c75d5b37
81 changed files with 812 additions and 474 deletions

View file

@ -27,7 +27,7 @@ namespace TINK.Model.Bike.BC
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string currentStationId = null,
string stationId = null,
Uri operatorUri = null,
TariffDescription tariffDescription = null)
{
@ -37,7 +37,7 @@ namespace TINK.Model.Bike.BC
IsDemo = isDemo ?? DEFAULTVALUEISDEMO;
Group = group ?? new List<string>();
CurrentStation = currentStationId;
StationId = stationId;
OperatorUri = operatorUri;
TariffDescription = tariffDescription;
}
@ -50,7 +50,7 @@ namespace TINK.Model.Bike.BC
bikeInfo.WheelType,
bikeInfo.TypeOfBike,
bikeInfo.Description,
bikeInfo.CurrentStation,
bikeInfo.StationId,
bikeInfo.OperatorUri,
bikeInfo.TariffDescription) { }
@ -58,13 +58,13 @@ namespace TINK.Model.Bike.BC
/// Constructs a bike info object for a available bike.
/// </summary>
/// <param name="id">Unique id of bike.</param>
/// <param name="currentStationId">Id of station where bike is located.</param>
/// <param name="stationId">Id of station where bike is located.</param>
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
/// <param name="tariffDescription">Hold tariff description of bike.</param>
/// <param name="wheelType"></param>
public BikeInfo(
string id,
string currentStationId,
string stationId,
Uri operatorUri = null,
TariffDescription tariffDescription = null,
bool? isDemo = DEFAULTVALUEISDEMO,
@ -79,7 +79,7 @@ namespace TINK.Model.Bike.BC
wheelType,
typeOfBike,
description,
currentStationId,
stationId,
operatorUri,
tariffDescription)
{
@ -179,7 +179,7 @@ namespace TINK.Model.Bike.BC
/// <summary>
/// Station a which bike is located, null otherwise.
/// </summary>
public string CurrentStation { get; }
public string StationId { get; }
/// <summary> Holds description about the tarif. </summary>
public TariffDescription TariffDescription { get; }
@ -210,7 +210,7 @@ namespace TINK.Model.Bike.BC
/// </summary>
public new string ToString()
{
return $"Id={Bike.Id}{(Bike.WheelType != null ? $", wheel(s)={Bike.WheelType}" : string.Empty)}{(Bike.TypeOfBike != null ? $"type={Bike.TypeOfBike}" : "")}, state={State}, location={(!string.IsNullOrEmpty(CurrentStation)? $"Station {CurrentStation}" : "On the road")}, is demo={IsDemo}.";
return $"Id={Bike.Id}{(Bike.WheelType != null ? $", wheel(s)={Bike.WheelType}" : string.Empty)}{(Bike.TypeOfBike != null ? $"type={Bike.TypeOfBike}" : "")}, state={State}, location={(!string.IsNullOrEmpty(StationId)? $"Station {StationId}" : "On the road")}, is demo={IsDemo}.";
}
}
}

View file

@ -24,7 +24,7 @@ namespace TINK.Model.Bike.BC
/// <param name="isDemo">True if device is demo device, false otherwise.</param>
/// <param name="dateTimeProvider">Provider for current date time to calculate remainig time on demand for state of type reserved.</param>
/// <param name="wheelType"></param>
/// <param name="currentStationId">Name of station where bike is located, null if bike is on the road.</param>
/// <param name="stationId">Name of station where bike is located, null if bike is on the road.</param>
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
/// <param name="tariffDescription">Hold tariff description of bike.</param>
/// <param name="stateInfo">Bike state info.</param>
@ -35,7 +35,8 @@ namespace TINK.Model.Bike.BC
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
string currentStationId = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
TariffDescription tariffDescription = null,
Func<DateTime> dateTimeProvider = null,
@ -46,32 +47,36 @@ namespace TINK.Model.Bike.BC
m_oBike = new Bike(id, wheelType, typeOfBike, description);
m_oStateInfo = new StateInfoMutable(dateTimeProvider, stateInfo);
m_oStateInfo.PropertyChanged += (sender, eventargs) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(eventargs.PropertyName));
CurrentStation = currentStationId;
StationId = stationId;
StationName = stationName;
OperatorUri = operatorUri;
TariffDescription = tariffDescription;
}
/// <summary> Constructs a bike object from source. </summary>
public BikeInfoMutable(IBikeInfo p_oBike) : this(
p_oBike.Id,
p_oBike.IsDemo,
p_oBike.Group,
p_oBike.WheelType,
p_oBike.TypeOfBike,
p_oBike.Description,
p_oBike.CurrentStation,
p_oBike.OperatorUri,
p_oBike.TariffDescription,
public BikeInfoMutable(IBikeInfo bike, string stationName) : this(
bike.Id,
bike.IsDemo,
bike.Group,
bike.WheelType,
bike.TypeOfBike,
bike.Description,
bike.StationId,
stationName,
bike.OperatorUri,
bike.TariffDescription,
null,
p_oBike.State)
bike.State)
{
}
/// <summary>
/// Station a which bike is located, null otherwise.
/// </summary>
/// <summary> Id of station a which bike is located, null otherwise.</summary>
[DataMember]
public string CurrentStation { get; }
public string StationId { get; }
/// <summary> Name of station a which bike is located, null otherwise. </summary>
[DataMember]
public string StationName { get; }
/// <summary> Holds description about the tarif. </summary>
[DataMember]
@ -118,7 +123,7 @@ namespace TINK.Model.Bike.BC
/// <returns></returns>
public new string ToString()
{
return $"Id={Id}{(WheelType != null ? $", wheel(s)={WheelType}" : string.Empty)}{(TypeOfBike != null ? $", type={TypeOfBike}" : "")}, demo={IsDemo}, state={State.ToString()}, location={(!string.IsNullOrEmpty(CurrentStation) ? $"Station {CurrentStation}" : "On the road")}.";
return $"Id={Id}{(WheelType != null ? $", wheel(s)={WheelType}" : string.Empty)}{(TypeOfBike != null ? $", type={TypeOfBike}" : "")}, demo={IsDemo}, state={State.ToString()}, location={(!string.IsNullOrEmpty(StationId) ? $"Station {StationId}" : "On the road")}.";
}
}
}

View file

@ -37,7 +37,7 @@ namespace TINK.Model.Bike.BC
/// <summary>
/// Station a which bike is located, null otherwise.
/// </summary>
string CurrentStation { get; }
string StationId { get; }
/// <summary>
/// Uri of the operator or null, in case of single operator setup.

View file

@ -35,7 +35,7 @@ namespace TINK.Model.Bikes.Bike.BC
/// <summary>
/// Station a which bike is located, null otherwise.
/// </summary>
string CurrentStation { get; }
string StationId { get; }
/// <summary>
/// Holds the rent state of the bike.

View file

@ -1,5 +1,4 @@
using System;
using TINK.Model.Bikes.Bike;
using TINK.Model.Bikes.Bike.BluetoothLock;
namespace TINK.Model.Bike.BluetoothLock
@ -7,14 +6,15 @@ namespace TINK.Model.Bike.BluetoothLock
public class BikeInfoMutable : BC.BikeInfoMutable, IBikeInfoMutable
{
/// <summary> Constructs a bike object from source. </summary>
public BikeInfoMutable(BikeInfo bike) : base(
public BikeInfoMutable(BikeInfo bike, string stationName) : base(
bike.Id,
bike.IsDemo,
bike.Group,
bike.WheelType,
bike.TypeOfBike,
bike.Description,
bike.CurrentStation,
bike.StationId,
stationName,
bike.OperatorUri,
bike.TariffDescription,
() => DateTime.Now,

View file

@ -17,7 +17,7 @@ namespace TINK.Model
string selectedStation)
{
return new BikeCollection(bikesAtAnyStation?
.Where(bike => !string.IsNullOrEmpty(selectedStation) && bike.CurrentStation == selectedStation)
.Where(bike => !string.IsNullOrEmpty(selectedStation) && bike.StationId == selectedStation)
.ToDictionary(x => x.Id) ?? new Dictionary<string, BikeInfo>());
}

View file

@ -1,8 +1,9 @@
using System;
using Serilog;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using TINK.Model.Station;
using BikeInfo = TINK.Model.Bike.BC.BikeInfo;
using BikeInfoMutable = TINK.Model.Bike.BC.BikeInfoMutable;
@ -22,10 +23,11 @@ namespace TINK.Model.Bike
/// - removes bikes which are no more contained in bikes response
/// - updates state of all bikes from state contained in bikes response
/// </summary>
/// <param name="bikesAll"> Object holding bikes info from copri to update from.</param>
/// <param name="bikesAll"> Object holding bikes info from copri to update from. Holds station id but not station name.</param>
/// <param name="stations"> All stations to get station names from.</param>
/// <param name="p_oDateTimeProvider">Provices date time information.</param>
public void Update(
IEnumerable<BikeInfo> bikesAll)
public void Update(IEnumerable<BikeInfo> bikesAll,
IEnumerable<IStation> stations)
{
// Get list of current bikes by state(s) to update.
// Needed to remove bikes which switched state and have to be removed from collection.
@ -33,16 +35,21 @@ namespace TINK.Model.Bike
foreach (var bikeInfo in bikesAll ?? new List<BikeInfo>())
{
/// Check if bike has to be added to list of existing station.
// Get name of station form station id.
var stationName = stations?.FirstOrDefault(x => x.Id == bikeInfo.StationId)?.StationName ?? string.Empty;
if (string.IsNullOrEmpty(stationName))
Log.ForContext<BikeCollectionMutable>().Debug($"No name for station with id {bikeInfo.StationId} found.");
// Check if bike has to be added to list of existing station.
if (ContainsKey(bikeInfo.Id) == false)
{
// Bike does not yet exist in list of bikes.
Add(BikeInfoMutableFactory.Create(bikeInfo));
Add(BikeInfoMutableFactory.Create(bikeInfo, stationName));
continue;
}
// Update bike.
GetById(bikeInfo.Id).State.Load(bikeInfo.State);
GetById(bikeInfo.Id).State.Load(bikeInfo.State);
if (bikesToBeRemoved.Contains<string>(bikeInfo.Id))
{
@ -52,29 +59,29 @@ namespace TINK.Model.Bike
}
// Remove obsolete bikes.
foreach (var l_oId in bikesToBeRemoved)
foreach (var stationId in bikesToBeRemoved)
{
RemoveById(l_oId);
RemoveById(stationId);
}
}
/// <summary>
/// Adds a new bike to collecion of bike.
/// </summary>
/// <param name="p_oNewBike">New bike to add.</param>
/// <param name="newBike">New bike to add.</param>
/// <exception cref="Exception">Thrown if bike is not unique.</exception>
public new void Add(BikeInfoMutable p_oNewBike)
public new void Add(BikeInfoMutable newBike)
{
// Ensure that bike id of new bike is is unique
foreach (BikeInfoMutable l_oBike in Items)
foreach (BikeInfoMutable bike in Items)
{
if (l_oBike.Id == p_oNewBike.Id)
if (bike.Id == newBike.Id)
{
throw new Exception(string.Format("Can not add bike with {0} to collection ob bike. Id is not unnique.", p_oNewBike));
throw new Exception(string.Format("Can not add bike with {0} to collection ob bike. Id is not unnique.", newBike));
}
}
base.Add(p_oNewBike);
base.Add(newBike);
}
/// <summary>
@ -134,11 +141,11 @@ namespace TINK.Model.Bike
/// </summary>
private static class BikeInfoMutableFactory
{
public static BikeInfoMutable Create(BikeInfo bikeInfo)
public static BikeInfoMutable Create(BikeInfo bikeInfo, string stationName)
{
return (bikeInfo is BluetoothLock.BikeInfo bluetoothLockBikeInfo)
? new BluetoothLock.BikeInfoMutable(bluetoothLockBikeInfo)
: new BikeInfoMutable(bikeInfo);
? new BluetoothLock.BikeInfoMutable(bluetoothLockBikeInfo, stationName)
: new BikeInfoMutable(bikeInfo, stationName);
}
}
}

View file

@ -60,7 +60,7 @@ namespace TINK.Model.Connector
{
response = (await CopriServer.DoAuthorizationAsync(mail, password, deviceId)).GetIsResponseOk(mail);
}
catch (System.Exception)
catch (Exception)
{
throw;
}

View file

@ -23,9 +23,9 @@ namespace TINK.Model.Connector
/// <summary>Constructs a copri query object.</summary>
/// <param name="p_oCopriServer">Server which implements communication.</param>
public CommandLoggedIn(ICopriServerBase p_oCopriServer,
string p_strSessionCookie,
string p_strMail,
Func<DateTime> p_oDateTimeProvider) : base(p_oCopriServer, p_strSessionCookie, p_strMail, p_oDateTimeProvider)
string sessionCookie,
string mail,
Func<DateTime> dateTimeProvider) : base(p_oCopriServer, sessionCookie, mail, dateTimeProvider)
{
}
@ -36,14 +36,14 @@ namespace TINK.Model.Connector
/// If communication fails an TINK.Repository.Exception is thrown.
/// </summary>
/// <param name="p_oAccount">Account to use for login.</param>
public Task<IAccount> DoLogin(string p_strMail, string p_strPassword, string p_strDeviceId)
public Task<IAccount> DoLogin(string mail, string password, string deviceId)
{
if (string.IsNullOrEmpty(p_strMail))
if (string.IsNullOrEmpty(mail))
{
throw new ArgumentNullException("Can not loging user. Mail address must not be null or empty.");
}
throw new Exception($"Fehler beim Anmelden von unter {p_strMail}. Benutzer {Mail} ist bereits angemeldet.");
throw new Exception($"Fehler beim Anmelden von unter {mail}. Benutzer {Mail} ist bereits angemeldet.");
}
/// <summary> Logs user out. </summary>

View file

@ -25,12 +25,12 @@ namespace TINK.Model.Connector
ICachedCopriServer server = null )
{
Command = GetCommand(
server ?? new CopriProviderHttps(activeUri, TinkApp.MerchantId, appContextInfo, sessionCookie),
server ?? new CopriProviderHttps(activeUri, appContextInfo.MerchantId, appContextInfo, sessionCookie),
sessionCookie,
mail);
Query = GetQuery(
server ?? new CopriProviderHttps(activeUri, TinkApp.MerchantId, appContextInfo, sessionCookie, expiresAfter),
server ?? new CopriProviderHttps(activeUri, appContextInfo.MerchantId, appContextInfo, sessionCookie, expiresAfter),
sessionCookie,
mail);
}

View file

@ -14,18 +14,19 @@ namespace TINK.Model.Connector
/// <param name="p_strMail">Mail of user.</param>
/// <param name="server"> Provides addess to copri.</param>
public ConnectorCache(
AppContextInfo appContextInfo,
string sessionCookie,
string mail,
ICopriServer server = null)
{
Command = Connector.GetCommand(
server ?? new CopriProviderMonkeyStore(TinkApp.MerchantId, sessionCookie),
server ?? new CopriProviderMonkeyStore(appContextInfo.MerchantId, sessionCookie),
sessionCookie,
mail);
Query = GetQuery(
server ?? new CopriProviderMonkeyStore(TinkApp.MerchantId, sessionCookie),
server ?? new CopriProviderMonkeyStore(appContextInfo.MerchantId, sessionCookie),
sessionCookie,
mail);
}

View file

@ -21,7 +21,7 @@ namespace TINK.Model.Connector
{
return isConnected
? new Connector(activeUri, appContextInfo, sessionCookie, mail, expiresAfter: expiresAfter) as IConnector
: new ConnectorCache(sessionCookie, mail);
: new ConnectorCache(appContextInfo, sessionCookie, mail);
}
}
}

View file

@ -16,24 +16,24 @@ namespace TINK.Model.Connector
protected readonly Func<DateTime> DateTimeProvider;
/// <summary>Constructs a copri query object.</summary>
/// <param name="p_oCopriServer">Server which implements communication.</param>
public BaseLoggedIn(ICopriServerBase p_oCopriServer,
string p_strSessionCookie,
string p_strMail,
Func<DateTime> p_oDateTimeProvider) : base(p_oCopriServer)
/// <param name="copriServer">Server which implements communication.</param>
public BaseLoggedIn(ICopriServerBase copriServer,
string sessionCookie,
string mail,
Func<DateTime> p_oDateTimeProvider) : base(copriServer)
{
if (string.IsNullOrEmpty(p_strSessionCookie))
if (string.IsNullOrEmpty(sessionCookie))
throw new ArgumentException("Can not instantiate query object- object. Session cookie must never be null or emtpy.");
if (string.IsNullOrEmpty(p_strMail))
if (string.IsNullOrEmpty(mail))
throw new ArgumentException("Can not instantiate query object- object. Mail address must never be null or emtpy.");
DateTimeProvider = p_oDateTimeProvider
?? throw new ArgumentException("Can not instantiate connector- object. No date time provider object available.");
SessionCookie = p_strSessionCookie;
SessionCookie = sessionCookie;
Mail = p_strMail;
Mail = mail;
}
}
}

View file

@ -26,30 +26,30 @@ namespace TINK.Model.Connector
/// <summary>
/// Gets the position from StationInfo object.
/// </summary>
/// <param name="p_oStationInfo">Object to get information from.</param>
/// <param name="stationInfo">Object to get information from.</param>
/// <returns>Position information.</returns>
public static Station.Position GetPosition(this StationsAvailableResponse.StationInfo p_oStationInfo)
public static Station.Position GetPosition(this StationsAvailableResponse.StationInfo stationInfo)
{
return GetPosition(p_oStationInfo.gps);
return GetPosition(stationInfo.gps);
}
/// <summary> Gets the position from StationInfo object. </summary>
/// <param name="p_oAuthorizationResponse">Object to get information from.</param>
/// <param name="authorizationResponse">Object to get information from.</param>
/// <returns>Position information.</returns>
public static IEnumerable<string> GetGroup(this AuthorizationResponse p_oAuthorizationResponse)
public static IEnumerable<string> GetGroup(this AuthorizationResponse authorizationResponse)
{
try
{
return p_oAuthorizationResponse.user_group.GetGroup();
return authorizationResponse.user_group.GetGroup();
}
catch (Exception l_oException)
{
throw new Exception($"Can not get group of user from text \"{p_oAuthorizationResponse.user_group}\".", l_oException);
throw new Exception($"Can not get group of user from text \"{authorizationResponse.user_group}\".", l_oException);
}
}
/// <summary> Gets the position from StationInfo object. </summary>
/// <param name="p_oAuthorizationResponse">Object to get information from.</param>
/// <param name="group">Object to get information from.</param>
/// <returns>Position information.</returns>
public static IEnumerable<string> GetGroup(this string[] group)
{
@ -63,43 +63,50 @@ namespace TINK.Model.Connector
return new HashSet<string>(group).ToList();
}
/// <summary> Gets the position from StationInfo object. </summary>
/// <param name="p_oAuthorizationResponse">Object to get information from.</param>
/// <summary> Gets if user acknowldged ags or not. </summary>
/// <param name="authorizationResponse">Object to get information from.</param>
/// <returns>Position information.</returns>
public static string GetGroup(this IEnumerable<string> p_oGroup)
public static bool GetIsAgbAcknowledged(this AuthorizationResponse authorizationResponse)
=> int.TryParse(authorizationResponse?.agb_checked, out int result)
&& result != 0;
/// <summary> Gets the position from StationInfo object. </summary>
/// <param name="group">Object to get information from.</param>
/// <returns>Position information.</returns>
public static string GetGroup(this IEnumerable<string> group)
{
return string.Join(",", p_oGroup);
return string.Join(",", group);
}
/// <summary> Gets the position from StationInfo object. </summary>
/// <param name="p_oStationInfo">Object to get information from.</param>
/// <param name="stationInfo">Object to get information from.</param>
/// <returns>Position information.</returns>
public static IEnumerable<string> GetGroup(this StationsAvailableResponse.StationInfo p_oStationInfo)
public static IEnumerable<string> GetGroup(this StationsAvailableResponse.StationInfo stationInfo)
{
try
{
return p_oStationInfo.station_group.GetGroup();
return stationInfo.station_group.GetGroup();
}
catch (Exception l_oException)
{
throw new Exception($"Can not get group of stations from text \"{p_oStationInfo.station_group}\".", l_oException);
throw new Exception($"Can not get group of stations from text \"{stationInfo.station_group}\".", l_oException);
}
}
/// <summary>
/// Gets the position from StationInfo object.
/// </summary>
/// <param name="p_oBikeInfo">Object to get information from.</param>
/// <param name="bikeInfo">Object to get information from.</param>
/// <returns>Position information.</returns>
public static InUseStateEnum GetState(this BikeInfoBase p_oBikeInfo)
public static InUseStateEnum GetState(this BikeInfoBase bikeInfo)
{
var l_oState = p_oBikeInfo.state;
var l_oState = bikeInfo.state;
if (string.IsNullOrEmpty(l_oState))
{
throw new InvalidResponseException<BikeInfoBase>(
string.Format("Unknown reservation state detected. Member {0}.{1}.", typeof(BikeInfoBase), nameof(BikeInfoBase.state)),
p_oBikeInfo);
bikeInfo);
}
if (l_oState == "available")
@ -123,58 +130,58 @@ namespace TINK.Model.Connector
/// <summary>
/// Gets the from date information from JSON.
/// </summary>
/// <param name="p_oBikeInfo">JSON to get information from..</param>
/// <param name="bikeInfo">JSON to get information from..</param>
/// <returns>From information.</returns>
public static DateTime GetFrom(this BikeInfoReservedOrBooked p_oBikeInfo)
public static DateTime GetFrom(this BikeInfoReservedOrBooked bikeInfo)
{
return DateTime.Parse(p_oBikeInfo.start_time);
return DateTime.Parse(bikeInfo.start_time);
}
/// <summary>
/// Gets whether the bike is a trike or not.
/// </summary>
/// <param name="p_oBikeInfo">JSON to get information from..</param>
/// <param name="bikeInfo">JSON to get information from..</param>
/// <returns>From information.</returns>
public static bool? GetIsDemo(this BikeInfoBase p_oBikeInfo)
public static bool? GetIsDemo(this BikeInfoBase bikeInfo)
{
return p_oBikeInfo?.description != null
? p_oBikeInfo.description.ToUpper().Contains(DEMOBIKEMARKER)
return bikeInfo?.description != null
? bikeInfo.description.ToUpper().Contains(DEMOBIKEMARKER)
: (bool?) null;
}
/// <summary>
/// Gets whether the bike is a trike or not.
/// </summary>
/// <param name="p_oBikeInfo">JSON to get information from..</param>
/// <param name="bikeInfo">JSON to get information from.</param>
/// <returns>From information.</returns>
public static IEnumerable<string> GetGroup(this BikeInfoBase p_oBikeInfo)
public static IEnumerable<string> GetGroup(this BikeInfoBase bikeInfo)
{
try
{
return p_oBikeInfo?.bike_group?.GetGroup()?.ToList() ?? new List<string>();
return bikeInfo?.bike_group?.GetGroup()?.ToList() ?? new List<string>();
}
catch (System.Exception l_oException)
{
throw new System.Exception($"Can not get group of user from text \"{p_oBikeInfo.bike_group}\".", l_oException);
throw new System.Exception($"Can not get group of user from text \"{bikeInfo.bike_group}\".", l_oException);
}
}
/// <summary> Gets whether the bike has a bord computer or not. </summary>
/// <param name="p_oBikeInfo">JSON to get information from.</param>
/// <param name="bikeInfo">JSON to get information from.</param>
/// <returns>From information.</returns>
public static bool GetIsManualLockBike(this BikeInfoBase p_oBikeInfo)
public static bool GetIsManualLockBike(this BikeInfoBase bikeInfo)
{
return !string.IsNullOrEmpty(p_oBikeInfo.system)
&& p_oBikeInfo.system.ToUpper().StartsWith("LOCK");
return !string.IsNullOrEmpty(bikeInfo.system)
&& bikeInfo.system.ToUpper().StartsWith("LOCK");
}
/// <summary> Gets whether the bike has a bord computer or not. </summary>
/// <param name="p_oBikeInfo">JSON to get information from..</param>
/// <param name="bikeInfo">JSON to get information from..</param>
/// <returns>From information.</returns>
public static bool GetIsBluetoothLockBike(this BikeInfoBase p_oBikeInfo)
public static bool GetIsBluetoothLockBike(this BikeInfoBase bikeInfo)
{
return !string.IsNullOrEmpty(p_oBikeInfo.system)
&& p_oBikeInfo.system.ToUpper().StartsWith("ILOCKIT");
return !string.IsNullOrEmpty(bikeInfo.system)
&& bikeInfo.system.ToUpper().StartsWith("ILOCKIT");
}
/// <summary> Gets whether the bike has a bord computer or not. </summary>
@ -342,13 +349,22 @@ namespace TINK.Model.Connector
: null;
}
/// <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);
}
/// <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)
=> response!= null
&& !string.IsNullOrEmpty(response.copri_version)
&& Version.TryParse(response.copri_version, out Version copriVersion)
=> response.TryGetCopriVersion(out Version copriVersion)
? copriVersion
: throw new InvalidResponseException($"Can not get version info from copri response {response?.copri_version}.");
}

View file

@ -85,7 +85,9 @@ namespace TINK.Model.Connector
/// <param name="response">Response to get data from.</param>
/// <returns>General data object initialized form COPRI response.</returns>
public static GeneralData GetGeneralData(this ResponseBase response)
=> new GeneralData(response.merchant_message, response.GetCopriVersion());
=> new GeneralData(response.merchant_message, response.TryGetCopriVersion(out Version copriVersion)
? new Version(0,0)
: copriVersion);
/// <summary> Gets account object from login response.</summary>
/// <param name="merchantId">Needed to extract cookie from autorization response.</param>
@ -106,6 +108,7 @@ namespace TINK.Model.Connector
return new Account(
mail,
password,
loginResponse.GetIsAgbAcknowledged(),
loginResponse.authcookie?.Replace(merchantId, ""),
loginResponse.GetGroup(),
loginResponse.debuglevel == 1

View file

@ -36,7 +36,7 @@ namespace TINK.Model
public delegate bool SetCredentialsDelegate(string p_strMailAddress, string p_strPassword);
/// <summary>Returns the id of the app (sharee.bike) to be identified by copri.</summary>
public static string MerchantId => "oiF2kahH";
public static string MerchantId { get; private set; }
/// <summary>
/// Holds status about whants new page.
@ -160,6 +160,7 @@ namespace TINK.Model
Settings.Settings settings,
IStore accountStore,
Func<bool, Uri, string /* session cookie*/, string /* mail address*/, TimeSpan, IConnector> connectorFactory,
string merchantId,
IServicesContainer<IGeolocation> geolocationServicesContainer,
ILocksService locksService,
ISmartDevice device,
@ -179,6 +180,9 @@ namespace TINK.Model
ConnectorFactory = connectorFactory
?? throw new ArgumentException("Can not instantiate TinkApp- object. No connector factory object available.");
MerchantId = merchantId
?? throw new ArgumentException($"Can not instantiate {nameof(TinkApp)}. No merchant id available.");
Cipher = cipher ?? new Cipher();
var locksServices = locksService != null

View file

@ -49,6 +49,8 @@ namespace TINK.Model.User.Account
/// </summary>
public class Account : IAccount
{
public const bool DEFAULTISAGBACKNOWLEDGED = false;
/// <summary> Constructs an account object.</summary>
/// <param name="mail">Mail address of the account holder.</param>
/// <param name="password">Password.</param>
@ -58,12 +60,14 @@ namespace TINK.Model.User.Account
public Account(
string mail,
string password,
bool isAgbAcknowledged,
string sessionCookie,
IEnumerable<string> bikeGroup,
Permissions debugLevel = Permissions.None)
{
Mail = mail;
Pwd = password;
IsAgbAcknowledged = isAgbAcknowledged;
SessionCookie = sessionCookie;
DebugLevel = debugLevel;
Group = bikeGroup != null
@ -71,7 +75,7 @@ namespace TINK.Model.User.Account
: throw new ArgumentException("Can not instantiate account object. Reference to group list must not be empty.");
}
public Account(IAccount p_oSource) : this(p_oSource?.Mail, p_oSource?.Pwd, p_oSource?.SessionCookie, p_oSource?.Group, p_oSource?.DebugLevel ?? Permissions.None)
public Account(IAccount source) : this(source?.Mail, source?.Pwd, source?.IsAgbAcknowledged ?? DEFAULTISAGBACKNOWLEDGED, source?.SessionCookie, source?.Group, source?.DebugLevel ?? Permissions.None)
{
}
@ -81,6 +85,9 @@ namespace TINK.Model.User.Account
/// <summary>Password of to authenticate.</summary>
public string Pwd { get; }
/// <summary>True if user acknowleged agbs.</summary>
public bool IsAgbAcknowledged { get; }
/// <summary>Session cookie used to sign in to copri.</summary>
public string SessionCookie { get; }

View file

@ -29,7 +29,7 @@ namespace TINK.Model.User.Account
public string Mail
{
get { return m_oAccount.Mail; }
set { m_oAccount = new Account(value, m_oAccount.Pwd, m_oAccount.SessionCookie, m_oAccount.Group, m_oAccount.DebugLevel); }
set { m_oAccount = new Account(value, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>
@ -38,16 +38,19 @@ namespace TINK.Model.User.Account
public string Pwd
{
get { return m_oAccount.Pwd; }
set { m_oAccount = new Account(m_oAccount.Mail, value, m_oAccount.SessionCookie, m_oAccount.Group, m_oAccount.DebugLevel); }
set { m_oAccount = new Account(m_oAccount.Mail, value, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>True if user acknowleged agbs.</summary>
public bool IsAgbAcknowledged => m_oAccount.IsAgbAcknowledged;
/// <summary>
/// Session cookie used to sign in to copri.
/// </summary>
public string SessionCookie
{
get { return m_oAccount.SessionCookie; }
set { m_oAccount = new Account(m_oAccount.Mail, m_oAccount.Pwd, value, m_oAccount.Group, m_oAccount.DebugLevel); }
set { m_oAccount = new Account(m_oAccount.Mail, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, value, m_oAccount.Group, m_oAccount.DebugLevel); }
}
/// <summary>
@ -64,7 +67,7 @@ namespace TINK.Model.User.Account
public Permissions DebugLevel
{
get { return m_oAccount.DebugLevel; }
set { m_oAccount = new Account(m_oAccount.Mail, m_oAccount.Pwd, m_oAccount.SessionCookie, m_oAccount.Group, value); }
set { m_oAccount = new Account(m_oAccount.Mail, m_oAccount.Pwd, m_oAccount.IsAgbAcknowledged, m_oAccount.SessionCookie, m_oAccount.Group, value); }
}
}
}

View file

@ -9,6 +9,8 @@ namespace TINK.Model.User.Account
public string Pwd => null;
public bool IsAgbAcknowledged => false;
public string SessionCookie => null;
public Permissions DebugLevel => Permissions.None;

View file

@ -13,6 +13,9 @@ namespace TINK.Model.User.Account
/// <summary>Password of the account.</summary>
string Pwd { get; }
/// <summary>True if user acknowleged agbs.</summary>
bool IsAgbAcknowledged { get; }
/// <summary>Session cookie used to sign in to copri.</summary>
string SessionCookie { get; }

View file

@ -17,6 +17,9 @@ namespace TINK.Model.User.Account
/// <summary> Holds id of the mail address key. </summary>
private const string KEY_MAILADDRESS = "MailAddress";
/// <summary> Holds key for flag is agb acknowledged. </summary>
private const string KEY_ISAGBACKNOWLEDGED = "IsAgbAcknowledged";
public IAccount Delete(IAccount account)
{
SecureStorage.RemoveAll();
@ -27,15 +30,16 @@ namespace TINK.Model.User.Account
{
var mail = string.Empty;
var isAgbAcknowledged = Account.DEFAULTISAGBACKNOWLEDGED;
var sessionCookie = string.Empty;
var debugLevel = Permissions.None;
try
{
mail = await SecureStorage.GetAsync(KEY_MAILADDRESS);
bool.TryParse(await SecureStorage.GetAsync(KEY_ISAGBACKNOWLEDGED), out isAgbAcknowledged);
sessionCookie = await SecureStorage.GetAsync(KEY_SESSIONCOOKIE);
Enum.TryParse(await SecureStorage.GetAsync(KEY_DEBUGLEVEL), out debugLevel);
}
catch (Exception exception)
{
@ -45,6 +49,7 @@ namespace TINK.Model.User.Account
return new Account(
mail,
string.Empty,
isAgbAcknowledged,
sessionCookie,
new List<string>(),
debugLevel);
@ -55,6 +60,7 @@ namespace TINK.Model.User.Account
try
{
await SecureStorage.SetAsync(KEY_MAILADDRESS, mailAndPwd.Mail);
await SecureStorage.SetAsync(KEY_ISAGBACKNOWLEDGED, mailAndPwd.IsAgbAcknowledged.ToString());
await SecureStorage.SetAsync(KEY_SESSIONCOOKIE, mailAndPwd.SessionCookie);
await SecureStorage.SetAsync(KEY_DEBUGLEVEL, mailAndPwd.DebugLevel.ToString());
}

View file

@ -476,7 +476,7 @@ namespace TINK.Model
AppResources.ChangeLog3_0_266
},
{
new Version(3, 0, 267),
new Version(3, 0, 270),
AppResources.ChangeLog3_0_231 // Minor improvements.
}
};