public void FindAndRegisterValidExtensionPoints_DoesNotRegisterInvalidExtensionPoints()
        {
            CreateExtensionPointsConfiguration(addInvalidExtensionPoints: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IParser parser = ExtensionPointsRepository.Instance.GetParserImplementation(".cs");

            Assert.IsNotNull(parser, "Default parser for '.cs' extension should be used!");
            Assert.AreEqual(parser.GetType().FullName, "Sando.Parser.SrcMLCSharpParser", "Invalid parser returned for '.cs' extension!");

            IWordSplitter wordSplitter = ExtensionPointsRepository.Instance.GetWordSplitterImplementation();

            Assert.IsNotNull(wordSplitter, "Default word splitter should be used!");
            Assert.AreEqual(wordSplitter.GetType().FullName, "Sando.Core.Tools.WordSplitter", "Invalid word splitter returned!");

            IResultsReorderer resultsReorderer = ExtensionPointsRepository.Instance.GetResultsReordererImplementation();

            Assert.IsNotNull(resultsReorderer, "Default results reorderer should be used!");
            Assert.AreEqual(resultsReorderer.GetType().FullName, "Sando.SearchEngine.SortByScoreResultsReorderer", "Invalid results reorderer returned!");

            string logFileContent = File.ReadAllText(logFilePath);

            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.NonExistingParser"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Could not load file or assembly 'file:///" + pluginDirectory + "NonExistingParser.dll' or one of its dependencies"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Could not load file or assembly 'file:///" + pluginDirectory + "NonExistingTestElement.dll' or one of its dependencies"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Could not load file or assembly 'file:///" + pluginDirectory + "NonExistingWordSplitter.dll' or one of its dependencies"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.TestExtensionPoints.NonExistingResultsReorderer"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.TestExtensionPoints.NonExistingQueryWeightsSupplier"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.TestExtensionPoints.NonExistingQueryRewriter"), "Log file should contain information about errors occurred during the assembly loading!");
            Assert.IsTrue(logFileContent.Contains("Type cannot be found: Sando.TestExtensionPoints.NonExistingIndexFilterManager"), "Log file should contain information about errors occurred during the assembly loading!");
        }
        private void RegisterExtensionPoints()
        {
            var extensionPointsRepository = ExtensionPointsRepository.Instance;

            // JZ: SrcMLService Integration
            extensionPointsRepository.RegisterParserImplementation(new List <string> {
                ".cs"
            }, new SrcMLCSharpParser());
            extensionPointsRepository.RegisterParserImplementation(new List <string> {
                ".h", ".cpp", ".cxx", ".c"
            }, new SrcMLCppParser(srcMLService));
            ////extensionPointsRepository.RegisterParserImplementation(new List<string> { ".cs" }, new SrcMLCSharpParser(_srcMLArchive));
            ////extensionPointsRepository.RegisterParserImplementation(new List<string> { ".h", ".cpp", ".cxx", ".c" }, new SrcMLCppParser(_srcMLArchive));
            // JZ: End of code changes
            extensionPointsRepository.RegisterParserImplementation(new List <string> {
                ".xaml"
            }, new XAMLFileParser());
            //extensionPointsRepository.RegisterParserImplementation(new List<string> { ".txt" },
            // new TextFileParser());

            extensionPointsRepository.RegisterWordSplitterImplementation(new WordSplitter());
            extensionPointsRepository.RegisterResultsReordererImplementation(new SortByScoreResultsReorderer());
            extensionPointsRepository.RegisterQueryWeightsSupplierImplementation(new QueryWeightsSupplier());
            extensionPointsRepository.RegisterQueryRewriterImplementation(new DefaultQueryRewriter());
            extensionPointsRepository.RegisterIndexFilterManagerImplementation(new IndexFilterManager());


            var sandoOptions = ServiceLocator.Resolve <ISandoOptionsProvider>().GetSandoOptions();

            var loggerPath = Path.Combine(sandoOptions.ExtensionPointsPluginDirectoryPath, "ExtensionPointsLogger.log");
            var logger     = FileLogger.CreateFileLogger("ExtensionPointsLogger", loggerPath);

            _extensionPointsConfiguration = ExtensionPointsConfigurationFileReader.ReadAndValidate(logger);

            if (_extensionPointsConfiguration != null)
            {
                _extensionPointsConfiguration.PluginDirectoryPath = sandoOptions.ExtensionPointsPluginDirectoryPath;
                ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(_extensionPointsConfiguration, logger);
            }

            var csParser = extensionPointsRepository.GetParserImplementation(".cs") as SrcMLCSharpParser;
            // JZ: SrcMLService Integration
            ////if(csParser != null) {
            ////    csParser.Archive = _srcMLArchive;
            ////}
            // End of code changes
            var cppParser = extensionPointsRepository.GetParserImplementation(".cpp") as SrcMLCppParser;
            // JZ: SrcMLService Integration
            ////if(cppParser != null) {
            ////    cppParser.Archive = _srcMLArchive;
            ////}
            // End of code changes
        }
        public void FindAndRegisterValidExtensionPoints_RemovesInvalidCustomIndexFilterManagerConfiguration()
        {
            CreateExtensionPointsConfiguration(addInvalidIndexFilterManagerConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IIndexFilterManager indexFilterManager = ExtensionPointsRepository.Instance.GetIndexFilterManagerImplementation();

            Assert.IsNotNull(indexFilterManager, "Default index filter manager should be used!");
            Assert.AreEqual(indexFilterManager.GetType().FullName, "Sando.Indexer.IndexFiltering.IndexFilterManager", "Invalid index filter manager returned!");

            string logFileContent = File.ReadAllText(logFilePath);

            Assert.IsTrue(logFileContent.Contains("Invalid index filter manager configuration found - it will be omitted during registration process."), "Log file should contain information about removed invalid index filter manager configuration!");
        }
        public void FindAndRegisterValidExtensionPoints_RemovesInvalidCustomResultsReordererConfiguration()
        {
            CreateExtensionPointsConfiguration(addInvalidResultsReordererConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IResultsReorderer resultsReorderer = ExtensionPointsRepository.Instance.GetResultsReordererImplementation();

            Assert.IsNotNull(resultsReorderer, "Default results reorderer should be used!");
            Assert.AreEqual(resultsReorderer.GetType().FullName, "Sando.SearchEngine.SortByScoreResultsReorderer", "Invalid results reorderer returned!");

            string logFileContent = File.ReadAllText(logFilePath);

            Assert.IsTrue(logFileContent.Contains("Invalid results reorderer configuration found - it will be omitted during registration process."), "Log file should contain information about removed invalid word splitter configuration!");
        }
        public void FindAndRegisterValidExtensionPoints_RemovesInvalidCustomParserConfigurations()
        {
            CreateExtensionPointsConfiguration(addInvalidParserConfigurations: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IParser parser = ExtensionPointsRepository.Instance.GetParserImplementation(".cs");

            Assert.IsNotNull(parser, "Default parser for '.cs' extension should be used!");
            Assert.AreEqual(parser.GetType().FullName, "Sando.Parser.SrcMLCSharpParser", "Invalid parser returned for '.cs' extension!");

            string logFileContent = File.ReadAllText(logFilePath);

            Assert.IsTrue(logFileContent.Contains("3 invalid parser configurations found - they will be omitted during registration process."), "Log file should contain information about removed invalid parser configurations!");
        }
        public void FindAndRegisterValidExtensionPoints_RegistersUsableCustomParser()
        {
            CreateExtensionPointsConfiguration(addValidParserConfigurations: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IParser parser = ExtensionPointsRepository.Instance.GetParserImplementation(".cs");

            Assert.IsNotNull(parser, "Parser for '.cs' extension should be registered!");
            List <ProgramElement> programElements = null;

            Assert.DoesNotThrow(() => programElements = parser.Parse("filename"));
            Assert.IsTrue(programElements != null && programElements.Count == 1, "Invalid results from Parse method!");
            Assert.AreEqual(programElements[0].Name, "TestCSharpName", "Name differs!");
            Assert.AreEqual(programElements[0].GetType().FullName, "Sando.TestExtensionPoints.TestElement", "Type differs!");
        }
        public void FindAndRegisterValidExtensionPoints_RegistersUsableCustomIndexFilterManager()
        {
            CreateExtensionPointsConfiguration(addValidIndexFilterManagerConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IIndexFilterManager indexFilterManager = ExtensionPointsRepository.Instance.GetIndexFilterManagerImplementation();

            Assert.IsNotNull(indexFilterManager, "Index filter manager should be registered!");
            Assert.AreEqual(indexFilterManager.GetType().FullName, "Sando.TestExtensionPoints.TestIndexFilterManager", "Invalid index filter manager returned!");

            bool shouldBeIndexed = false;

            Assert.DoesNotThrow(() => shouldBeIndexed = indexFilterManager.ShouldFileBeIndexed("C:\\\\index.xml"));
            Assert.IsTrue(shouldBeIndexed, "Invalid results from ShouldFileBeIndexed method!");
        }
        public void FindAndRegisterValidExtensionPoints_RegistersUsableCustomWordSplitter()
        {
            CreateExtensionPointsConfiguration(addValidWordSplitterConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IWordSplitter wordSplitter = ExtensionPointsRepository.Instance.GetWordSplitterImplementation();

            Assert.IsNotNull(wordSplitter, "Word splitter should be registered!");
            Assert.AreEqual(wordSplitter.GetType().FullName, "Sando.TestExtensionPoints.TestWordSplitter", "Invalid word splitter returned!");

            string[] splittedWords = null;
            Assert.DoesNotThrow(() => splittedWords = wordSplitter.ExtractWords("FileName"));
            Assert.IsTrue(splittedWords != null && splittedWords.Length == 2, "Invalid results from ExtractWords method!");
            Assert.AreEqual(splittedWords[0], "File", "First splitted word is invalid!");
            Assert.AreEqual(splittedWords[1], "Name", "Second splitted word is invalid!");
        }
        public void FindAndRegisterValidExtensionPoints_RegistersUsableCustomQueryRewriter()
        {
            CreateExtensionPointsConfiguration(addValidQueryRewriterConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IQueryRewriter queryRewriter = ExtensionPointsRepository.Instance.GetQueryRewriterImplementation();

            Assert.IsNotNull(queryRewriter, "Query rewriter should be registered!");
            Assert.AreEqual(queryRewriter.GetType().FullName, "Sando.TestExtensionPoints.TestQueryRewriter", "Invalid query rewriter returned!");

            string query = null;

            Assert.DoesNotThrow(() => query = queryRewriter.RewriteQuery("Two Keywords"));
            Assert.IsFalse(String.IsNullOrWhiteSpace(query), "Invalid results from RewriteQuery method!");
            Assert.AreEqual(query, "two keywords", "Query is invalid!");
        }
        public void FindAndRegisterValidExtensionPoints_RegistersUsableCustomQueryWeightsSupplier()
        {
            CreateExtensionPointsConfiguration(addValidQueryWeightsSupplierConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IQueryWeightsSupplier queryWeightsSupplier = ExtensionPointsRepository.Instance.GetQueryWeightsSupplierImplementation();

            Assert.IsNotNull(queryWeightsSupplier, "Query weights supplier should be registered!");
            Assert.AreEqual(queryWeightsSupplier.GetType().FullName, "Sando.TestExtensionPoints.TestQueryWeightsSupplier", "Invalid query weights supplier returned!");

            Dictionary <string, float> weights = null;

            Assert.DoesNotThrow(() => weights = queryWeightsSupplier.GetQueryWeightsValues());
            Assert.IsTrue(weights != null && weights.Count() == 2, "Invalid results from SetQueryWeightsValues method!");
            Assert.AreEqual(weights["field1"], 2, "First weight is invalid!");
            Assert.AreEqual(weights["field2"], 3, "Second weight is invalid!");
        }
        public void FindAndRegisterValidExtensionPoints_RegistersUsableCustomResultsReorderer()
        {
            CreateExtensionPointsConfiguration(addValidResultsReordererConfiguration: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IResultsReorderer resultsReorderer = ExtensionPointsRepository.Instance.GetResultsReordererImplementation();

            Assert.IsNotNull(resultsReorderer, "Results reorderer should be registered!");
            Assert.AreEqual(resultsReorderer.GetType().FullName, "Sando.TestExtensionPoints.TestResultsReorderer", "Invalid results reorderer returned!");

            List <CodeSearchResult> results = new List <CodeSearchResult>()
            {
                new CodeSearchResult(SampleProgramElementFactory.GetSampleClassElement(), 1),
                new CodeSearchResult(SampleProgramElementFactory.GetSampleMethodElement(), 3),
            };

            Assert.DoesNotThrow(() => results = resultsReorderer.ReorderSearchResults(results.AsQueryable()).ToList());
            Assert.IsTrue(results != null && results.Count() == 2, "Invalid results from ReorderSearchResults method!");
            Assert.IsTrue(results.ElementAt(0).Score == 3 && results.ElementAt(0).ProgramElement.ProgramElementType == ProgramElementType.Method, "First result is invalid!");
            Assert.IsTrue(results.ElementAt(1).Score == 1 && results.ElementAt(1).ProgramElement.ProgramElementType == ProgramElementType.Class, "Second result is invalid!");
        }
        public void FindAndRegisterValidExtensionPoints_RegistersCustomParsers()
        {
            CreateExtensionPointsConfiguration(addValidParserConfigurations: true);
            ExtensionPointsConfigurationAnalyzer.FindAndRegisterValidExtensionPoints(extensionPointsConfiguration, logger);

            IParser parser = ExtensionPointsRepository.Instance.GetParserImplementation(".cs");

            Assert.IsNotNull(parser, "Parser for '.cs' extension should be registered!");
            Assert.AreEqual(parser.GetType().FullName, "Sando.TestExtensionPoints.TestCSharpParser", "Invalid parser returned for '.cs' extension!");

            parser = ExtensionPointsRepository.Instance.GetParserImplementation(".h");
            Assert.IsNotNull(parser, "Parser for '.h' extension should be registered!");
            Assert.AreEqual(parser.GetType().FullName, "Sando.TestExtensionPoints.TestCppParser", "Invalid parser returned for '.h' extension!");

            parser = ExtensionPointsRepository.Instance.GetParserImplementation(".cpp");
            Assert.IsNotNull(parser, "Parser for '.cpp' extension should be registered!");
            Assert.AreEqual(parser.GetType().FullName, "Sando.TestExtensionPoints.TestCppParser", "Invalid parser returned for '.cpp' extension!");

            parser = ExtensionPointsRepository.Instance.GetParserImplementation(".cxx");
            Assert.IsNotNull(parser, "Parser for '.cxx' extension should be registered!");
            Assert.AreEqual(parser.GetType().FullName, "Sando.TestExtensionPoints.TestCppParser", "Invalid parser returned for '.cxx' extension!");
        }