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);
            }
        }
Esempio n. 2
0
        private static IEnumerable <KeyValuePair <ProjectPoco, IEnumerable <string> > > ComposeBindingsErrors(IList <ProjectPoco> projects,
                                                                                                              IDictionary <ProjectPoco, IEnumerable <ReferenceMetadataBase> >
                                                                                                              referenceMetadatas)
        {
            var referencesByProjects = referenceMetadatas.Transform(x => x.OfType <ExistingReferenceMetadataBase>())
                                       .Transform((x, y) => y.Select(z => z.GetReferenceInformation(x)));

            var appConfigFileParser = new ProbabilityMatchEngine <ProjectItem>();

            appConfigFileParser.With(new AppConfigFileReferenceMatcher());
            var projectBindings = projects.Where(x => x.AppConfigPath != null)
                                  .ToDictionary(
                x => x,
                x =>
            {
                var r = new AppConfigFileReferenceMatcher.AppConfigFilePropabilityMetadata(null, null, 0d, x.AppConfigPath);
                return(r.RedirectModels);
            });

            return(projectBindings.Join(
                       referencesByProjects,
                       x => x.Key,
                       y => y.Key,
                       (x, y) =>
            {
                var bindingReferences = x.Value.Select(z => new ReferenceInformation(z.Name, z.NewVersion));

                var incorrect = bindingReferences.Join(
                    y.Value,
                    x1 => x1.AssemblyName,
                    y1 => y1.AssemblyName,
                    (x1, y1) => new Tuple <ReferenceInformation, ReferenceInformation>(x1, y1))
                                .Where(z => !string.Equals(z.Item1.Version, z.Item2.Version))
                                .Select(z => $"reference mismatch: redirect: {z.Item1.ToString()}, reference: {z.Item2.ToString()}");

                return new KeyValuePair <ProjectPoco, IEnumerable <string> >(x.Key, incorrect);
            }));
        }
        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();
            }
        }