Esempio n. 1
0
        private static void AnalyzeInternal(string solutionPath, IObserver <Message.Info> observer)
        {
            try
            {
                observer.OnNextInfo("--==--");

                observer.OnNextInfo($"starting the {solutionPath} analysis...");
                observer.OnNextInfo("parsing the solution...");
                var projects = SolutionParser.GetProjects(solutionPath)
                               .ToList();

                observer.OnNextInfo("parsed.");

                var referenceMatcher = new ProbabilityMatchEngine <ReferenceBase>();
                referenceMatcher.With(new NugetReference())
                .With(new SystemReference())
                .With(new DllReference())
                .With(new ProjectReference());

                var wrongReferenceMatcher = new ProbabilityMatchEngine <DllMetadata>();
                wrongReferenceMatcher.With(new WrongReferenceMatcher(projects));

                var referenceMetadatas = projects.ToDictionary(
                    x => x,
                    x => x.References.FindBestMatch <ReferenceBase, ReferenceMetadataBase>(referenceMatcher, 0d));

                var projectReferenceVsDirectDllReference = ComposeProjectReferenceErrors(referenceMetadatas,
                                                                                         wrongReferenceMatcher);
                var incorrectReferences = ComposeBindingsErrors(projects, referenceMetadatas);

                var errorReport = projectReferenceVsDirectDllReference.Merge(incorrectReferences);
                foreach (var item in errorReport)
                {
                    observer.OnNextInfo($"project: {item.Key} report:");
                    item.Value
                    .DoIfEmpty(() => observer.OnNextInfo("all seems to be ok"))
                    .Do(x => observer.OnNextError($"possible issue: {x}"));
                }

                observer.OnNextInfo("analysis completed.");
                observer.OnCompleted();
            }
            catch (Exception e)
            {
                observer.OnError(e);
            }
        }
        private static void AnalyzeInternal(string solutionPath, IObserver <Message.Info> observer)
        {
            try
            {
                observer.OnNextInfo("--==--");

                observer.OnNextInfo($"starting the {solutionPath} analysis...");
                observer.OnNextInfo("parsing the solution...");
                var projects = SolutionParser.GetProjects(solutionPath)
                               .ToList();

                observer.OnNextInfo("parsed.");

                var referenceMatcher = new ProbabilityMatchEngine <ReferenceBase>();
                referenceMatcher.With(new NugetReference())
                .With(new SystemReference())
                .With(new DllReference())
                .With(new ProjectReference());

                var wrongReferenceMatcher = new ProbabilityMatchEngine <DllMetadata>();
                wrongReferenceMatcher.With(new WrongReferenceMatcher(projects));

                var referenceMetadatas = projects.ToDictionary(
                    x => x,
                    x => x.References.FindBestMatch <ReferenceBase, ReferenceMetadataBase>(referenceMatcher, 0d));

                var projectReferenceVsDirectDllReference = DllAndProjectMisreferenceAmalyzer.ComposeProjectReferenceErrors(referenceMetadatas, wrongReferenceMatcher);
                var referencesByProjects = ComposeReferencesByProjects(observer, referenceMetadatas);

                var incorrectReferences = IncorrectBindingsAnalyzer.ComposeBindingsErrors(projects, referencesByProjects);
                var differentVersionsReferencesErrors = DifferentVersionsAnalyzer.ComposeDifferentVersionsReferencesErrors(referencesByProjects);
                //[DS]: this world is just not readey yet for this check...
                //var assemblyRedirectsVsReferencesErrors = IncorrectRedirectsAndReferencesAnalyzer.ComposeRedirectsVsReferencesErrors(projects);
                var solutionDirectory = Path.GetDirectoryName(solutionPath);
                var inconsistentNugetPackageReferences = InconsistentNugetPackagesAnalyzer.ComposeInconsistentNugetPackageReferences(
                    solutionDirectory,
                    projects,
                    referencesByProjects,
                    referenceMetadatas);

                var wordsAnalyzer  = new ForbiddenWordsAnalyzer(GetForbiddenWordsFilePath(), projects);
                var forbiddedWords = wordsAnalyzer.Analyze();

                var observations = projectReferenceVsDirectDllReference.Merge(incorrectReferences)
                                   .Merge(differentVersionsReferencesErrors)
                                   //.Merge(assemblyRedirectsVsReferencesErrors)
                                   .Merge(inconsistentNugetPackageReferences)
                                   .Merge(forbiddedWords)
                                   .Select(
                    x =>
                {
                    if (x.Value.Any())
                    {
                        var errorMessage = string.Join(
                            Environment.NewLine,
                            x.Value.Select(y => $"possible issue: {y}"));
                        return(new Message.Error(
                                   $"project: {x.Key} report:{Environment.NewLine}{errorMessage}"));
                    }
                    return(new Message.Info($"project: {x.Key} report: all seems to be ok"));
                });
                observations.ForEachItem(observer.OnNext);
            }
            catch (Exception e)
            {
                observer.OnNextError(e.Message);
            }
            finally
            {
                observer.OnNext(new Message.Info("analysis completed."));
                observer.OnCompleted();
            }
        }