mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-07-07 21:36:35 +02:00
33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace TINK.Model.Connector
|
|
{
|
|
public static class TextToLockItTypeHelper
|
|
{
|
|
/// <summary> Lock id which representing a non valid id. </summary>
|
|
public const int INVALIDLOCKID = 0;
|
|
|
|
/// <summary> Lock GUID which representing a non valid id. </summary>
|
|
public readonly static Guid INVALIDLOCKGUID = new Guid();
|
|
|
|
/// <summary> First part of advertisement name.</summary>
|
|
public static string ISHAREITADVERTISMENTTITLE = "ISHAREIT";
|
|
|
|
/// <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;
|
|
|
|
return int.TryParse(Regex.Replace(advertisementName, $"{ISHAREITADVERTISMENTTITLE}[\\-,\\+ ]", ""), out int lockId)
|
|
? lockId
|
|
: INVALIDLOCKID;
|
|
}
|
|
}
|
|
}
|