Example #1
0
 public string GetUniqueDatabaseName()
 {
     if (_uniqueDbName == null)
     {
         _uniqueDbName = new UniqueDbName(DatabaseNameTemplate, IsDebugMode());
     }
     return(_uniqueDbName.ToString());
 }
        public static bool TryParse(string uniqueName, string template, out UniqueDbName result)
        {
            if (uniqueName == null)
            {
                throw new ArgumentNullException(nameof(uniqueName));
            }
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            result = null;

            var patternString             = "^" + string.Format(template, RegexForId + "_" + RegexForDate) + "$";
            var regexForEligibleDatabases = new Regex(patternString, RegexOptions.IgnoreCase);
            var match = regexForEligibleDatabases.Match(uniqueName);

            if (!match.Success)
            {
                return(false);
            }

            Guid?uniqueId = null;

            if (Guid.TryParse(match.Groups["id"].Value, out var parsedId))
            {
                uniqueId = parsedId;
            }

            var isDebugMode = uniqueName.Contains(string.Format(template, $"{DebugSpec}_"));

            result = new UniqueDbName(template, isDebugMode)
            {
                _creationDate = DateTime.ParseExact(match.Groups["date"].Value, "yyyyMMdd", CultureInfo.InvariantCulture)
            };
            result.UniqueId = uniqueId ?? result.UniqueId;

            return(true);
        }