예제 #1
0
        public Workspace MapWorkspace(Workspace ws, TfsTeamProjectCollection pc)
        {
            try
            {
                var serverPath = "$/";
                var localPath  = pc.GetProjectCollectionLocalPath(Globals.TfsRoot);
                $"mapWorkspace: {nameof(serverPath)} = {serverPath}".Trace();
                $"mapWorkspace: {nameof(localPath)} = {localPath}".Trace();
                var vcs = pc.GetService <VersionControlServer>();
                var lws = Workstation.Current.RemoveCachedWorkspaceInfo(vcs);
                var wss = vcs.QueryWorkspaces(null, vcs.AuthorizedUser, null);
                foreach (var workspace in wss)
                {
                    $"Checking workspace {workspace.Name} for mapping of local path {localPath}".Info();
                    if (workspace.IsLocalPathMapped(localPath))
                    {
                        var wf = workspace.TryGetWorkingFolderForLocalItem(localPath);
                        if (wf != null)
                        {
                            try
                            {
                                workspace.DeleteMapping(wf);
                            }
                            catch (Exception e)
                            {
                                $"Exception in {nameof(MapWorkspace)} while deleting mapping".Error();
                            }
                        }
                        $"Deleted {localPath} mapping from workspace {workspace.Name}".Info();
                    }
                }

                ws.Map(serverPath, localPath);
                return(ws);
            }
            catch (Exception e)
            {
                e.Error();
            }
            return(null);
        }
예제 #2
0
 private void DropMappings(TfsTeamProjectCollection collection)
 {
     try
     {
         var vcs       = collection.GetService <VersionControlServer>();
         var wss       = vcs.QueryWorkspaces(null, vcs.AuthorizedUser, null);
         var localPath = collection.GetProjectCollectionLocalPath(Globals.TfsRoot);
         var withPath  = wss.Select(workspace => Tuple.Create(workspace, workspace.TryGetWorkingFolderForServerItem(collection.Uri.AbsoluteUri)));
         foreach (var tuple in withPath)
         {
             if (tuple.Item1 != null && tuple.Item2 != null)
             {
                 $"Dropping {tuple.Item2.LocalItem} for workspace {tuple.Item1.Name}".Info();
                 tuple.Item1.DeleteMapping(tuple.Item2);
             }
         }
     }
     catch (Exception e)
     {
         e.Error();
     }
 }