Beispiel #1
0
        /// <summary>
        /// Moves a package from one state to another.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="newState"></param>
        /// <exception cref="ArgumentException"></exception>
        private void MarkPackageAs(Package p, PackageEvaluationStates newState)
        {
            if (p == null)
            {
                throw new ArgumentException($"Cannot mark 'null' as solved.");
            }

            if (this.packagePool[PackageEvaluationStates.Ready].Contains(p))
            {
                this.packagePool[PackageEvaluationStates.Ready].Remove(p);
                this.packagePool[newState].Add(p);
            }
            else
            {
                var(found, state) = TryGetEvaluationStateForPackage(p, DefaultPackageState);
                if (found)
                {
                    throw new ArgumentException($"The package '{p.Name}' is not in the 'Ready'-state and thus cannot be marked solved. It was found in the '{state}'-state.");
                }
                else
                {
                    throw new ArgumentException($"The package '{p.Name}' does not exist in the storage.");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Searches the complete packagePool dictionary for the state of a package. Returns false if the package is not found.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="fallback"></param>
        /// <returns></returns>
        private (bool, PackageEvaluationStates) TryGetEvaluationStateForPackage(Package p, PackageEvaluationStates fallback)
        {
            foreach (var state in Enum.GetValues(typeof(PackageEvaluationStates)).Cast <PackageEvaluationStates>())
            {
                if (this.packagePool[state].Contains(p))
                {
                    return(true, state);
                }
            }

            return(false, fallback);
        }