Пример #1
0
        public FrameworkPrecedenceOutput FrameworkPrecedence(FrameworkPrecedenceInput input)
        {
            var output = new FrameworkPrecedenceOutput
            {
                InputStatus = InputStatus.Missing,
                Input       = input
            };

            TFramework framework = default(TFramework);

            if (input != null &&
                !string.IsNullOrWhiteSpace(input.Framework))
            {
                try
                {
                    framework          = _logic.Parse(input.Framework);
                    output.Framework   = framework;
                    output.InputStatus = InputStatus.Valid;
                }
                catch (Exception)
                {
                    output.InputStatus = InputStatus.Invalid;
                }
            }

            if (output.InputStatus == InputStatus.Valid)
            {
                output.Precedence = GetPrecendence(output, framework);
            }

            return(output);
        }
Пример #2
0
        private IReadOnlyList <IFramework> GetPrecendence(FrameworkPrecedenceOutput output, TFramework framework)
        {
            // Get the initial set of candidates.
            var remainingCandidates = new HashSet <TFramework>(
                GetCandidates(output, framework),
                new FrameworkEqualityComparer());

            // Perform "get nearest" on the remaining set to find the next in precedence.
            var precedence = new List <IFramework>();

            while (remainingCandidates.Count > 0)
            {
                var nearest = _logic.GetNearest(framework, remainingCandidates);
                precedence.Add(nearest);
                remainingCandidates.Remove(nearest);
            }

            return(precedence);
        }
Пример #3
0
        private IEnumerable <TFramework> GetCandidates(FrameworkPrecedenceOutput output, TFramework framework)
        {
            IEnumerable <TFramework> candidates = GetFrameworkList();

            if (!output.Input.IncludeProfiles)
            {
                candidates = candidates.Where(x => string.IsNullOrEmpty(x.Profile) || IsPortable(x));
            }

            if (output.Input.ExcludePortable)
            {
                candidates = candidates.Where(x => !IsPortable(x));
            }

            var excludedIdentifiers = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            if (!string.IsNullOrWhiteSpace(output.Input.ExludedIdentifiers))
            {
                var split = output
                            .Input
                            .ExludedIdentifiers
                            .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select(x => x.Trim())
                            .Where(x => x.Length > 0)
                            .ToList();

                foreach (var identifier in split)
                {
                    excludedIdentifiers.Add(identifier);
                }

                if (excludedIdentifiers.Any())
                {
                    candidates = candidates.Where(x => !excludedIdentifiers.Contains(x.Identifier));
                }
            }

            // Narrow the list of frameworks down to those that are compatible.
            candidates = candidates.Where(x => _logic.IsCompatible(framework, x));

            return(candidates);
        }