Ejemplo n.º 1
0
        public void RefreshContent(DocumentDiff diff)
        {
            var a = UnsolvedConflicts.ToList();

            UnsolvedConflicts = a;
            OriginalText      = string.Join("\n", diff.OldValue.ToArray());
            NewText           = diff.NewValue;
            MergedText        = string.Empty;
            IsOriginalChecked = false;
            IsNewChecked      = false;
        }
        public virtual async Task <IEnumerable <MethodModification> > GetModificationsAsync(IEnumerable <string> modifiedDocuments)
        {
            var cancellationTokenSource = new CancellationTokenSource();
            var result       = new List <MethodModification>();
            var documentDiff = new DocumentDiff();

            this.newProject = await Utils.ReadProjectAsync(projectPath);

            var oldProjectDocuments = from doc in project.Documents
                                      select doc.FilePath;

            var newProjectDocuments = from doc in newProject.Documents
                                      select doc.FilePath;

            var allProjectDocuments      = oldProjectDocuments.Union(newProjectDocuments, StringComparer.InvariantCultureIgnoreCase);
            var modifiedProjectDocuments = modifiedDocuments.Intersect(allProjectDocuments, StringComparer.InvariantCultureIgnoreCase);

            if (modifiedProjectDocuments.Any())
            {
                this.newCompilation = await Utils.CompileProjectAsync(newProject, cancellationTokenSource.Token);

                this.newDocumentsInfo = new Dictionary <DocumentPath, DocumentInfo>(this.DocumentsInfo);

                foreach (var documentPath in modifiedProjectDocuments)
                {
                    var oldDocumentInfo = await this.GetDocumentInfoAsync(documentPath, false);

                    this.useNewFieldsVersion = true;

                    this.RemoveDocumentInfo(documentPath);
                    var newDocumentInfo = await this.GetDocumentInfoAsync(documentPath);

                    this.useNewFieldsVersion = false;

                    var modifications = documentDiff.GetDifferences(oldDocumentInfo, newDocumentInfo);
                    result.AddRange(modifications);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public async Task TestDocumentsDiff()
        {
            #region original source code
            var source = @"
using System;
class Program
{
    public static void MethodToRemove()
    {
		Console.WriteLine(1);
    }

    public static void MethodToUpdate()
    {
		MethodToRemove();
    }

    public static void Main()
    {
		MethodToUpdate();
    }
}";
            #endregion

            #region modified source code
            var newSource = @"
using System;
class Program
{
	public static void MethodToAdd()
    {
		Console.WriteLine(2);
    }

    public static void MethodToUpdate()
    {
		MethodToAdd();
    }

    public static void Main()
    {
		MethodToUpdate();
    }
}";
            #endregion

            Document document;
            Document newDocument;

            GetDocumentsFromSource(source, newSource, out document, out newDocument);

            var documentDiff  = new DocumentDiff();
            var modifications = await documentDiff.GetDifferencesAsync(document, newDocument);

            var remove = new MethodModification(new MethodDescriptor("Program", "MethodToRemove", true), ModificationKind.MethodRemoved);
            var update = new MethodModification(new MethodDescriptor("Program", "MethodToUpdate", true), ModificationKind.MethodUpdated);
            var add    = new MethodModification(new MethodDescriptor("Program", "MethodToAdd", true), ModificationKind.MethodAdded);

            Assert.IsTrue(modifications.Contains(remove));
            Assert.IsTrue(modifications.Contains(update));
            Assert.IsTrue(modifications.Contains(add));
        }