Ejemplo n.º 1
0
        /// <summary>
        /// Finds provider by recursing one or more directories.
        /// </summary>
        /// <returns>An application model provider.</returns>
        public IApplicationModelProvider FindModelProvider()
        {
            _logger.LogInformation(InformationMessages.FindingModelProvider);

            if (_options.FindPath != null && _options.FindPath.Any())
            {
                FileInfo providerAssembly = null;

                foreach (var path in _options.FindPath)
                {
                    // Find plugin assembly locations
                    var assemblies = _pluginFinder.FindPluginAssemblies(path.FullName, _sharedTypes);

                    // Remove duplicates (based on filename, without path), if any
                    var distinctAssemblies = assemblies.Select(a => new FileInfo(a)).GroupBy(f => f.Name).Select(f => f.First());

                    if (distinctAssemblies.Any())
                    {
                        _logger.LogInformation(InformationMessages.AssemblyCountInPath, distinctAssemblies.Count(), path.FullName);

                        // There should be only one, so break after the first one found
                        providerAssembly = distinctAssemblies.First();
                        break;
                    }
                    else
                    {
                        _logger.LogDebug(TraceMessages.ModelProviderAssemblyNotFoundInPath, path.FullName);
                    }
                }

                if (providerAssembly != null)
                {
                    // Load provider into separate plugin host
                    _pluginHost.LoadPlugins(new string[1] {
                        providerAssembly.FullName
                    }, _sharedTypes);

                    return(_pluginHost.GetPlugins().Where(p => p is IApplicationModelProvider).Select(p => (IApplicationModelProvider)p).First());
                }
                else
                {
                    _logger.LogWarning(WarningMessages.ModelProviderAssemblyNotFound);
                }
            }

            return(null);
        }
        /// <summary>
        /// Finds components by recursing one or more directories.
        /// </summary>
        /// <param name="config">The runner configuration.</param>
        /// <returns>A list of stage runners.</returns>
        public IEnumerable <IStageRunner> FindComponents(IRunnerConfiguration config)
        {
            _logger.LogInformation(InformationMessages.FindingStageRunners);

            if (_options.FindPath != null && _options.FindPath.Any())
            {
                var stageRunnerAssemblies = new List <FileInfo>();

                foreach (var path in _options.FindPath)
                {
                    // Find plugin assembly locations
                    var assemblies = _pluginFinder.FindPluginAssemblies(path.FullName, _sharedTypes);

                    // Remove duplicates (based on filename, without path), if any
                    var distinctAssemblies = assemblies.Select(a => new FileInfo(a)).GroupBy(f => f.Name).Select(f => f.First());

                    if (distinctAssemblies.Any())
                    {
                        _logger.LogInformation(InformationMessages.AssemblyCountInPath, distinctAssemblies.Count(), path.FullName);

                        foreach (var assembly in distinctAssemblies)
                        {
                            stageRunnerAssemblies.Add(assembly);
                        }
                    }
                    else
                    {
                        _logger.LogDebug(TraceMessages.StageRunnerAssembliesNotFoundInPath, path.FullName);
                    }
                }

                if (stageRunnerAssemblies.Count > 0)
                {
                    // Load stage runners into separate plugin host
                    var distinctStageRunnerAssemblies = stageRunnerAssemblies.GroupBy(f => f.Name).Select(f => f.First().FullName);
                    _pluginHost.LoadPlugins(distinctStageRunnerAssemblies, _sharedTypes);

                    return(_pluginHost.GetPlugins().Where(p => p is IStageRunner).Select(p => (IStageRunner)p));
                }
                else
                {
                    _logger.LogWarning(WarningMessages.StageRunnerAssembliesNotFound);
                }
            }

            return(Enumerable.Empty <IStageRunner>());
        }