예제 #1
1
        public Workspace GetWorkspaceByName(string workspaceName, VersionControlServer sourceControl)
        {
            Workspace MyWorkspace = null;

            if (String.IsNullOrEmpty(workspaceName))
            {
                throw new BuildException("Unable to determine Workspace to use as both the WorkspaceName and LocalItem are not set.");
            }

            Workspace[] Workspaces = sourceControl.QueryWorkspaces(workspaceName, sourceControl.AuthenticatedUser, Workstation.Current.Name);
            if (Workspaces.Length > 0)
                MyWorkspace = Workspaces[0];

            return MyWorkspace;
        }
예제 #2
0
        public void UpdateWorkspaceInfoCache(VersionControlServer versionControl,
                                             string ownerName)
        {
            InternalServerInfo[] serverInfos = ReadCachedWorkspaceInfo();
            XmlElement           servers     = InitWorkspaceInfoCache();

            Workspace[]        workspaces    = versionControl.QueryWorkspaces(null, ownerName, Name);
            InternalServerInfo newServerInfo = new InternalServerInfo(versionControl.Uri.ToString(), versionControl.ServerGuid, workspaces);

            bool found = false;

            foreach (InternalServerInfo sInfo in serverInfos)
            {
                InternalServerInfo finalInfo = sInfo;
                if (sInfo.Uri == versionControl.Uri)
                {
                    finalInfo = newServerInfo;
                    found     = true;
                }

                XmlElement serverInfoElement = finalInfo.ToXml(servers.OwnerDocument);
                servers.AppendChild(serverInfoElement);
            }

            if (!found)
            {
                XmlElement serverInfoElement = newServerInfo.ToXml(servers.OwnerDocument);
                servers.AppendChild(serverInfoElement);
            }

            SaveWorkspaceInfoCache(servers.OwnerDocument);
        }
        public void Workspace_QueryWorkspaces2()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

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

            Workspace[] workspaces = vcs.QueryWorkspaces(null, null, Environment.MachineName);
            foreach (Workspace workspace in workspaces)
            {
                Assert.IsNotNull(workspace.Name);
            }
        }
예제 #4
0
        /// <summary>
        /// Gets a TFS workspace mapped to the specified target path (i.e. generally the /SRC temporary directory)
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="sourcePath">The source path.</param>
        /// <param name="targetPath">The target path.</param>
        private Workspace GetMappedWorkspace(VersionControlServer server, string sourcePath, string targetPath)
        {
            string workspaceName = "BuildMaster" + Guid.NewGuid().ToString().Replace("-", "");

            var workspaces = server.QueryWorkspaces(workspaceName, server.AuthorizedUser, Environment.MachineName);
            var workspace = workspaces.SingleOrDefault(ws => ws.Name == workspaceName);
            if (workspace != null)
            {
                workspace.Delete();
            }

            workspace = server.CreateWorkspace(workspaceName);

            workspace.CreateMapping(new WorkingFolder(sourcePath, targetPath));

            if (!workspace.HasReadPermission)
            {
                throw new SecurityException(String.Format("{0} does not have read permission for {1}", server.AuthorizedUser, targetPath));
            }

            return workspace;
        }
 private string GetLatestVerstion(VersionControlServer versionControl, TfsGetCodeParams objTfsGetCodeParams)
 {
     Workspace[] workspaces = versionControl.QueryWorkspaces(objTfsGetCodeParams.WorkStationName, versionControl.AuthenticatedUser, Workstation.Current.Name);
     if (workspaces.Length > 0)
     {
         versionControl.DeleteWorkspace(objTfsGetCodeParams.WorkStationName, versionControl.AuthenticatedUser);
     }
     Workspace workspace = versionControl.CreateWorkspace(objTfsGetCodeParams.WorkStationName, versionControl.AuthenticatedUser, "Temporary Workspace");
     try
     {
         workspace.Map(objTfsGetCodeParams.SourcePath, objTfsGetCodeParams.TargetPath+"/"+objTfsGetCodeParams.BuildVersion );
         GetRequest request = new GetRequest(new ItemSpec(objTfsGetCodeParams.SourcePath, RecursionType.Full), VersionSpec.Latest);
         GetStatus status = workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite); // this line doesn't do anything - no failures or errors
         return "done";
     }
     finally
     {
         if (workspace != null)
         {
             workspace.Delete();
         }
     }
 }
예제 #6
0
 private static void RemoveWorkspace(string workspaceName, VersionControlServer server)
 {
     TraceHelper.TraceInformation(TraceSwitches.TfsDeployer, "Removing Workspace{0}", workspaceName);
     if (server.QueryWorkspaces(workspaceName, server.AuthenticatedUser, Environment.MachineName).Length > 0)
     {
         server.DeleteWorkspace(workspaceName, server.AuthenticatedUser);
     }
 }
