예제 #1
0
        /// <summary>
        /// Gets the list of allowed templates from <paramref name="templateGroup"/> as the result of constraints evaluation.
        /// </summary>
        internal static async Task <IEnumerable <CliTemplateInfo> > GetAllowedTemplatesAsync(this TemplateGroup templateGroup, TemplateConstraintManager constraintManager, CancellationToken cancellationToken)
        {
            IReadOnlyList <(ITemplateInfo Template, IReadOnlyList <TemplateConstraintResult> Result)> results =
                await constraintManager.EvaluateConstraintsAsync(templateGroup.Templates, cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();
            return(results.Where(r => r.Result.IsTemplateAllowed()).Select(r => r.Template).Cast <CliTemplateInfo>());
        }
예제 #2
0
        internal static async Task <IReadOnlyList <TemplateConstraintResult> > ValidateConstraintsAsync(TemplateConstraintManager constraintManager, ITemplateInfo template, CancellationToken cancellationToken)
        {
            if (!template.Constraints.Any())
            {
                return(Array.Empty <TemplateConstraintResult>());
            }

            IReadOnlyList <(ITemplateInfo Template, IReadOnlyList <TemplateConstraintResult> Result)> result = await constraintManager.EvaluateConstraintsAsync(new[] { template }, cancellationToken).ConfigureAwait(false);

            IReadOnlyList <TemplateConstraintResult> templateConstraints = result.Single().Result;

            if (templateConstraints.IsTemplateAllowed())
            {
                return(Array.Empty <TemplateConstraintResult>());
            }
            return(templateConstraints.Where(cr => cr.EvaluationStatus != TemplateConstraintResult.Status.Allowed).ToList());
        }