コード例 #1
0
        public override Task <bool> Execute(RecommendationTestInput input)
        {
            var propertyValue = input.ProjectDefinition.GetMSPropertyValue(input.Test.Condition.PropertyName);
            var result        = (propertyValue != null && input.Test.Condition.AllowedValues.Contains(propertyValue));

            return(Task.FromResult(result));
        }
コード例 #2
0
        public async Task <RulesResult> EvaluateRules(IList <RecommendationRuleItem> rules)
        {
            // If there are no rules the recipe must be invalid so don't include it.
            if (false == rules?.Any())
            {
                return(new RulesResult {
                    Include = false
                });
            }

            var availableTests = RecommendationTestFactory.LoadAvailableTests();
            var results        = new RulesResult {
                Include = true
            };

            foreach (var rule in rules !)
            {
                var allTestPass = true;
                foreach (var test in rule.Tests)
                {
                    if (!availableTests.TryGetValue(test.Type, out var testInstance))
                    {
                        throw new InvalidRecipeDefinitionException($"Invalid test type [{test.Type}] found in rule.");
                    }

                    var input = new RecommendationTestInput(
                        test,
                        _orchestratorSession.ProjectDefinition,
                        _orchestratorSession);

                    allTestPass &= await testInstance.Execute(input);

                    if (!allTestPass)
                    {
                        break;
                    }
                }

                results.Include &= ShouldInclude(rule.Effect, allTestPass);

                var effectOptions = GetEffectOptions(rule.Effect, allTestPass);

                if (effectOptions != null)
                {
                    if (effectOptions.PriorityAdjustment.HasValue)
                    {
                        results.PriorityAdjustment += effectOptions.PriorityAdjustment.Value;
                    }
                }
            }

            return(results);
        }
コード例 #3
0
        public override Task <bool> Execute(RecommendationTestInput input)
        {
            var directory = Path.GetDirectoryName(input.ProjectDefinition.ProjectPath);

            if (directory == null ||
                input.Test.Condition.FileName == null)
            {
                return(Task.FromResult(false));
            }

            var result = (Directory.GetFiles(directory, input.Test.Condition.FileName).Length == 1);

            return(Task.FromResult(result));
        }
コード例 #4
0
        public override Task <bool> Execute(RecommendationTestInput input)
        {
            var result = !string.IsNullOrEmpty(input.ProjectDefinition.GetMSPropertyValue(input.Test.Condition.PropertyName));

            return(Task.FromResult(result));
        }
コード例 #5
0
        public override Task <bool> Execute(RecommendationTestInput input)
        {
            var result = string.Equals(input.ProjectDefinition.SdkType, input.Test.Condition.Value, StringComparison.InvariantCultureIgnoreCase);

            return(Task.FromResult(result));
        }
コード例 #6
0
        public override Task <bool> Execute(RecommendationTestInput input)
        {
            var result = !string.IsNullOrEmpty(input.ProjectDefinition.GetPackageReferenceVersion(input.Test.Condition.NuGetPackageName));

            return(Task.FromResult(result));
        }
コード例 #7
0
 /// <summary>
 /// Executes the test
 /// </summary>
 /// <param name="input"></param>
 /// <returns>True for successful test pass, otherwise false.</returns>
 public abstract Task <bool> Execute(RecommendationTestInput input);