mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-21 04:26:29 +02:00
Version 3.0.339
This commit is contained in:
parent
0468955d49
commit
52c9f6f1d9
43 changed files with 993 additions and 614 deletions
|
@ -1,11 +1,13 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TINK.Repository.Exception
|
||||
{
|
||||
public class NotAtStationException : InvalidResponseException
|
||||
{
|
||||
/// <summary> COPRI response status regular expression. </summary>
|
||||
public const string RETURNBIKE_FAILURE_STATUS_MESSAGE_UPPERCASE = "(FAILURE 2178: BIKE [0-9]+ OUT OF GEO FENCING\\. )([0-9]+)( METER DISTANCE TO NEXT STATION )([0-9]+)";
|
||||
public const string RETURNBIKE_FAILURE_STATUS_MESSAGE_CODE = "FAILURE 2178:";
|
||||
|
||||
/// <summary> COPRI response status regular expression to extract detail information. </summary>
|
||||
public const string RETURNBIKE_FAILURE_STATUS_MESSAGE_UPPERCASE = "(BIKE [A-Za-z0-9_]+ OUT OF GEO FENCING\\. )([0-9]+)( METER DISTANCE TO NEXT STATION )([A-Za-z0-9_]+)";
|
||||
|
||||
/// <summary> Prevents invalid use of exception. </summary>
|
||||
private NotAtStationException() : base(typeof(NotAtStationException).Name)
|
||||
|
@ -15,25 +17,36 @@ namespace TINK.Repository.Exception
|
|||
public static bool IsNotAtStation(string responseState, out NotAtStationException exception)
|
||||
{
|
||||
// Check if there are too many bikes requested/ booked.
|
||||
var match = Regex.Match(
|
||||
responseState.ToUpper(),
|
||||
RETURNBIKE_FAILURE_STATUS_MESSAGE_UPPERCASE);
|
||||
if (match.Groups.Count != 5
|
||||
|| !int.TryParse(match.Groups[2].ToString(), out int meters)
|
||||
|| !int.TryParse(match.Groups[4].ToString(), out int stationNr))
|
||||
var response = responseState.Trim().ToUpper();
|
||||
|
||||
if (!response.StartsWith(RETURNBIKE_FAILURE_STATUS_MESSAGE_CODE))
|
||||
{
|
||||
exception = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
exception = new NotAtStationException { Distance = meters, StationNr = stationNr };
|
||||
var match = Regex.Match(
|
||||
responseState.ToUpper(),
|
||||
RETURNBIKE_FAILURE_STATUS_MESSAGE_UPPERCASE);
|
||||
if (match.Groups.Count != 5
|
||||
|| !int.TryParse(match.Groups[2].ToString(), out int meters))
|
||||
{
|
||||
exception = new NotAtStationException();
|
||||
return true;
|
||||
}
|
||||
|
||||
exception = new NotAtStationException {
|
||||
Distance = meters,
|
||||
StationNr = match.Groups[4].ToString()
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary> Holds the maximum count of bikes allowed to reserve/ book.</summary>
|
||||
public int Distance { get; private set; }
|
||||
public int? Distance { get; private set; } = null;
|
||||
|
||||
/// <summary> Holds the maximum count of bikes allowed to reserve/ book.</summary>
|
||||
public int StationNr { get; private set; }
|
||||
public string StationNr { get; private set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue