Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string tfsurl = "http://tfscollectionurl";
            TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(tfsurl));
            VersionControlServer     vcs  = ttpc.GetService <VersionControlServer>();

            string[]   path      = { "$/Path/To/Item.cs" };
            ItemSpec[] itemSpecs = ItemSpec.FromStrings(path, RecursionType.Full);
            ItemSpec   itemSpec  = itemSpecs.Cast <ItemSpec>().First();
            IEnumerable <Changeset> changesets = vcs.QueryHistory(itemSpec);
            Changeset latestchangeset          = changesets.Cast <Changeset>().First();

            Console.WriteLine(latestchangeset.Committer);
            Console.WriteLine(latestchangeset.CommitterDisplayName);
            Console.WriteLine(latestchangeset.Owner);
            Console.WriteLine(latestchangeset.OwnerDisplayName);
            Console.WriteLine(latestchangeset.CreationDate);
            Console.ReadLine();
        }
Exemplo n.º 2
0
        public ExtendedItem GetExtendedItem()
        {
            if (Workspace == null)
            {
                return(null);
            }

            var extendedItems = Workspace.GetExtendedItems(
                new[] { ItemSpec.FromStrings(new[] { Path }, RecursionType.None)[0] },
                DeletedState.Any,
                Microsoft.TeamFoundation.VersionControl.Client.ItemType.Any,
                GetItemsOptions.None);

            if (extendedItems[0].Length == 0)
            {
                return(null);
            }

            return(extendedItems[0][0]);
        }
Exemplo n.º 3
0
        public static void UncheckoutIfItHasBeenNotModified(string fileName, IServiceProvider serviceProvider)
        {
            var _md5Provider = new MD5CryptoServiceProvider();

            var fileInfo = new FileInfo(fileName);

            if (fileInfo.IsReadOnly)
            {
                return;
            }

            var tfsContext = serviceProvider.GetService <ITeamFoundationContextManager>();

            if (tfsContext == null)
            {
                return;
            }

            if (tfsContext.CurrentContext == null || tfsContext.CurrentContext.TeamProjectCollection == null)
            {
                return;
            }

            var tfs = tfsContext.CurrentContext.TeamProjectCollection;
            var vcs = tfs.GetService <VersionControlServer>();

            if (vcs == null)
            {
                return;
            }

            // If file is new nothing comparer
            if (!vcs.ServerItemExists(fileName, ItemType.File))
            {
                return;
            }

            var workspace = vcs.TryGetWorkspace(fileName);

            if (workspace == null)
            {
                return;
            }

            var fileInfoItem = vcs.GetItem(fileName);

            if (fileInfoItem != null)
            {
                using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan))
                {
                    var currentHash = _md5Provider.ComputeHash(fileStream);
                    var hashEquals  = HashEquals(currentHash, fileInfoItem.HashValue);
                    if (hashEquals && !IsMerged(workspace, fileName))
                    {
                        // This is from
                        // Assembly: Microsoft.VisualStudio.TeamFoundation.VersionControl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
                        // Type: Microsoft.VisualStudio.TeamFoundation.VersionControl.ClientHelperVS
                        // Method: internal static void Undo(Workspace workspace, PendingChange[] changes)
                        using (new WorkspaceSuppressAsynchronousScanner(workspace))
                        {
                            using (new WorkspacePersistedMetadataTables(workspace))
                            {
                                workspace.Undo(ItemSpec.FromStrings(new[] { fileInfoItem.ServerItem }, RecursionType.None), false);
                                workspace.UnqueueForEdit(fileName);

                                ////workspace.Get(new GetRequest(fileInfoItem.ServerItem, RecursionType.None, VersionSpec.Latest), GetOptions.None);
                                //var vsFileChangeEx = GetService<Microsoft.VisualStudio.Shell.Interop.SVsFileChangeEx, Microsoft.VisualStudio.Shell.Interop.IVsFileChangeEx>();
                                //vsFileChangeEx.SyncFile(fileName);
                            }
                        }
                    }
                }
            }
        }