예제 #7
0
        /// <summary>
        /// Gets a TFS workspace mapped to the specified target path
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="sourcePath">The source path.</param>
        /// <param name="targetPath">The target path.</param>
        private Workspace GetMappedWorkspace(VersionControlServer server, TfsSourceControlContext context)
        {
            var workspaces = server.QueryWorkspaces(context.WorkspaceName, server.AuthorizedUser, Environment.MachineName);
            var workspace = workspaces.FirstOrDefault();
            if (workspace == null) 
        {
                this.LogDebug("Existing workspace not found, creating workspace \"{0}\"...", context.WorkspaceName);
                workspace = server.CreateWorkspace(context.WorkspaceName);
            }
            else 
            {
                this.LogDebug("Workspace found: " + workspace.Name);
            }

            this.LogDebug("Workspace mappings: \r\n" + string.Join(Environment.NewLine, workspace.Folders.Select(m => m.LocalItem + "\t->\t" + m.ServerItem)));

            if (!workspace.IsLocalPathMapped(context.WorkspaceDiskPath))
            {
                this.LogDebug("Local path is not mapped, creating mapping to \"{0}\"...", context.WorkspaceDiskPath);
                this.DeleteWorkspace(context);
                workspace.Map(context.SourcePath, context.WorkspaceDiskPath);
            }

            if (!workspace.HasReadPermission)
                throw new System.Security.SecurityException(string.Format("{0} does not have read permission for {1}", server.AuthorizedUser, context.WorkspaceDiskPath));

            return workspace;
        }
예제 #8
0
        public void UpdateWorkspaceInfoCache(VersionControlServer versionControl,
																				 string ownerName)
        {
            InternalServerInfo[] serverInfos = ReadCachedWorkspaceInfo();
            XmlElement servers = InitWorkspaceInfoCache();

            Workspace[] workspaces = versionControl.QueryWorkspaces(null, ownerName, Name);
            InternalServerInfo newServerInfo = new InternalServerInfo(versionControl.Uri.ToString(), versionControl.ServerGuid, workspaces);

            bool found = false;
            foreach (InternalServerInfo sInfo in serverInfos)
                {
                    InternalServerInfo finalInfo = sInfo;
                    if (sInfo.Uri == versionControl.Uri)
                        {
                            finalInfo = newServerInfo;
                            found = true;
                        }

                    XmlElement serverInfoElement = finalInfo.ToXml(servers.OwnerDocument);
                    servers.AppendChild(serverInfoElement);
                }

            if (!found)
                {
                    XmlElement serverInfoElement = newServerInfo.ToXml(servers.OwnerDocument);
                    servers.AppendChild(serverInfoElement);
                }

            SaveWorkspaceInfoCache(servers.OwnerDocument);
        }
예제 #9
0
        private void InitTfsWorkspace()
        {
            tfsCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(RegisteredTfsConnections.GetProjectCollections().Single());
            versionControlServer = tfsCollection.GetService<VersionControlServer>();

            userName = tfsCollection.AuthorizedIdentity.UniqueName;

            workspace = versionControlServer.QueryWorkspaces(null, null, System.Environment.MachineName).Single();
            workingFolders = workspace.Folders.Where(f => !f.IsCloaked).ToList();

            tfsProjects = new List<TeamProject>();
            folderByProject = new Dictionary<TeamProject, WorkingFolder>();
            foreach (var folder in workingFolders)
            {
                var project = workspace.GetTeamProjectForLocalPath(folder.LocalItem);
                if (!folderByProject.ContainsKey(project))
                {
                    tfsProjects.Add(project);
                    folderByProject.Add(project, folder);
                }
            }

            ProjectsCombo.ItemsSource = tfsProjects;
            allBranches = versionControlServer.QueryRootBranchObjects(RecursionType.Full);
        }
        private void SetupWorkspace(string workingDirectory, string cpSourceBranch, VersionControlServer versionControl)
        {
            List<WorkingFolder> workingFolders = new List<WorkingFolder>();
            workingFolders.Add(new WorkingFolder(cpSourceBranch, workingDirectory));

            // Create a workspace.
            Workspace[] workspaces = versionControl.QueryWorkspaces(sourcePuller.WorkspaceName, versionControl.AuthorizedUser, Environment.MachineName);

            if (workspaces.Length > 0)
                versionControl.DeleteWorkspace(sourcePuller.WorkspaceName, versionControl.AuthorizedUser);

            workspace = versionControl.CreateWorkspace(sourcePuller.WorkspaceName, versionControl.AuthorizedUser, "Work for GetTFSSourceUtil tool", workingFolders.ToArray(), Environment.MachineName);
        }