2021-05-13 17:07:16 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
|
namespace ShareeBike.Model.Connector
|
2021-05-13 17:07:16 +02:00
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
public static class TextToLockItTypeHelper
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Lock id which representing a non valid id. </summary>
|
|
|
|
|
public const int INVALIDLOCKID = 0;
|
2021-05-13 17:07:16 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
/// <summary> Lock GUID which representing a non valid id. </summary>
|
|
|
|
|
public readonly static Guid INVALIDLOCKGUID = new Guid();
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
/// <summary> First part of advertisement name.</summary>
|
|
|
|
|
public static string ISHAREITADVERTISMENTTITLE = "ISHAREIT";
|
2021-05-13 17:07:16 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
/// <summary> Gets the ID part from advertisment name. </summary>
|
|
|
|
|
/// <remarks> Advertisement name is made up of name plus separator (+ or -) and a ID</remarks>
|
|
|
|
|
/// <param name="advertisementName">Advertisment name to extract info from.</param>
|
|
|
|
|
/// <returns>From information.</returns>
|
|
|
|
|
public static int GetBluetoothLockId(this string advertisementName)
|
|
|
|
|
{
|
|
|
|
|
var name = advertisementName?.ToUpper();
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
return INVALIDLOCKID;
|
2021-05-13 17:07:16 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
return int.TryParse(Regex.Replace(advertisementName, $"{ISHAREITADVERTISMENTTITLE}[\\-,\\+ ]", ""), out int lockId)
|
|
|
|
|
? lockId
|
|
|
|
|
: INVALIDLOCKID;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-13 17:07:16 +02:00
|
|
|
|
}
|