using System; using System.Text.RegularExpressions; namespace TINK.Model.Connector { public static class TextToLockItTypeHelper { /// Lock id which representing a non valid id. public const int INVALIDLOCKID = 0; /// Lock GUID which representing a non valid id. public readonly static Guid INVALIDLOCKGUID = new Guid(); /// First part of advertisement name. public static string ISHAREITADVERTISMENTTITLE = "ISHAREIT"; /// Gets the ID part from advertisment name. /// Advertisement name is made up of name plus separator (+ or -) and a ID /// Advertisment name to extract info from. /// From information. 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; } } }