private async Task RemoveConflictingWorkspacesAsync(ITfsVCCommandManager tf, ITfsVCWorkspace[] tfWorkspaces, string name, string directory) { // Validate the args. ArgUtil.NotNullOrEmpty(name, nameof(name)); ArgUtil.NotNullOrEmpty(directory, nameof(directory)); // Fixup the directory. directory = directory.TrimEnd('/', '\\'); ArgUtil.NotNullOrEmpty(directory, nameof(directory)); string directorySlash = $"{directory}{Path.DirectorySeparatorChar}"; foreach (ITfsVCWorkspace tfWorkspace in tfWorkspaces ?? new ITfsVCWorkspace[0]) { // Attempt to match the workspace by name. if (string.Equals(tfWorkspace.Name, name, StringComparison.OrdinalIgnoreCase)) { // Try deleting the workspace from the server. if (!(await tf.TryWorkspaceDeleteAsync(tfWorkspace))) { // Otherwise fallback to deleting the workspace from the local computer. await tf.WorkspacesRemoveAsync(tfWorkspace); } // Continue iterating over the rest of the workspaces. continue; } // Attempt to match the workspace by local path. foreach (ITfsVCMapping tfMapping in tfWorkspace.Mappings ?? new ITfsVCMapping[0]) { // Skip cloaks. if (tfMapping.Cloak) { continue; } if (string.Equals(tfMapping.LocalPath, directory, StringComparison.CurrentCultureIgnoreCase) || (tfMapping.LocalPath ?? string.Empty).StartsWith(directorySlash, StringComparison.CurrentCultureIgnoreCase)) { // Try deleting the workspace from the server. if (!(await tf.TryWorkspaceDeleteAsync(tfWorkspace))) { // Otherwise fallback to deleting the workspace from the local computer. await tf.WorkspacesRemoveAsync(tfWorkspace); } // Break out of this nested for loop only. // Continue iterating over the rest of the workspaces. break; } } } }
private async Task RemoveConflictingWorkspacesAsync(ITfsVCCommandManager tf, ITfsVCWorkspace[] tfWorkspaces, string name, string directory) { // Validate the args. ArgUtil.NotNullOrEmpty(name, nameof(name)); ArgUtil.NotNullOrEmpty(directory, nameof(directory)); // Fixup the directory. directory = directory.TrimEnd('/', '\\'); ArgUtil.NotNullOrEmpty(directory, nameof(directory)); string directorySlash = $"{directory}{Path.DirectorySeparatorChar}"; foreach (ITfsVCWorkspace tfWorkspace in tfWorkspaces ?? new ITfsVCWorkspace[0]) { // Attempt to match the workspace by name. if (string.Equals(tfWorkspace.Name, name, StringComparison.OrdinalIgnoreCase)) { // Try deleting the workspace from the server. if (!(await tf.TryWorkspaceDeleteAsync(tfWorkspace))) { // Otherwise fallback to deleting the workspace from the local computer. await tf.WorkspacesRemoveAsync(tfWorkspace); } // Continue iterating over the rest of the workspaces. continue; } // Attempt to match the workspace by local path. foreach (ITfsVCMapping tfMapping in tfWorkspace.Mappings ?? new ITfsVCMapping[0]) { // Skip cloaks. if (tfMapping.Cloak) { continue; } if (string.Equals(tfMapping.LocalPath, directory, StringComparison.Ordinal) || (tfMapping.LocalPath ?? string.Empty).StartsWith(directorySlash, StringComparison.Ordinal)) { // Try deleting the workspace from the server. if (!(await tf.TryWorkspaceDeleteAsync(tfWorkspace))) { // Otherwise fallback to deleting the workspace from the local computer. await tf.WorkspacesRemoveAsync(tfWorkspace); } // Break out of this nested for loop only. // Continue iterating over the rest of the workspaces. break; } } } }