コード例 #1
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);
        }
コード例 #2
0
        private void GetLabeledInternal(string sourcePath, string label, string targetDirectory, string workspaceDiskPath)
        {
            var context = new TfsSourceControlContext(this, sourcePath, label, workspaceDiskPath);

            this.EnsureLocalWorkspaceInternal(context);
            this.UpdateLocalWorkspaceInternal(context);
            this.ExportFilesInternal(context, targetDirectory);
        }
コード例 #3
0
        private void ApplyLabel(TfsSourceControlContext context, string label)
        {
            using (var tfs = this.GetTeamProjectCollection())
            {
                var versionControlService = tfs.GetService <VersionControlServer>();

                var versionControlLabel = new VersionControlLabel(versionControlService, label, versionControlService.AuthorizedUser, context.SourcePath, "Label applied by BuildMaster");
                versionControlService.CreateLabel(versionControlLabel, new[] { new LabelItemSpec(new ItemSpec(context.SourcePath, RecursionType.Full), VersionSpec.Latest, false) }, LabelChildOption.Replace);
            }
        }
コード例 #4
0
        private byte[] GetFileContents(TfsSourceControlContext context)
        {
            var tempFile = Path.GetTempFileName();

            using (var tfs = this.GetTeamProjectCollection())
            {
                var versionControlServer = tfs.GetService <VersionControlServer>();
                var item = versionControlServer.GetItem(context.SourcePath);
                item.DownloadFile(tempFile);

                return(File.ReadAllBytes(tempFile));
            }
        }
コード例 #5
0
 private DirectoryEntryInfo GetDirectoryEntryInfo(TfsSourceControlContext context)
 {
     using (var tfs = this.GetTeamProjectCollection())
     {
         var sourceControl = tfs.GetService <VersionControlServer>();
         var itemSet       = sourceControl.GetItems(context.SourcePath, RecursionType.OneLevel);
         return(new DirectoryEntryInfo(
                    context.LastSubDirectoryName,
                    context.SourcePath,
                    itemSet.Items.Where(i => i.ServerItem != context.SourcePath).Select(i => context.CreateSystemEntryInfo(i))
                    ));
     }
 }
コード例 #6
0
        private byte[] GetFileContentsInternal(string filePath, string workspaceDiskPath)
        {
            var context = new TfsSourceControlContext(this, filePath, workspaceDiskPath);

            var tempFile = Path.GetTempFileName();

            using (var tfs = this.GetTeamProjectCollection())
            {
                var versionControlServer = tfs.GetService <VersionControlServer>();
                var item = versionControlServer.GetItem(context.SourcePath);
                item.DownloadFile(tempFile);

                return(File.ReadAllBytes(tempFile));
            }
        }
コード例 #7
0
        private object GetCurrentRevision(TfsSourceControlContext context)
        {
            using (var tfs = this.GetTeamProjectCollection())
            {
                var sourceControl = tfs.GetService <VersionControlServer>();

                string sourcePath = sourceControl.GetItem(context.SourcePath).ServerItem; // matches the sourcePath with the base path returned by TFS

                var itemSet = sourceControl.GetItems(sourcePath, VersionSpec.Latest, RecursionType.Full, DeletedState.Any, ItemType.Any);
                if (itemSet == null || itemSet.Items == null || itemSet.Items.Length == 0)
                {
                    return(new byte[0]);
                }

                return(itemSet.Items.Max(i => i.ChangesetId));
            }
        }
コード例 #8
0
        private byte[] GetFileContents(TfsSourceControlContext context)
        {
            var tempFile = Path.GetTempFileName();
            using (var tfs = this.GetTeamProjectCollection())
            {
                var versionControlServer = tfs.GetService<VersionControlServer>();
                var item = versionControlServer.GetItem(context.SourcePath);
                item.DownloadFile(tempFile);

                return File.ReadAllBytes(tempFile);
            }
        }
コード例 #9
0
 private void GetLatest(TfsSourceControlContext context, string targetPath)
 {
     this.EnsureLocalWorkspace(context);
     this.UpdateLocalWorkspace(context);
     this.ExportFiles(context, targetPath);
 }
