Exemplo n.º 1
0
        private void InitializeAnalysisEngineToCurrentSettings()
        {
            // If script analysis has been disabled, just return null
            if (_configurationService.CurrentSettings.ScriptAnalysis.Enable != true)
            {
                if (_analysisEngineLazy != null && _analysisEngineLazy.IsValueCreated)
                {
                    _analysisEngineLazy.Value.Dispose();
                }

                _analysisEngineLazy = null;
                return;
            }

            // We may be triggered after the lazy factory is set,
            // but before it's been able to instantiate
            if (_analysisEngineLazy == null)
            {
                _analysisEngineLazy = new Lazy <PssaCmdletAnalysisEngine>(InstantiateAnalysisEngine);
                return;
            }
            else if (!_analysisEngineLazy.IsValueCreated)
            {
                return;
            }

            // Retrieve the current script analysis engine so we can recreate it after we've overridden it
            PssaCmdletAnalysisEngine currentAnalysisEngine = AnalysisEngine;

            // Clear the open file markers and set the new engine factory
            ClearOpenFileMarkers();
            _analysisEngineLazy = new Lazy <PssaCmdletAnalysisEngine>(() => RecreateAnalysisEngine(currentAnalysisEngine));
        }
        private PssaCmdletAnalysisEngine RecreateAnalysisEngine(PssaCmdletAnalysisEngine oldAnalysisEngine)
        {
            if (TryFindSettingsFile(out string settingsFilePath))
            {
                _logger.LogInformation($"Recreating analysis engine with rules at '{settingsFilePath}'");
                _pssaSettingsFilePath = settingsFilePath;
                return(oldAnalysisEngine.RecreateWithNewSettings(settingsFilePath));
            }

            _logger.LogInformation("PSScriptAnalyzer settings file not found. Falling back to default rules");
            return(oldAnalysisEngine.RecreateWithRules(s_defaultRules));
        }
        private void InitializeAnalysisEngineToCurrentSettings()
        {
            // We may be triggered after the lazy factory is set,
            // but before it's been able to instantiate
            if (_analysisEngineLazy == null)
            {
                _analysisEngineLazy = new Lazy <PssaCmdletAnalysisEngine>(InstantiateAnalysisEngine);
                return;
            }
            else if (!_analysisEngineLazy.IsValueCreated)
            {
                return;
            }

            // Retrieve the current script analysis engine so we can recreate it after we've overridden it
            PssaCmdletAnalysisEngine currentAnalysisEngine = AnalysisEngine;

            // Clear the open file markers and set the new engine factory
            ClearOpenFileMarkers();
            _analysisEngineLazy = new Lazy <PssaCmdletAnalysisEngine>(() => RecreateAnalysisEngine(currentAnalysisEngine));
        }