Example #1
0
 private void AddPackageToStack(Stack <string> stackOfPackageAndDependency, string packageName)
 {
     if (stackOfPackageAndDependency.Contains(packageName))
     {
         throw InputParserException.InvalidInputException(ErrorMessages.INPUT_CONTAINS_CYCLE);
     }
     else
     {
         stackOfPackageAndDependency.Push(packageName);
     }
 }
Example #2
0
        private void ValidateInput(string[] input)
        {
            //Test if input is null
            if (input == null)
            {
                throw InputParserException.InvalidInputException(ErrorMessages.NULL_INPUT_MESSAGE);
            }

            //Test that input contains null element.
            if (input.Any(x => x is null))
            {
                throw InputParserException.InvalidInputException(ErrorMessages.INVALID_INPUT_MESSAGE);
            }

            //Test if input contains ":" in every element
            if (input.Any(x => !x.Contains(":")))
            {
                throw InputParserException.InvalidInputException(ErrorMessages.INVALID_INPUT_MESSAGE);
            }
        }
Example #3
0
        public IEnumerable <string> ParseInput(string[] input)
        {
            ValidateInput(input);
            IDictionary <string, string> dependencies = ParseInputIntoPackageAndDependency(input);
            List <string> sequencedPackageNames       = new List <string>();


            foreach (var pkgDependency in dependencies)
            {
                string packageName = pkgDependency.Key;

                if (string.IsNullOrWhiteSpace(packageName))
                {
                    throw InputParserException.InvalidInputException(ErrorMessages.PACKAGENAME_IS_EMPTY);
                }
                if (!sequencedPackageNames.Contains(pkgDependency.Key, StringComparer.InvariantCultureIgnoreCase))
                {
                    IEnumerable <string> resolvedDependencies = ResolveDependenciesForPackage(pkgDependency, dependencies).ToList();
                    sequencedPackageNames.AddRange(resolvedDependencies);
                }
            }
            return(sequencedPackageNames.Distinct());
        }