コード例 #1
0
        private void ThrowInvalidLanguageProvided(BuildScriptGeneratorContext context)
        {
            var languages = _programmingPlatforms.Select(sg => sg.Name);
            var exc       = new UnsupportedLanguageException($"'{context.Language}' platform is not supported. " +
                                                             $"Supported platforms are: {string.Join(", ", languages)}");

            _logger.LogError(exc, "Exception caught");
            throw exc;
        }
コード例 #2
0
        private bool IsCompatiblePlatform(
            RepositoryContext ctx,
            string platformName,
            string platformVersion,
            out Tuple <IProgrammingPlatform, string> platformResult)
        {
            platformResult = null;
            var selectedPlatform = _programmingPlatforms
                                   .Where(p => string.Equals(platformName, p.Name, StringComparison.OrdinalIgnoreCase))
                                   .FirstOrDefault();

            if (selectedPlatform == null)
            {
                var languages = string.Join(", ", _programmingPlatforms.Select(p => p.Name));
                var exec      = new UnsupportedLanguageException($"'{platformName}' platform is not supported. " +
                                                                 $"Supported platforms are: {languages}");
                _logger.LogError(exec, $"Exception caught, provided platform '{platformName}' is not supported.");
                throw exec;
            }

            if (!selectedPlatform.IsEnabled(ctx))
            {
                var exc = new UnsupportedLanguageException($"Platform '{selectedPlatform.Name}' has been disabled.");
                _logger.LogError(exc, $"Exception caught, platform '{selectedPlatform.Name}' has been disabled.");
                throw exc;
            }

            if (string.IsNullOrEmpty(platformVersion))
            {
                var detectionResult = selectedPlatform.Detect(ctx);
                if (detectionResult == null)
                {
                    _logger.LogError($"Platform '{platformName}' was not detected in the given repository.");
                    return(false);
                }
                else if (string.IsNullOrEmpty(detectionResult.LanguageVersion))
                {
                    _logger.LogError($"Platform '{platformName}' was detected in the given repository, but " +
                                     $"no compatible version was found.");
                    return(false);
                }

                _logger.LogDebug($"No platform version found, " +
                                 $"setting to the detected version '{detectionResult.LanguageVersion}'.");
                platformVersion = detectionResult.LanguageVersion;
            }

            _logger.LogDebug($"Detected platform '{platformName}' with version '{platformVersion}'.");
            platformResult = Tuple.Create(selectedPlatform, platformVersion);
            return(true);
        }