Esempio n. 1
0
        /// <summary>
        /// Downloads the source for the specified changeset.
        /// </summary>
        /// <param name="projectSourcePath">The project source path.</param>
        /// <param name="changesetID">The ID of the changeset to be downloaded.</param>
        /// <param name="workspaceName">The name of the local workspace.</param>
        /// <param name="localWorkspacePath">The local workspace path.</param>
        public void DownloadSource(string projectSourcePath, int changesetID, string workspaceName, string localWorkspacePath)
        {
            if (string.IsNullOrEmpty(projectSourcePath))
            {
                throw new ArgumentNullException(projectSourcePath);
            }

            Workspace workspace = null;

            try
            {
                workspace = SourceControl.GetWorkspace(workspaceName,
                                                       SourceControl.AuthorizedUser);
            }
            catch (WorkspaceNotFoundException)
            {
                workspace = SourceControl.CreateWorkspace(workspaceName,
                                                          SourceControl.AuthorizedUser);
            }

            var serverFolder  = String.Format(CultureInfo.InvariantCulture, "$/{0}/", projectSourcePath.TrimEnd('/'));
            var workingFolder = new WorkingFolder(serverFolder, localWorkspacePath);

            // Create a workspace mapping
            workspace.CreateMapping(workingFolder);
            if (!workspace.HasReadPermission)
            {
                throw new SecurityException(
                          String.Format(CultureInfo.InvariantCulture, Resources.ReadPermissionException,
                                        SourceControl.AuthorizedUser, serverFolder));
            }

            workspace.Get(new ChangesetVersionSpec(changesetID), GetOptions.GetAll);
        }