コード例 #1
0
ファイル: HostConstraint.cs プロジェクト: dotnet/templating
            protected override TemplateConstraintResult EvaluateInternal(string?args)
            {
                IReadOnlyList <HostInformation> supportedHosts = ParseArgs(args).ToList();

                //check primary host name first
                bool primaryHostNameMatch = false;

                foreach (HostInformation hostInfo in supportedHosts.Where(h => h.HostName.Equals(EnvironmentSettings.Host.HostIdentifier, StringComparison.OrdinalIgnoreCase)))
                {
                    primaryHostNameMatch = true;
                    if (hostInfo.Version == null || hostInfo.Version.CheckIfVersionIsValid(EnvironmentSettings.Host.Version))
                    {
                        return(TemplateConstraintResult.CreateAllowed(this));
                    }
                }
                if (!primaryHostNameMatch)
                {
                    //if there is no primary host name, check fallback host names
                    foreach (HostInformation hostInfo in supportedHosts.Where(h => EnvironmentSettings.Host.FallbackHostTemplateConfigNames.Contains(h.HostName, StringComparer.OrdinalIgnoreCase)))
                    {
                        if (hostInfo.Version == null || hostInfo.Version.CheckIfVersionIsValid(EnvironmentSettings.Host.Version))
                        {
                            return(TemplateConstraintResult.CreateAllowed(this));
                        }
                    }
                }
                string errorMessage = string.Format(LocalizableStrings.HostConstraint_Message_Restricted, EnvironmentSettings.Host.HostIdentifier, EnvironmentSettings.Host.Version, supportedHosts.ToCsvString());

                return(TemplateConstraintResult.CreateRestricted(this, errorMessage));
            }
コード例 #2
0
 public TemplateConstraintResult Evaluate(string?args)
 {
     if (args == "yes")
     {
         return(TemplateConstraintResult.CreateAllowed(this));
     }
     else if (args == "no")
     {
         return(TemplateConstraintResult.CreateRestricted(this, "cannot run", "do smth"));
     }
     return(TemplateConstraintResult.CreateEvaluationFailure(this, "bad params"));
 }
コード例 #3
0
            protected override TemplateConstraintResult EvaluateInternal(string?args)
            {
                IEnumerable <OSPlatform> supportedOS = ParseArgs(args);

                foreach (OSPlatform platform in supportedOS)
                {
                    if (RuntimeInformation.IsOSPlatform(platform))
                    {
                        return(TemplateConstraintResult.CreateAllowed(this));
                    }
                }
                return(TemplateConstraintResult.CreateRestricted(this, string.Format(LocalizableStrings.OSConstraint_Message_Restricted, RuntimeInformation.OSDescription, string.Join(", ", supportedOS))));
            }
コード例 #4
0
            protected override TemplateConstraintResult EvaluateInternal(string?args)
            {
                IReadOnlyList <string> supportedWorkloads = ParseArgs(args).ToList();

                bool isSupportedWorkload = supportedWorkloads.Any(_installedWorkloads.Contains);

                if (isSupportedWorkload)
                {
                    return(TemplateConstraintResult.CreateAllowed(this));
                }

                return(TemplateConstraintResult.CreateRestricted(
                           this,
                           string.Format(
                               LocalizableStrings.WorkloadConstraint_Message_Restricted,
                               string.Join(", ", supportedWorkloads),
                               string.Join(", ", _installedWorkloadsString)),
                           _remedySuggestionFactory(supportedWorkloads)
                           ));
            }
コード例 #5
0
            protected override TemplateConstraintResult EvaluateInternal(string?args)
            {
                IReadOnlyList <IVersionSpecification> supportedSdks = ParseArgs(args).ToList();

                foreach (IVersionSpecification supportedSdk in supportedSdks)
                {
                    if (supportedSdk.CheckIfVersionIsValid(_currentSdkVersion.ToString()))
                    {
                        return(TemplateConstraintResult.CreateAllowed(this));
                    }
                }

                string cta = _remedySuggestionFactory(
                    VersionSpecificationsToStrings(supportedSdks),
                    VersionSpecificationsToStrings(_installedSdkVersion.Where(installed =>
                                                                              supportedSdks.Any(supported => supported.CheckIfVersionIsValid(installed.ToString())))));

                return(TemplateConstraintResult.CreateRestricted(
                           this,
                           string.Format(LocalizableStrings.SdkConstraint_Message_Restricted, _currentSdkVersion.ToString(), supportedSdks.ToCsvString()),
                           cta));
            }