mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-19 03:27:29 +02:00
Version 3.0.270
This commit is contained in:
parent
67999ef4ae
commit
e0c75d5b37
81 changed files with 812 additions and 474 deletions
|
@ -60,7 +60,7 @@ namespace TINK.Model.Connector
|
|||
{
|
||||
response = (await CopriServer.DoAuthorizationAsync(mail, password, deviceId)).GetIsResponseOk(mail);
|
||||
}
|
||||
catch (System.Exception)
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}.");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue