Esempio n. 1
0
        public AssemblyNode CreateAssemblyNode(IOldToNewTupleMap <string> assemblyMap)
        {
            var generationProjectInfoMap = new OldToNewTupleMap <GeneratedProjectOutputInfo>
                                           (
                new GeneratedProjectOutputInfo(assemblyMap.OldType),
                new GeneratedProjectOutputInfo(assemblyMap.NewType)
                                           );

            Console.Write("Loading old assembly...");
            var assemblyDecompilationResultOld = GetAssemblyDecompilationResult(
                assemblyMap.OldType,
                generationProjectInfoMap.OldType.OutputPath,
                CancellationToken.None);

            GlobalDecompilationResultsRepository.Instance.AddDecompilationResult(assemblyMap.OldType, assemblyDecompilationResultOld);
            Console.WriteLine("done.");

            Console.Write("Loading new assembly...");
            var assemblyDecompilationResultNew = GetAssemblyDecompilationResult(
                assemblyMap.NewType,
                generationProjectInfoMap.NewType.OutputPath,
                CancellationToken.None);

            GlobalDecompilationResultsRepository.Instance.AddDecompilationResult(assemblyMap.NewType, assemblyDecompilationResultNew);
            Console.WriteLine("done.");

            return(AssemblyNode.Create(assemblyMap, generationProjectInfoMap));
        }
        public AssemblyBrowseTabItem(IOldToNewTupleMap <string> comparableModel)
        {
            APIDiffInfo diffInfo = new APIDiffInfo(APIDiffHelper.GetAPIDifferences(comparableModel.OldType, comparableModel.NewType));

            var generationProjectInfoMap = new OldToNewTupleMap <GeneratedProjectOutputInfo>
                                           (
                new GeneratedProjectOutputInfo(comparableModel.OldType),
                new GeneratedProjectOutputInfo(comparableModel.NewType)
                                           );

            FilterSettings filterSettings = new FilterSettings(this.ShowAllUnmodified);

            this.nodes = new AssemblyNode[] {
                new AssemblyNode(comparableModel, null, null, this, filterSettings)
                {
                    GenerationProjectInfoMap = generationProjectInfoMap
                }
            };

            this.header  = GetTabTitle(comparableModel);
            this.toolTip = GetTabToolTip(comparableModel);

            this.nodes[0].ChildrenLoaded += OnAssemblyNodeChildrenLoaded;
            this.contentLoaded            = new bool[2];
        }
        private AssemblyNode ProcessAssemblyNodeCreation(IOldToNewTupleMap <string> typesMap)
        {
            APIDiffInfo diffInfo = this.apiDiffInfo != null ? new APIDiffInfo(APIDiffHelper.GetAPIDifferences(typesMap.OldType, typesMap.NewType)) : null;

            var generationProjectInfoMap = new OldToNewTupleMap <GeneratedProjectOutputInfo>
                                           (
                new GeneratedProjectOutputInfo(typesMap.OldType),
                new GeneratedProjectOutputInfo(typesMap.NewType)
                                           );
            var assemblyNode = new AssemblyNode(typesMap, this, diffInfo, progressNotifier, this.FilterSettings)
            {
                GenerationProjectInfoMap = generationProjectInfoMap
            };

            assemblyNode.SetDifferenceDecoration();

            return(assemblyNode);
        }
Esempio n. 4
0
        private static void RunMain(string[] args)
        {
            if (args.Length < 3 || args.Length > 4)
            {
                WriteErrorAndSetErrorCode("Wrong number of arguments." + Environment.NewLine + Environment.NewLine + "Sample:" + Environment.NewLine + "justassembly.commandlinetool Path\\To\\Assembly1 Path\\To\\Assembly2 Path\\To\\XMLOutput [Path\\To\\IgnoreXML]");
                return;
            }

            var oldAssemblyPath = args[0];

            if (!FilePathValidater.ValidateInputFile(oldAssemblyPath))
            {
                WriteErrorAndSetErrorCode("First assembly path is in incorrect format or file not found.");
                return;
            }

            var newAssemblyPath = args[1];

            if (!FilePathValidater.ValidateInputFile(newAssemblyPath))
            {
                WriteErrorAndSetErrorCode("Second assembly path is in incorrect format or file not found.");
                return;
            }

            var outputPath = args[2];

            if (!FilePathValidater.ValidateOutputFile(outputPath))
            {
                WriteErrorAndSetErrorCode("Output file path is in incorrect format.");
                return;
            }

            var ignoreFile = args.Length > 3 ? args[3] : null;
            IgnoredChangesSet ignoreChangeSet = new IgnoredChangesSet(new ChangeSet(new Change[0]));

            if (ignoreFile != null)
            {
                if (!FilePathValidater.ValidateOutputFile(ignoreFile))
                {
                    WriteErrorAndSetErrorCode("Ignore file path is in incorrect format.");
                    return;
                }

                try
                {
                    using (var textReader = File.OpenText(ignoreFile))
                    {
                        var xmlReader    = new XmlSerializer(typeof(ChangeSet));
                        var rawChangeSet = (ChangeSet)xmlReader.Deserialize(textReader);
                        ignoreChangeSet = new IgnoredChangesSet(rawChangeSet);
                    }
                }
                catch (Exception ex)
                {
                    WriteExceptionAndSetErrorCode("A problem occurred while parsing the ignore file.", ex);
                    return;
                }
            }

            var differ = new Differ(ignoreChangeSet, new EmptyFileGenerationNotifier());

            ChangeSet changeSet;

            try
            {
                var typesMap     = new OldToNewTupleMap <string> (oldAssemblyPath, newAssemblyPath);
                var assemblyNode = differ.CreateAssemblyNode(typesMap);
                changeSet = differ.CreateChangeSet(assemblyNode);
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("A problem occurred while creating the change set.", ex);
                return;
            }

            try
            {
                differ.CreatePatchFileAndSources(
                    changeSet,
                    Path.ChangeExtension(outputPath, ".patch"),
                    Path.ChangeExtension(outputPath, ".zip"));
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("There was a problem while writing the patch file.", ex);
                return;
            }

            string xml = string.Empty;

            try
            {
                foreach (var change in changeSet.MemberChanges)
                {
                    if (change is ResourceChange)
                    {
                        if (change.OldSource != null)
                        {
                            change.OldSource.Text = null;
                        }
                        if (change.NewSource != null)
                        {
                            change.NewSource.Text = null;
                        }
                    }
                }
                xml = differ.CreateXMLDiff(changeSet);
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("A problem occurred while creating the API diff.", ex);
                return;
            }

            try
            {
                using (StreamWriter writer = new StreamWriter(outputPath))
                {
                    writer.Write(xml);
                }
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("There was a problem while writing output file.", ex);
                return;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("API differences calculated successfully.");
            Console.ResetColor();
        }