示例#1
1
        /// <summary>
        /// 'Pends' a delete of a folder and its contents that was previously 
        /// checked-in and then commits that deletion to the repository.
        /// </summary>
        /// <param name="workspace">Version control workspace to use when 
        /// deleting the folder and its contents.</param>
        /// <param name="newFilename">Full path to the folder to delete</param>
        /// <exception cref="SecurityException">If the user doesn't have
        /// check-in permission for the specified <paramref name="workspace"/>.</exception>
        /// <exception cref="IOException">If there's a problem creating the file.</exception>
        /// <exception cref="VersionControlException">If </exception>
        private static void DeleteFolder(Workspace workspace, String newFolder)
        {
            Debug.Assert(workspace != null);
            Debug.Assert(!String.IsNullOrEmpty(newFolder));

            try
            {
                // Delete the items
                workspace.PendDelete(workspace.GetServerItemForLocalItem(newFolder), RecursionType.Full);
                var pendingDeletes = workspace.GetPendingChanges();

                if (pendingDeletes.Length > 0)
                {
                    workspace.CheckIn(pendingDeletes, "Clean up!");
                }
            }
            catch (VersionControlException ex)
            {
                Console.Error.WriteLine("Error deleting file: {0}", ex.Message);
                throw;
            }
        }
示例#2
0
        public void Workspace_GetServerItemForLocalItem_PassValidItem()
        {
            string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT"));
            string item1      = String.Format("{0}/foo.txt", serverItem);
            string item2      = workspace.GetServerItemForLocalItem(Path.Combine(Environment.CurrentDirectory, "foo.txt"));

            Assert.AreEqual(item1, item2);
        }
示例#3
0
 public ElPackager(string root, TfsChangesets changesets)
 {
     _root = root;
     var tpc = new TfsTeamProjectCollection(new Uri(TfsUrl));
     var vc = tpc.GetService<VersionControlServer>();
     _workspace = vc.GetWorkspace(root);
     var serverFolder = _workspace.GetServerItemForLocalItem(root);
     changesets.LoadChangesets(vc, serverFolder);
     _changesets = changesets;
 }
        public string GetBranchNameForItem(
            string localFullPath, 
            bool waitForConnection, 
            CancellationToken cancellationToken,
            out Workspace workspace, 
            out BranchObject branchObject)
        {
            workspace = null;
            branchObject = null;

            try
            {
                if (localFullPath.IsNullOrEmpty())
                    return null;

                WaitForConnection();

                if (cancellationToken.IsCancellationRequested)
                    return null;

                var info = Workstation.Current.GetLocalWorkspaceInfo(localFullPath);
                if (info == null)
                    return null;

                var serverName = info.ServerUri;

                var tfsSrv = Microsoft.TeamFoundation.Client.TeamFoundationServerFactory.GetServer(serverName);

                VersionControlServer vcs = (VersionControlServer)tfsSrv.GetService(typeof(VersionControlServer));

                if (cancellationToken.IsCancellationRequested)
                    return null;

                workspace = vcs.TryGetWorkspace(localFullPath);
                if (workspace == null)
                    return null;

                var serverItem = workspace.GetServerItemForLocalItem(localFullPath);

                if (cancellationToken.IsCancellationRequested)
                    return null;

                var branchObjects =
                    vcs.QueryRootBranchObjects(RecursionType.Full)
                    .OrderBy(bo => bo.Properties.RootItem.Item)
                    .Reverse();

                var itemSpecs = new ItemSpec[]
                {
                    new ItemSpec(serverItem, RecursionType.None)
                };

                // for each itemSpec return BranchHistoryItem[]
                var branchHistory = vcs.GetBranchHistory(itemSpecs, VersionSpec.Latest);

                if (!branchHistory[0].Any())
                    return null;

                if (cancellationToken.IsCancellationRequested)
                    return null;

                branchObject =
                    (from bo in branchObjects
                     where serverItem.StartsWith(bo.Properties.RootItem.Item)
                     select bo).
                     FirstOrDefault();

                if (branchObject == null)
                    return null;

                var branchName = System.IO.Path.GetFileName(branchObject.Properties.RootItem.Item);

                if (cancellationToken.IsCancellationRequested)
                    return null;

                return branchName;

            }
            catch (Exception ex)
            {
                // TODO: logging
                return null;
            }
        }
 public string GetServerItemForLocalItem(Workspace workspace, string localItem)
 {
     return workspace.GetServerItemForLocalItem(localItem);
 }