private TIdType GetID(IDiffItem leftItem)
 {
     if (leftItem is IDiffUnorderedCollectionItemWithID)
     {
         return(((IDiffUnorderedCollectionItemWithID <TIdType>)leftItem).Id);
     }
     else if (leftItem is IDiffItemAdded)
     {
         return(this.aIdAccessor(((IDiffItemAdded <TItemType>)leftItem).NewValue));
     }
     else if (leftItem is IDiffItemRemoved)
     {
         return(this.aIdAccessor(((IDiffItemRemoved <TItemType>)leftItem).OldValue));
     }
     else if (leftItem is IDiffItemReplaced)
     {
         return(this.aIdAccessor(((IDiffItemReplaced <TItemType>)leftItem).OldValue));
     }
     else if (leftItem is IDiffItemUnchanged)
     {
         return(this.aIdAccessor(((IDiffItemUnchanged <TItemType>)leftItem).Value));
     }
     else
     {
         throw new Exception();
     }
 }
Beispiel #2
0
        public static void DiffFiles(IDiffItem source, IDiffItem target,
                                     DiffOptions diffOpts, string fileNameForHeader,
                                     bool wait)
        {
            DiffItemUtil aItem  = new DiffItemUtil('a', fileNameForHeader, source.GetFile());
            DiffItemUtil bItem  = new DiffItemUtil('b', fileNameForHeader, target.GetFile());
            StreamWriter stream = diffOpts.StreamWriter;

            // short circuit for binary file comparisions
            if (source.GetEncoding() == RepositoryConstants.EncodingBinary && target.GetEncoding() == RepositoryConstants.EncodingBinary)
            {
                stream.WriteLine("Binary files {0} and {1} differ", aItem.Name, bItem.Name);
                return;
            }

            WriteHeader(aItem, bItem, diffOpts);

            // short circuit new files
            if (aItem.Length == 0)
            {
                WriteNewFile(stream, bItem.Lines);
                return;
            }

            Hashtable hashtable        = new Hashtable(aItem.Length + bItem.Length);
            bool      ignoreWhiteSpace = (diffOpts.Flags & DiffOptionFlags.IgnoreWhiteSpace) == DiffOptionFlags.IgnoreWhiteSpace;

            DiffItem[] items = DiffUtil.DiffText(hashtable, aItem.Lines, bItem.Lines,
                                                 ignoreWhiteSpace, ignoreWhiteSpace, false);

            WriteUnified(stream, aItem.Lines, bItem.Lines, items);
        }
Beispiel #3
0
        public static void DiffFiles(VersionControlServer versionControl,
																	IDiffItem source, IDiffItem target,
																	DiffOptions diffOpts, string fileNameForHeader,
																	bool wait)
        {
            DiffItemUtil aItem = new DiffItemUtil('a', fileNameForHeader, source.GetFile());
            DiffItemUtil bItem = new DiffItemUtil('b', fileNameForHeader, target.GetFile());
            StreamWriter stream = diffOpts.StreamWriter;

            // short circuit for binary file comparisions
            if (source.GetEncoding() == RepositoryConstants.EncodingBinary && target.GetEncoding() == RepositoryConstants.EncodingBinary)
                {
                    stream.WriteLine("Binary files {0} and {1} differ", aItem.Name, bItem.Name);
                    return;
                }

            WriteHeader(aItem, bItem, diffOpts);

            // short circuit new files
            if (aItem.Length == 0)
                {
                    WriteNewFile(stream, bItem.Lines);
                    return;
                }

            Hashtable hashtable = new Hashtable(aItem.Length + bItem.Length);
            bool ignoreWhiteSpace = (diffOpts.Flags & DiffOptionFlags.IgnoreWhiteSpace) ==  DiffOptionFlags.IgnoreWhiteSpace;

            DiffItem[] items = DiffUtil.DiffText(hashtable, aItem.Lines, bItem.Lines,
                                                                                     ignoreWhiteSpace, ignoreWhiteSpace, false);

            WriteUnified(stream, aItem.Lines, bItem.Lines, items);
        }