コード例 #10
0
 /// <summary>
 /// When implemented in a derived class, retrieves labeled
 /// source code from the provider's source path into the target path.
 /// </summary>
 /// <param name="label">Label of source files to get.</param>
 /// <param name="sourcePath">Provider source path.</param>
 /// <param name="targetPath">Target file path.</param>
 /// <exception cref="ArgumentNullException">
 /// sourcePath
 /// or
 /// targetPath
 /// </exception>
 /// <exception cref="DirectoryNotFoundException">targetPath not found:  + targetPath</exception>
 public void GetLabeled(string label, string sourcePath, string targetPath)
 {
     var context = new TfsSourceControlContext(this, sourcePath, label);
     this.GetLabeled(context, label, targetPath);
         }
コード例 #11
0
 private void GetLabeled(TfsSourceControlContext context, string label, string targetDirectory)
 {
     this.EnsureLocalWorkspace(context);
     this.UpdateLocalWorkspace(context);
     this.ExportFiles(context, targetDirectory);
 }
コード例 #12
0
        /// <summary>
        /// When implemented in a derived class, retrieves labeled
        /// source code from the provider's source path into the target path.
        /// </summary>
        /// <param name="label">Label of source files to get.</param>
        /// <param name="sourcePath">Provider source path.</param>
        /// <param name="targetPath">Target file path.</param>
        /// <exception cref="ArgumentNullException">
        /// sourcePath
        /// or
        /// targetPath
        /// </exception>
        /// <exception cref="DirectoryNotFoundException">targetPath not found:  + targetPath</exception>
        public void GetLabeled(string label, string sourcePath, string targetPath)
        {
            var context = new TfsSourceControlContext(this, sourcePath, label);

            this.GetLabeled(context, label, targetPath);
        }
コード例 #13
0
 private void GetLabeled(TfsSourceControlContext context, string label, string targetDirectory)
         {
     this.EnsureLocalWorkspace(context);
     this.UpdateLocalWorkspace(context);
     this.ExportFiles(context, targetDirectory);
 }
コード例 #14
0
        private void ApplyLabel(TfsSourceControlContext context, string label)
        {
            using (var tfs = this.GetTeamProjectCollection())
            {
                var versionControlService = tfs.GetService<VersionControlServer>();

                var versionControlLabel = new VersionControlLabel(versionControlService, label, versionControlService.AuthorizedUser, context.SourcePath, "Label applied by BuildMaster");
                versionControlService.CreateLabel(versionControlLabel, new[] { new LabelItemSpec(new ItemSpec(context.SourcePath, RecursionType.Full), VersionSpec.Latest, false) }, LabelChildOption.Replace);
            }
        }
コード例 #15
0
 private DirectoryEntryInfo GetDirectoryEntryInfo(TfsSourceControlContext context)
 {
     using (var tfs = this.GetTeamProjectCollection())
     {
         var sourceControl = tfs.GetService<VersionControlServer>();
         var itemSet = sourceControl.GetItems(context.SourcePath, RecursionType.OneLevel);
             return new DirectoryEntryInfo(
                 context.LastSubDirectoryName,
                 context.SourcePath,
                 itemSet.Items.Where(i => i.ServerItem != context.SourcePath).Select(i => context.CreateSystemEntryInfo(i))
         );
     }
 }
コード例 #16
0
 private void GetLatest(TfsSourceControlContext context, string targetPath)
     {
     this.EnsureLocalWorkspace(context);
     this.UpdateLocalWorkspace(context);
     this.ExportFiles(context, targetPath);
         }
コード例 #17
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;
        }
コード例 #18
0
        private object GetCurrentRevision(TfsSourceControlContext context)
        {
            using (var tfs = this.GetTeamProjectCollection())
            {
                var sourceControl = tfs.GetService<VersionControlServer>();

                string sourcePath = sourceControl.GetItem(context.SourcePath).ServerItem; // matches the sourcePath with the base path returned by TFS

                var itemSet = sourceControl.GetItems(sourcePath, VersionSpec.Latest, RecursionType.Full, DeletedState.Any, ItemType.Any);
                if (itemSet == null || itemSet.Items == null || itemSet.Items.Length == 0)
                    return new byte[0];

                return itemSet.Items.Max(i => i.ChangesetId);
            }
        }