Esempio n. 1
0
        /// <summary>
        /// The method opens up a window comparing two files
        /// </summary>
        /// <param name="compareFiles">The compare files view model</param>
        private static void CompareFiles(FileComparisonViewModel compareFiles)
        {
            string firstFileName  = Path.GetTempFileName();
            string secondFileName = Path.GetTempFileName();

            if (compareFiles.FirstFile != null)
            {
                compareFiles.FirstFile.DownloadShelvedFile(firstFileName);
            }

            if (compareFiles.SecondFile != null)
            {
                compareFiles.SecondFile.DownloadShelvedFile(secondFileName);
            }

            string diffToolCommandArguments = string.Empty;
            string diffToolCommand          = string.Empty;

            GetExternalTool(Path.GetExtension(compareFiles.FirstFile.FileName), out diffToolCommand, out diffToolCommandArguments);

            if (string.IsNullOrWhiteSpace(diffToolCommand))
            {
                var currentProcess = Process.GetCurrentProcess();
                currentProcess.StartInfo.FileName  = currentProcess.Modules[0].FileName;
                currentProcess.StartInfo.Arguments = string.Format(CultureInfo.CurrentCulture, @"/diff ""{0}"" ""{1}""", firstFileName, secondFileName);
                currentProcess.Start();
            }
            else
            {
                // So there is a tool configured. Let's use it
                diffToolCommandArguments = diffToolCommandArguments.Replace("%1", firstFileName).Replace("%2", secondFileName);
                var startInfo = new ProcessStartInfo()
                {
                    Arguments = diffToolCommandArguments,
                    FileName  = diffToolCommand
                };

                Process.Start(startInfo);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Returns true or false depending upon whether the first or second file name starts with the given filter.
 /// </summary>
 /// <param name="fileComparisonViewModel">The file comparison object to looking into</param>
 /// <param name="filter">The filter</param>
 /// <returns>True if the name exists. False otherwise</returns>
 private static bool HasMatchingFileName(FileComparisonViewModel fileComparisonViewModel, string filter)
 {
     return(fileComparisonViewModel.FirstFileDisplayName.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0 ||
            fileComparisonViewModel.SecondFileDisplayName.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0);
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes the Shelveset Comparison View Model
        /// </summary>
        /// <param name="firstShelveset">The first shelveset.</param>
        /// <param name="secondShelveset">The second shelveset</param>
        public void Initialize(Shelveset firstShelveset, Shelveset secondShelveset)
        {
            if (firstShelveset == null)
            {
                throw new ArgumentNullException("firstShelveset");
            }

            if (secondShelveset == null)
            {
                throw new ArgumentNullException("secondShelveset");
            }

            var tfcontextManager = this.GetService <ITeamFoundationContextManager>();
            var vcs = tfcontextManager.CurrentContext.TeamProjectCollection.GetService <VersionControlServer>();

            if (vcs == null)
            {
                this.SummaryText = Resources.ConnectionErrorMessage;
                return;
            }

            this.FirstShelvesetName  = firstShelveset.Name;
            this.SecondShelvesetName = secondShelveset.Name;

            this.files.Clear();
            var firstShelvesetChanges  = vcs.QueryShelvedChanges(firstShelveset)[0].PendingChanges;
            var secondShelvesetChanges = vcs.QueryShelvedChanges(secondShelveset)[0].PendingChanges;
            var orderedCollection      = new SortedList <string, FileComparisonViewModel>();

            int sameContentFileCount = 0;
            int commonFilesCount     = 0;

            foreach (var pendingChange in firstShelvesetChanges)
            {
                var matchingFile = secondShelvesetChanges.FirstOrDefault(s => s.ItemId == pendingChange.ItemId);
                if (matchingFile == null)
                {
                    matchingFile = secondShelvesetChanges.FirstOrDefault(s => s.LocalOrServerItem == pendingChange.LocalOrServerItem);
                }

                bool sameContent = matchingFile != null?AreFilesInPendingChangesSame(pendingChange, matchingFile) : false;

                FileComparisonViewModel comparisonItem = new FileComparisonViewModel()
                {
                    FirstFile        = pendingChange,
                    SecondFile       = matchingFile,
                    FirstShelveName  = firstShelvesetName,
                    SecondShelveName = SecondShelvesetName,
                    Color            = sameContent ? ColorMatchingFiles : (matchingFile != null) ? ColorDifferentFiles : ColorNoMatchingFile
                };

                orderedCollection.Add(pendingChange.LocalOrServerFolder + "/" + pendingChange.FileName, comparisonItem);
                if (sameContent)
                {
                    sameContentFileCount++;
                }

                if (matchingFile != null)
                {
                    commonFilesCount++;
                }
            }

            foreach (var pendingChange in secondShelvesetChanges)
            {
                if (!orderedCollection.ContainsKey(pendingChange.LocalOrServerFolder + "/" + pendingChange.FileName))
                {
                    var isThereAreNamedFile = FindItemWithSameItemId(orderedCollection, pendingChange.ItemId);
                    if (isThereAreNamedFile == null)
                    {
                        FileComparisonViewModel comparisonItem = new FileComparisonViewModel()
                        {
                            SecondFile       = pendingChange,
                            SecondShelveName = SecondShelvesetName,
                            Color            = ColorNoMatchingFile
                        };

                        orderedCollection.Add(pendingChange.LocalOrServerFolder + "/" + pendingChange.FileName, comparisonItem);
                    }
                }
            }

            foreach (var item in orderedCollection.Keys)
            {
                this.files.Add(orderedCollection[item]);
            }

            if (firstShelveset.Name == secondShelveset.Name && firstShelveset.OwnerName == secondShelveset.OwnerName)
            {
                this.SummaryText            = Resources.SameShelvesetMessage;
                this.TotalNumberOfFiles     = firstShelvesetChanges.Count();
                this.NumberOfDifferentFiles = 0;
                this.NumberOfMatchingFiles  = firstShelvesetChanges.Count();
            }
            else
            {
                this.SummaryText            = string.Format(CultureInfo.CurrentCulture, Resources.SummaryMessage, commonFilesCount, sameContentFileCount, orderedCollection.Count - sameContentFileCount);
                this.TotalNumberOfFiles     = commonFilesCount;
                this.NumberOfMatchingFiles  = sameContentFileCount;
                this.NumberOfDifferentFiles = orderedCollection.Count - sameContentFileCount;
            }
        }