// Options

        public static DiffConfiguration UpdateOptions(this DiffConfiguration configuration, DiffConfigurationOptions options)
        {
            var left  = configuration.Left;
            var right = configuration.Right;

            return(new DiffConfiguration(left, right, options));
        }
예제 #2
0
        public static MappingSettings GetMappingSettings(DiffConfiguration configuration)
        {
            Func <DifferenceType, bool> diffFilterPredicate = t => (t != DifferenceType.Added || configuration.IsOptionSet(DiffConfigurationOptions.IncludeAdded)) &&
                                                              (t != DifferenceType.Changed || configuration.IsOptionSet(DiffConfigurationOptions.IncludeChanged)) &&
                                                              (t != DifferenceType.Removed || configuration.IsOptionSet(DiffConfigurationOptions.IncludeRemoved)) &&
                                                              (t != DifferenceType.Unchanged || configuration.IsOptionSet(DiffConfigurationOptions.IncludeUnchanged));

            var cciFilter = GetFilter(configuration);
            var mappingDifferenceFilter = configuration.IsOptionSet(DiffConfigurationOptions.TypesOnly)
                                              ? new TypesOnlyMappingDifferenceFilter(diffFilterPredicate, cciFilter)
                                              : new MappingDifferenceFilter(diffFilterPredicate, cciFilter);

            var includeAddedTypes   = configuration.IsOptionSet(DiffConfigurationOptions.IncludeAddedTypes);
            var includeRemovedTypes = configuration.IsOptionSet(DiffConfigurationOptions.IncludeRemovedTypes);
            var actualFilter        = includeAddedTypes && includeRemovedTypes
                                   ? (IMappingDifferenceFilter)mappingDifferenceFilter
                                   : new CommonTypesMappingDifferenceFilter(mappingDifferenceFilter, includeAddedTypes, includeRemovedTypes);

            return(new MappingSettings
            {
                Filter = cciFilter,
                DiffFilter = actualFilter,
                IncludeForwardedTypes = true,
                GroupByAssembly = configuration.IsOptionSet(DiffConfigurationOptions.GroupByAssembly),
                FlattenTypeMembers = configuration.IsOptionSet(DiffConfigurationOptions.FlattenTypes),
                AlwaysDiffMembers = configuration.IsOptionSet(DiffConfigurationOptions.AlwaysDiffMembers)
            });
        }
        private static DiffConfiguration UpdateAssemblies(this DiffConfiguration configuration, bool isLeft, AssemblySet assemblySet)
        {
            var isRight     = !isLeft;
            var existingSet = isLeft
                                  ? configuration.Left
                                  : configuration.Right;

            // This is the a debatible thing here.
            //
            // Without Dipose(), instances of DiffConfiguration would be fully immutable, which means
            // we could pass it around to different threads and you could be sure that no than is stepping
            // on your toes.
            //
            // However, this also means we would only unlock the files on disk when the GC collects the
            // the underlying metadata reader host. This means, nobody can open the files exlusively or
            // deleting them until they are collected.
            //
            // A workaround for the user is to simply close the app but I feel the workaround feels really
            // bad. Especially because most of the assemblies being added to the tool will come from temp
            // folders on the desktop.
            //
            // Since our apps is blocking adding/removing files when an analysis is running, there are
            // no real advantages of full immutable sharing.

            existingSet.Dispose();

            var newLeft  = isLeft ? assemblySet : configuration.Left;
            var newRight = isRight ? assemblySet : configuration.Right;

            return(new DiffConfiguration(newLeft, newRight, configuration.Options));
        }
예제 #4
0
        public void OnExecute()
        {
            if (string.IsNullOrEmpty(NewSet))
            {
                // Reset the filter to be unchanged if we only have a single set so that it will
                // simply output the contents of the set.
                Removed   = Added = false;
                Unchanged = true;
            }

            if (!Added && !Removed && !Changed && !Unchanged)
            {
                // If the user didn't explicitly specify what to include we default to changes only.
                Added = Removed = Changed = true;
            }

            DiffConfigurationOptions options = GetDiffOptions();
            DiffFormat diffFormat            = GetDiffFormat();

            AssemblySet oldAssemblies = AssemblySet.FromPaths(OldSet);
            AssemblySet newAssemblies = AssemblySet.FromPaths(NewSet);

            DiffConfiguration diffConfiguration = new DiffConfiguration(oldAssemblies, newAssemblies, options);

            using (TextWriter output = GetOutput())
                DiffEngine.Export(diffConfiguration, null, diffFormat, output);
        }
        public static DiffConfiguration SetOption(this DiffConfiguration configuration, DiffConfigurationOptions option, bool set)
        {
            var newOptions = set
                                 ? configuration.Options | option
                                 : configuration.Options & ~option;

            return(configuration.UpdateOptions(newOptions));
        }
        private static DiffConfiguration RemoveAssemblies(this DiffConfiguration configuration, bool isLeft, IEnumerable <IAssembly> removals)
        {
            var existingSet = isLeft
                                  ? configuration.Left
                                  : configuration.Right;
            var newSet = existingSet.Remove(removals);

            return(configuration.UpdateAssemblies(isLeft, newSet));
        }
예제 #7
0
        private static ICciFilter GetFilter(DiffConfiguration configuration)
        {
            var includeAttributes = configuration.IsOptionSet(DiffConfigurationOptions.DiffAttributes);
            var includeInternals  = configuration.IsOptionSet(DiffConfigurationOptions.IncludeInternals);
            var includePrivates   = configuration.IsOptionSet(DiffConfigurationOptions.IncludePrivates);
            var includeGenerated  = configuration.IsOptionSet(DiffConfigurationOptions.IncludeGenerated);

            return(new DiffCciFilter(includeAttributes, includeInternals, includePrivates, includeGenerated));
        }
예제 #8
0
        public static void Export(DiffConfiguration configuration, IEnumerable <DiffComment> diffComments, DiffFormat format, TextWriter streamWriter)
        {
            var strikeOutRemoved = configuration.IsOptionSet(DiffConfigurationOptions.StrikeRemoved);

            using (var syntaxWriter = GetExportWriter(format, streamWriter, strikeOutRemoved))
            {
                var writer = CreateExportWriter(format, streamWriter, configuration, syntaxWriter, diffComments);
                WriteDiff(configuration, writer);
            }
        }
        private static DiffConfiguration AddAssemblies(this DiffConfiguration configuration, bool isLeft, IEnumerable <string> addedPaths)
        {
            var existingSet = isLeft
                                  ? configuration.Left
                                  : configuration.Right;
            var existingAssemblyPaths = from a in existingSet.Assemblies
                                        select a.Location;

            var totalAssemblyPaths = existingAssemblyPaths.Concat(addedPaths).ToArray();
            var newName            = existingSet.IsEmpty ? null : existingSet.Name;

            return(configuration.UpdateAssemblies(isLeft, totalAssemblyPaths, newName));
        }
예제 #10
0
        private static void GetTokens(DiffConfiguration configuration, CancellationToken cancellationToken, out IEnumerable <DiffToken> tokens, out IEnumerable <DiffApiDefinition> apiDefinitions)
        {
            bool            includeAttributes = configuration.IsOptionSet(DiffConfigurationOptions.DiffAttributes);
            var             diffRecorder      = new DiffRecorder(cancellationToken);
            MappingSettings mappingSettings   = GetMappingSettings(configuration);
            var             writer            = new ApiRecordingCSharpDiffWriter(diffRecorder, mappingSettings, includeAttributes)
            {
                IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo),
                HighlightBaseMembers      = configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers)
            };

            WriteDiff(configuration, writer);

            tokens         = diffRecorder.Tokens;
            apiDefinitions = writer.ApiDefinitions;
        }
예제 #11
0
        private static void WriteDiff(DiffConfiguration configuration, ICciDifferenceWriter writer)
        {
            var oldSet            = configuration.Left;
            var oldAssemblies     = oldSet.Assemblies;
            var oldAssembliesName = oldSet.Name;

            // The diff writer special cases the name being null
            // to indicated that there is only one "set".
            var newSet            = configuration.Right;
            var newAssembliesName = newSet.IsNull
                                        ? null
                                        : newSet.Name;
            var newAssemblies = newSet.Assemblies;

            writer.Write(oldAssembliesName, oldAssemblies, newAssembliesName, newAssemblies);
        }
예제 #12
0
        public static DiffDocument BuildDiffDocument(DiffConfiguration configuration, CancellationToken cancellationToken)
        {
            try
            {
                IEnumerable <DiffToken>         tokens;
                IEnumerable <DiffApiDefinition> apiDefinitions;
                GetTokens(configuration, cancellationToken, out tokens, out apiDefinitions);

                IEnumerable <DiffLine> lines = GetLines(tokens, cancellationToken);
                AssemblySet            left  = configuration.Left;
                AssemblySet            right = configuration.Right;
                return(new DiffDocument(left, right, lines, apiDefinitions));
            }
            catch (OperationCanceledException)
            {
                return(null);
            }
        }
예제 #13
0
        public void OnExecute()
        {
            if (string.IsNullOrEmpty(NewSet))
            {
                // Reset the filter to be unchanged if we only have a single set so that it will
                // simply output the contents of the set.
                Removed   = Added = false;
                Unchanged = true;
            }

            if (!Added && !Removed && !Changed && !Unchanged)
            {
                // If the user didn't explicitly specify what to include we default to changes only.
                Added = Removed = Changed = true;
            }

            if (!string.IsNullOrEmpty(Language))
            {
                var cultureInfo = System.Globalization.CultureInfo.GetCultureInfo(Language);
                Thread.CurrentThread.CurrentCulture   = cultureInfo;
                Thread.CurrentThread.CurrentUICulture = cultureInfo;
            }

            DiffConfigurationOptions options = GetDiffOptions();
            DiffFormat diffFormat            = GetDiffFormat();

            AssemblySet oldAssemblies = AssemblySet.FromPaths(OldSetName, OldSet);
            AssemblySet newAssemblies = AssemblySet.FromPaths(NewSetName, NewSet);

            DiffConfiguration diffConfiguration = new DiffConfiguration(oldAssemblies, newAssemblies, options);

            if (diffFormat == DiffFormat.Md)
            {
                DiffDocument diffDocument         = DiffEngine.BuildDiffDocument(diffConfiguration);
                var          markdownDiffExporter = new MarkdownDiffExporter(diffDocument, OutFile, IncludeTableOfContents, CreateFilePerNamespace);
                markdownDiffExporter.Export();
            }
            else
            {
                using (TextWriter output = GetOutput())
                    DiffEngine.Export(diffConfiguration, null, diffFormat, output);
            }
        }
 public static DiffConfiguration AddRightAssemblies(this DiffConfiguration configuration, IEnumerable <string> addedPaths)
 {
     return(configuration.AddAssemblies(false, addedPaths));
 }
예제 #15
0
 public static DiffDocument BuildDiffDocument(DiffConfiguration configuration)
 {
     return(BuildDiffDocument(configuration, CancellationToken.None));
 }
 public static bool IsOptionSet(this DiffConfiguration configuration, DiffConfigurationOptions option)
 {
     return(option == DiffConfigurationOptions.None
                ? configuration.Options == DiffConfigurationOptions.None
                : (configuration.Options & option) == option);
 }
 public static DiffConfiguration UpdateLeftAssemblies(this DiffConfiguration configuration, IEnumerable <string> paths, string name)
 {
     return(configuration.UpdateAssemblies(true, paths, name));
 }
 public static DiffConfiguration RemoveRightAssemblies(this DiffConfiguration configuration, IEnumerable <IAssembly> removals)
 {
     return(configuration.RemoveAssemblies(false, removals));
 }
예제 #19
0
        private static ICciDifferenceWriter CreateExportWriter(DiffFormat format, TextWriter textWriter, DiffConfiguration configuration, IStyleSyntaxWriter writer, IEnumerable <DiffComment> diffComments)
        {
            var mappingSettings   = GetMappingSettings(configuration);
            var includeAttributes = configuration.IsOptionSet(DiffConfigurationOptions.DiffAttributes);

            switch (format)
            {
            case DiffFormat.Csv:
                var diffColumns   = DiffCsvColumn.CreateStandardColumns(configuration).Where(c => c.IsVisible).ToArray();
                var csvTextWriter = new CsvTextWriter(textWriter);
                csvTextWriter.WriteLine(diffColumns.Select(c => c.Name));
                return(new DiffCsvWriter(csvTextWriter, mappingSettings, diffColumns, CancellationToken.None));

            case DiffFormat.Html:
                return(new DiffCSharpWriter(writer, mappingSettings, diffComments, includeAttributes)
                {
                    IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo),
                    HighlightBaseMembers = configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers)
                });

            case DiffFormat.WordXml:
            case DiffFormat.Text:
            case DiffFormat.UnifiedDiff:
                return(new DiffCSharpWriter(writer, mappingSettings, diffComments, includeAttributes)
                {
                    IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo),
                    HighlightBaseMembers = configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers)
                });

            default:
                throw new ArgumentOutOfRangeException("format");
            }
        }
        // Update assemblies

        public static DiffConfiguration UpdateLeftAssemblies(this DiffConfiguration configuration, IEnumerable <string> paths)
        {
            return(configuration.UpdateLeftAssemblies(paths, null));
        }
 public static DiffConfiguration UpdateRightAssemblies(this DiffConfiguration configuration, AssemblySet assemblySet)
 {
     return(configuration.UpdateAssemblies(false, assemblySet));
 }
 public static DiffConfiguration UpdateLeftAssemblies(this DiffConfiguration configuration, AssemblySet assemblySet)
 {
     return(configuration.UpdateAssemblies(true, assemblySet));
 }
        private static DiffConfiguration UpdateAssemblies(this DiffConfiguration configuration, bool isLeft, IEnumerable <string> newPaths, string newName)
        {
            var assemblySet = AssemblySet.FromPaths(newPaths, newName);

            return(configuration.UpdateAssemblies(isLeft, assemblySet));
        }