Exemple #1
0
        /// <summary>
        /// Compares changesets
        /// </summary>
        /// <param name="localPath"></param>
        /// <param name="sourceChangesetId">Source changeset Id</param>
        /// <param name="serverUrl">Server Uri</param>
        /// <param name="srcPath">Source item path</param>
        public static void CompareLocal(string localPath, string sourceChangesetId, string serverUri, string srcPath)
        {
            if (String.IsNullOrWhiteSpace(sourceChangesetId))
            {
                throw new ArgumentException("'sourceChangesetId' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(serverUri))
            {
                throw new TfsHistorySearchException("'serverUri' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(srcPath))
            {
                throw new TfsHistorySearchException("'srcPath' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(localPath))
            {
                throw new TfsHistorySearchException("'localPath' is null or empty.");
            }

            TfsTeamProjectCollection tc  = new TfsTeamProjectCollection(new Uri(serverUri));
            VersionControlServer     vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

            //VersionSpec sourceVersion = VersionSpec.ParseSingleSpec(sourceChangesetId, vcs.TeamFoundationServer.AuthenticatedUserName);
            VersionSpec sourceVersion = VersionSpec.ParseSingleSpec(sourceChangesetId, vcs.AuthorizedUser);

            //VersionSpec targetVersion = VersionSpec.ParseSingleSpec(targetChangesetId, vcs.TeamFoundationServer.AuthenticatedUserName);

            //Difference.DiffFiles(
            Difference.VisualDiffItems(vcs, Difference.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion), Difference.CreateTargetDiffItem(vcs, localPath, null, 0, null));
            //Difference.VisualDiffFiles();
            //Difference.VisualDiffItems(vcs,
            //                           Difference.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion),
            //                           Difference.CreateTargetDiffItem(vcs, targetPath, targetVersion, 0, targetVersion));
        }
Exemple #2
0
        /// <summary>
        /// Compares changesets
        /// </summary>
        /// <param name="sourceChangesetId">Source changeset Id</param>
        /// <param name="targetChangesetId">Target changeset Id</param>
        /// <param name="serverUrl">Server Uri</param>
        /// <param name="srcPath">Source item path</param>
        /// <param name="targetPath">Target item path</param>
        public static void Compare(string sourceChangesetId, string targetChangesetId, string serverUri, string srcPath, string targetPath)
        {
            if (String.IsNullOrWhiteSpace(sourceChangesetId))
            {
                throw new ArgumentException("'sourceChangesetId' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(targetChangesetId))
            {
                throw new ArgumentException("'targetChangesetId' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(serverUri))
            {
                throw new ArgumentException("'serverUri' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(srcPath))
            {
                throw new ArgumentException("'srcPath' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(targetPath))
            {
                throw new ArgumentException("'targetPath' is null or empty.");
            }

            TfsTeamProjectCollection tc  = new TfsTeamProjectCollection(new Uri(serverUri));
            VersionControlServer     vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

            VersionSpec sourceVersion = VersionSpec.ParseSingleSpec(sourceChangesetId, vcs.AuthorizedUser);
            VersionSpec targetVersion = VersionSpec.ParseSingleSpec(targetChangesetId, vcs.AuthorizedUser);

            Difference.VisualDiffItems(vcs,
                                       Difference.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion),
                                       Difference.CreateTargetDiffItem(vcs, targetPath, targetVersion, 0, targetVersion));
        }
Exemple #3
0
 public void CompareFiles(string sourceFile, string targetFile)
 {
     Difference.VisualDiffItems(versionControlServer,
                                Difference.CreateTargetDiffItem(versionControlServer, sourceFile, VersionSpec.Latest, 0, VersionSpec.Latest),
                                Difference.CreateTargetDiffItem(versionControlServer, targetFile, VersionSpec.Latest, 0, VersionSpec.Latest),
                                false);
 }
Exemple #4
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);
        }
Exemple #5
0
        private bool DiffFiles(Item item1, Item item2)
        {
            if (item1 == null || item2 == null || item1.ItemType != ItemType.File)
            {
                return(false);
            }

            lock (_lock)
            {
                Difference.VisualDiffItems(_versionControlServer,
                                           Difference.CreateTargetDiffItem(_versionControlServer, item2.ServerItem, new ChangesetVersionSpec(item2.ChangesetId), 0, new ChangesetVersionSpec(item2.ChangesetId)),
                                           Difference.CreateTargetDiffItem(_versionControlServer, item1.ServerItem, new ChangesetVersionSpec(item1.ChangesetId), 0, new ChangesetVersionSpec(item1.ChangesetId)));
            }

            return(true);
        }
        /// <summary>
        /// Create a difference string from a shelveset
        /// Also sets the URl to the file on the TFS Server
        /// </summary>
        /// <param name="set">The selected PendingSet</param>
        /// <returns>the diff String which is sent to Codestriker</returns>
        public string ReviewShelveset(
            PendingSet set)
        {
            if (set == null)
            {
                throw new ArgumentNullException(nameof(set));
            }


            MemoryStream stream = new MemoryStream();

            StreamWriter writer = new StreamWriter(stream);

            {
                DiffOptions options = new DiffOptions
                {
                    Flags          = DiffOptionFlags.EnablePreambleHandling,
                    OutputType     = DiffOutputType.Unified,
                    TargetEncoding = Encoding.UTF8,
                    SourceEncoding = Encoding.UTF8,
                    Recursive      = true,
                    StreamWriter   = writer
                };

                StringBuilder sb        = new StringBuilder();
                int           streampos = 0;
                foreach (var pendingchange in set.PendingChanges)
                {
                    if (pendingchange.ItemType != ItemType.Folder)
                    {
                        string fileUrl = string.Format(pendingchange.VersionControlServer.TeamProjectCollection.Uri.AbsoluteUri);
                        fileUrl += s_LinkCompletionVersioncontrol;
                        fileUrl +=
                            $"{HttpUtility.UrlEncode(pendingchange.PendingSetName + ";" + pendingchange.PendingSetOwner)}{s_PathParameter}";
                        fileUrl += HttpUtility.UrlEncode(pendingchange.LocalOrServerItem);
                        //the semicolons after s_ActionParameter and pendingchange.FileName are important for the right parsing on codestriker
                        fileUrl += $"{s_ActionParameter}&#path={HttpUtility.UrlEncode(pendingchange.LocalOrServerItem)}{s_ActionParameter};{pendingchange.LocalOrServerItem};";

                        var diffChange  = new DiffItemShelvedChange(set.Name, pendingchange);
                        var diffVersion = Difference.CreateTargetDiffItem(m_VersionControl, pendingchange, null);

                        Difference.DiffFiles(
                            m_VersionControl,
                            diffVersion,
                            diffChange,
                            options,
                            string.Empty,
                            true);

                        writer.Flush();
                        sb.Append(writer.GetHashCode()).Append(Environment.NewLine);
                        string pendingChangeString = Encoding.UTF8.GetString(stream.ToArray().Skip(streampos).ToArray());

                        Regex rgx = new Regex(s_RegexPattern);

                        //replace the filename with the tfs url path of the file
                        //necessary for the link between codestriker and TFS
                        pendingChangeString = rgx.Replace(
                            pendingChangeString,
                            m => m.Groups["prefix"].Value + ": " + fileUrl,
                            1);

                        sb.Append(pendingChangeString);
                        streampos = stream.ToArray().Length;
                    }
                }

                return(sb.ToString());
            }

            #endregion
        }