Download only required solutions from workspace

2019-08-23 00:36发布

I have a piece of code that sets up a work space and download files from tfs work space programmatically. I want to extend to specify what solutions can I download in that work space. Any ideas how I can do this?

private GetStatus DownloadLatestFiles()
    {
        Workspace workspace = null;

        try
        {
            workspace = SetupWorkSpace();

            workspace.Map(_repositoryCredentials.RepositoryProjectPath, _repositoryCredentials.WorkingDirectory);
            GetRequest request = new GetRequest(new ItemSpec(_repositoryCredentials.RepositoryProjectPath, RecursionType.Full), VersionSpec.Latest);

            return workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite);
        }
        catch
        {
            throw;
        }
    }

    private Workspace SetupWorkSpace()
    {
        VersionControlServer sourceControl = SetupVersionControlRepositoryConnection();
        Workspace workspace = sourceControl.QueryWorkspaces(
                 Environment.MachineName,
                 sourceControl.AuthorizedUser,
                 Environment.MachineName).SingleOrDefault();

        if (workspace == null)
        {
            workspace = sourceControl.CreateWorkspace(Environment.MachineName, sourceControl.AuthenticatedUser, "newworkspace");
        }

        return workspace;
    }

I made a change so now it shows...

private GetStatus DownloadLatestFiles()
    {
        Workspace workspace = null;
        GetStatus status = null;

        try
        {
            workspace = SetupWorkSpace();
            List<Solution> services = _serviceList.GetAll();

           foreach (Solution solution in services)
            {
                WorkingFolder workingFolder = new WorkingFolder(ConvertLocalToTfsPath(solution), GetSolutionFolder(solution));
                workspace.CreateMapping(workingFolder);

                //GetRequest request = new GetRequest(new ItemSpec(_repositoryCredentials.RepositoryProjectPath, RecursionType.Full), VersionSpec.Latest);
                //status = workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite);
                status = workspace.Get();
            }
        }
        catch
        {
            throw;
        }

        return status;
    }

Currently still downloads all files.

2条回答
The star\"
2楼-- · 2019-08-23 00:42

Just add below piece of code:

     var workspace = sourceControl .CreateWorkspace("workspaceName","workspaceOwner");

        String ServerFolder = @"$/TeamProject/Solution1";
        String LocalFolder = @"D:\Folder\";

        WorkingFolder workfolder = new WorkingFolder(ServerFolder,LocalFolder);
        workspace.CreateMapping(workfolder);

        workspace.Get();

Refer to this article for detials: Download Project from TFS online With .NET C#

查看更多
欢心
3楼-- · 2019-08-23 00:56

I found the answer. Just a little bit of an adaption from what the above answer.

private List<GetStatus> DownloadLatestFiles()
    {
        Workspace workspace = null;
        List<GetStatus> statusResult = new List<GetStatus>();

        try
        {
            workspace = SetupWorkSpace();
            List<Solution> services = _serviceList.GetAll();

           foreach (Solution solution in services)
            {
                WorkingFolder workingFolder = new WorkingFolder(ConvertLocalToTfsPath(solution), GetSolutionFolder(solution));
                workspace.CreateMapping(workingFolder);

                GetRequest request = new GetRequest(new ItemSpec(ConvertLocalToTfsPath(solution), RecursionType.Full), VersionSpec.Latest);
                statusResult.Add(workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite));
            }
        }
        catch
        {
            throw;
        }

        return statusResult;
    }
查看更多
登录 后发表回答