mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-23 07:36:31 +01:00
40 lines
1.6 KiB
C#
40 lines
1.6 KiB
C#
|
using System.Text.RegularExpressions;
|
|||
|
|
|||
|
namespace TINK.Model.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]+)";
|
|||
|
|
|||
|
/// <summary> Prevents invalid use of exception. </summary>
|
|||
|
private NotAtStationException() : base(typeof(NotAtStationException).Name)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
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))
|
|||
|
{
|
|||
|
exception = null;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
exception = new NotAtStationException { Distance = meters, StationNr = stationNr };
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary> Holds the maximum count of bikes allowed to reserve/ book.</summary>
|
|||
|
public int Distance { get; private set; }
|
|||
|
|
|||
|
/// <summary> Holds the maximum count of bikes allowed to reserve/ book.</summary>
|
|||
|
public int StationNr { get; private set; }
|
|||
|
}
|
|||
|
}
|