Beispiel #4
0
        private static void RunMain(string[] args)
        {
            if (args.Length != 3)
            {
                WriteErrorAndSetErrorCode("Wrong number of arguments." + Environment.NewLine + Environment.NewLine + "Sample:" + Environment.NewLine + "justassembly.commandlinetool Path\\To\\Assembly1 Path\\To\\Assembly2 Path\\To\\XMLOutput");
                return;
            }

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

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

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

            string xml = string.Empty;

            try
            {
                IDiffItem diffItem = APIDiffHelper.GetAPIDifferences(args[0], args[1]);
                if (diffItem != null)
                {
                    xml = diffItem.ToXml();
                }
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("A problem occurred while creating the API diff.", ex);
                return;
            }

            try
            {
                using (StreamWriter writer = new StreamWriter(args[2]))
                {
                    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();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                WriteErrorAndSetErrorCode("Exactly 3 arguments are needed - 2 file paths for input files and 1 file path for output xml file.");
                return;
            }

            if (!FilePathValidater.ValidateInputFile(args[0]))
            {
                WriteErrorAndSetErrorCode("First file path is in incorrect format or file not found.");
                return;
            }

            if (!FilePathValidater.ValidateInputFile(args[1]))
            {
                WriteErrorAndSetErrorCode("Second file path is in incorrect format or file not found.");
                return;
            }

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

            string xml = string.Empty;

            try
            {
                IDiffItem diffItem = APIDiffHelper.GetAPIDifferences(args[0], args[1]);
                if (diffItem != null)
                {
                    xml = diffItem.ToXml();
                }
            }
            catch (Exception ex)
            {
                WriteExceptionAndSetErrorCode("There was a problem during calculation of API differences.", ex);
                return;
            }

            try
            {
                using (StreamWriter writer = new StreamWriter(args[2]))
                {
                    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();
        }
        public bool IsSame(IDiffItem other)
        {
            if (!(other is IDiffItemChanged <TItemType>))
            {
                return(false);
            }

            return(object.Equals(this.ValueDiff, ((IDiffItemChanged <TItemType>)other).ValueDiff));
        }
Beispiel #7
0
        public bool IsSame(IDiffItem other)
        {
            if (!(other is IDiffItemRemoved <TItemType>))
            {
                return(false);
            }

            return(object.Equals(this.OldValue, ((IDiffItemRemoved <TItemType>)other).OldValue));
        }
Beispiel #8
0
        public bool IsSame(IDiffItem other)
        {
            if (!(other is IDiffItemConflicted))
            {
                return(false);
            }

            return(this.Left.SequenceEqual(((IDiffItemConflicted)other).Left) &&
                   this.Right.SequenceEqual(((IDiffItemConflicted)other).Right));
        }
Beispiel #9
0
        /// <summary>
        /// Visual compare current text document with the latest version in Version Control.
        /// </summary>
        private void CompareDocumentWithLatestVersion()
        {
            Item item = _marginCore.VersionControlItem;
            VersionControlServer vcs     = item.VersionControlServer;
            ITextDocument        textDoc = _marginCore.TextDocument;

            IDiffItem source = Difference.CreateTargetDiffItem(vcs, item.ServerItem, VersionSpec.Latest, 0, VersionSpec.Latest);
            var       target = new DiffItemLocalFile(textDoc.FilePath, textDoc.Encoding.CodePage, textDoc.LastContentModifiedTime, false);

            Difference.VisualDiffItems(vcs, source, target);
        }
        private static bool IncludeDiffType(SuggestedVersionChange prevent, IDiffItem change)
        {
            switch (prevent)
            {
            case SuggestedVersionChange.Major:
                return(change.IsBreakingChange);

            case SuggestedVersionChange.Minor:
                return(change.IsBreakingChange || change.DiffType == DiffType.New);

            case SuggestedVersionChange.Patch:
                return(true);

            default:
                return(false);
            }
        }
Beispiel #11
0
        public IEnumerable <IDiffItem> GetMultipleDifferences(IEnumerable <T> oldElements, IEnumerable <T> newElements)
        {
            List <T> oldElementsSorted = new List <T>(oldElements);

            oldElementsSorted.Sort(CompareElements);

            List <T> newElementsSorted = new List <T>(newElements);

            newElementsSorted.Sort(CompareElements);

            int oldIndex;
            int newIndex;

            List <IDiffItem> result = new List <IDiffItem>();

            for (oldIndex = 0, newIndex = 0; oldIndex < oldElementsSorted.Count && newIndex < newElementsSorted.Count;)
            {
                T oldElement = oldElementsSorted[oldIndex];
                T newElement = newElementsSorted[newIndex];

                int compareResult = CompareElements(oldElement, newElement);

                if (compareResult < 0)
                {
                    oldIndex++;
                    if (IsAPIElement(oldElement))
                    {
                        result.Add(GetMissingDiffItem(oldElement));
                    }
                }
                else if (compareResult > 0)
                {
                    newIndex++;
                    if (IsAPIElement(newElement))
                    {
                        IDiffItem newItem = GetNewDiffItem(newElement);
                        if (newItem != null)
                        {
                            result.Add(newItem);
                        }
                    }
                }
                else
                {
                    oldIndex++;
                    newIndex++;
                    if (IsAPIElement(oldElement) || IsAPIElement(newElement))
                    {
                        IDiffItem diffResult = this.GenerateDiffItem(oldElement, newElement);
                        if (diffResult != null)
                        {
                            result.Add(diffResult);
                        }
                    }
                }
            }

            for (; oldIndex < oldElementsSorted.Count; oldIndex++)
            {
                if (IsAPIElement(oldElementsSorted[oldIndex]))
                {
                    result.Add(GetMissingDiffItem(oldElementsSorted[oldIndex]));
                }
            }

            for (; newIndex < newElementsSorted.Count; newIndex++)
            {
                if (IsAPIElement(newElementsSorted[newIndex]))
                {
                    IDiffItem newItem = GetNewDiffItem(newElementsSorted[newIndex]);
                    if (newItem != null)
                    {
                        result.Add(newItem);
                    }
                }
            }

            return(result);
        }
Beispiel #12
0
 public ClassDiffItemFactory <TType> Custom(IDiffItem item)
 {
     this.aDiffItems.Add(item);
     return(this);
 }
 public KeyValueDiffItemFactory <TType, TKey, TValue> Custom(IDiffItem item)
 {
     this.aDiffItems.Add(item);
     return(this);
 }
Beispiel #14
0
 public UnorderedDiffItemFactory <TType, TValue> Custom(IDiffItem item)
 {
     this.aDiffItems.Add(item);
     return(this);
 }
Beispiel #15
0
        private void WriteDiffsToStream(Item file, IDiffItem sourceItem, IDiffItem targetItem, StreamWriter outputStream)
        {
            var diffOptions = new DiffOptions
            {
                SourceEncoding = Encoding.GetEncoding(file.Encoding),
                TargetEncoding = Encoding.GetEncoding(file.Encoding),
                OutputType = DiffOutputType.Unified,
                StreamWriter = outputStream,
            };

            Difference.DiffFiles(this.versionControlServer, sourceItem, targetItem, diffOptions, "AllYourBaseAreBelongToUs", true);
        }
Beispiel #16
0
 public DiffAnyConflicted(IDiffItem left, IDiffItem right)
 {
     this.Left  = new DiffItemList(left);
     this.Right = new DiffItemList(right);
 }
        private string GetAPIDiffResult(string oldFile, string newFile)
        {
            IDiffItem diffItem = APIDiffHelper.GetAPIDifferences(oldFile, newFile);

            return(diffItem == null ? string.Empty : diffItem.ToXml());
        }