Example #1
0
        public List<ParsedPart> Increment(ParsedVersionString parsedVersionString, int indexToStart)
        {
            if (!parsedVersionString.IsValid)
                throw new ApplicationException("Can't Increment an invalid parsedVersion String");
            if(indexToStart>parsedVersionString.VersionParts.Count-1)
                throw new ApplicationException("Index out of Range of parsed version parts");
            var parsedParts = parsedVersionString.VersionParts;
            var indexToWorkOn = indexToStart;
            var startingPoint = parsedParts[indexToWorkOn];

            if (startingPoint.IsChar && (startingPoint.Value == 90 || startingPoint.Value == 122))
                return Increment(parsedVersionString, indexToStart - 1);

            var i = indexToWorkOn;
            parsedParts[i].Value = parsedParts[i].Value + 1;
            if (parsedParts[i].IsChar && parsedParts[i].Value == 91)
                parsedParts[i].Value = 65;
            if (parsedParts[i].IsChar && parsedParts[i].Value == 123)
                parsedParts[i].Value = 97;
            i += 1;
            while (i < parsedParts.Count)
            {
                var workOn = parsedParts[i];
                workOn.Value = workOn.IsChar ? IsCapitalCharacters(workOn.Value) ? 'A' : 'a' : 0;
                i++;
            }

            return parsedParts;
        }
Example #2
0
        public ParsedVersionString Parse(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return new ParsedVersionString()
                       {
                           InvalidReason = "Input is empty"
                       }
            }
            ;


            var versionParts = input.Split('.');

            if (versionParts.Length != 4)
            {
                return new ParsedVersionString()
                       {
                           InvalidReason = "Post split length is not 4"
                       }
            }
            ;

            if (!int.TryParse(versionParts[0], out var _))
            {
                return new ParsedVersionString()
                       {
                           InvalidReason = "Major version has to be Int"
                       }
            }
            ;

            var versionPartValidator = new VersionPartParser();
            var parsedVersionString  = new ParsedVersionString()
            {
            };

            foreach (var versionPart in versionParts)
            {
                var parsedPart = versionPartValidator.Parse(versionPart);

                if (parsedPart == null)
                {
                    parsedVersionString.IsValid       = false;
                    parsedVersionString.InvalidReason = $"{versionPart} is invalid";
                    return(parsedVersionString);
                }

                parsedVersionString.IsValid = true;
                parsedVersionString.VersionParts.Add(parsedPart);
            }

            return(parsedVersionString);
        }
    }
}