public static IScannerHost GetScannerHost()
 {
     if (_host == null)
     {
         _host = new ScannerHost(_serviceProvider);
     }
     return(_host);
 }
 public static void CleanupFactory()
 {
     _backgroundScanner = null;
     _buildManager      = null;
     _taskProvider      = null;
     _host = null;
     _projectStores.Clear();
 }
Exemplo n.º 3
0
        private void OutputScanResults(IScanResult result)
        {
            if (result.Scanned)
            {
                if (!result.Passed)
                {
                    foreach (IScanHit hit in result.Results)
                    {
                        IIgnoreInstance thisIgnoreInstance = Factory.GetIgnoreInstance(result.FilePath, hit.LineText, hit.Term.Text, hit.Column);

                        if (!_ignoreInstances.Contains(thisIgnoreInstance))
                        {
                            if (hit.Warning != null)
                            {
                                if (null == _duplicateTerms.Find(
                                        delegate(string item)
                                {
                                    return(String.Compare(item, hit.Term.Text, StringComparison.OrdinalIgnoreCase) == 0);
                                }))
                                {
                                    Log.LogWarning(hit.Warning);
                                    _duplicateTerms.Add(hit.Term.Text);
                                }
                            }

                            string outputText;

                            if (hit.Term.RecommendedTerm != null && hit.Term.RecommendedTerm.Length > 0)
                            {
                                outputText = String.Format(CultureInfo.CurrentUICulture, Resources.HitFormatWithReplacement, result.FilePath, hit.Line + 1, hit.Column + 1, hit.Term.Text, hit.Term.Severity, hit.Term.Class, hit.Term.Comment, hit.Term.RecommendedTerm);
                            }
                            else
                            {
                                outputText = String.Format(CultureInfo.CurrentUICulture, Resources.HitFormat, result.FilePath, hit.Line + 1, hit.Column + 1, hit.Term.Text, hit.Term.Severity, hit.Term.Class, hit.Term.Comment);
                            }

                            if (HostObject != null && HostObject is IScannerHost)
                            {
                                // We're piping the results to the task list, so we don't want to use
                                // LogWarning, which would create an entry in the error list.
                                Log.LogMessage(MessageImportance.High, outputText);
                            }
                            else
                            {
                                Log.LogWarning(outputText);
                            }
                        }
                    }
                }
            }
            else
            {
                Log.LogWarning(String.Format(CultureInfo.CurrentUICulture, Resources.FileNotScannedError, result.FilePath));
            }

            if (HostObject != null && HostObject is IScannerHost)
            {
                IScannerHost scannerHost = HostObject as IScannerHost;
                scannerHost.AddResult(result, _project);
            }
        }