protected override void ProcessRecordInEH() { if (ParameterSetName != "QueryByWIQL" && (WorkItem == null || WorkItem.Count == 0)) { throw new PSArgumentException("No filter has been specified. Please specify at least 1 filter for removing the work items."); } WorkItemStore workItemStore = EnsureWorkItemStore(); List <WorkItem> deletingWorkItems = QueryWorkItems(workItemStore).ToList(); List <int> idOfDeletingWorkItems = deletingWorkItems.Select(x => x.Id).ToList(); WriteVerbose(string.Format("Removing workitems with id: {0}.", string.Join(", ", idOfDeletingWorkItems))); ICollection <WorkItemOperationError> errors = workItemStore.DestroyWorkItems(idOfDeletingWorkItems); var errorMap = errors.ToDictionary(x => x.Id, x => x); List <RemoveTfsWorkItemResult> results = deletingWorkItems.Select((x) => { WorkItemOperationError error = null; errorMap.TryGetValue(x.Id, out error); return(new RemoveTfsWorkItemResult() { WorkItem = x, Error = error }); }).ToList(); foreach (var result in results) { WriteObject(result); } }
public int DestroyWorkItems(string workItemType) { TfsTeamProjectCollection tpc = TfsConnect(); // Get work items WorkItemStore store = new WorkItemStore(tpc); Project project = store.Projects[TeamProject]; string wiql = "SELECT [System.Id] FROM WorkItems " + "WHERE [System.TeamProject] = '" + TeamProject + "'"; if (workItemType != "" && workItemType != "*") { wiql = "SELECT [System.Id] FROM WorkItems " + "WHERE [System.TeamProject] = '" + TeamProject + "' AND [System.WorkItemType] = '" + workItemType + "'"; } WorkItemCollection collection = store.Query(wiql); // Get list of work items to destroy ArrayList destroyIds = new ArrayList(); for (int i = 0; i < collection.Count; i++) { WorkItem wi = collection[i]; destroyIds.Add(wi.Id); Console.Write("."); } if (destroyIds.Count < 1) { return(0); } // Convert to int array int[] ids = new int[destroyIds.Count]; for (int i = 0; i < destroyIds.Count; i++) { ids[i] = Convert.ToInt32(destroyIds[i]); } // Destroy work items IEnumerable <WorkItemOperationError> errors = store.DestroyWorkItems(ids); List <WorkItemOperationError> errorList = new List <WorkItemOperationError>(errors); if (errorList.Count > 0) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < errorList.Count; i++) { builder.AppendLine(string.Format("> Error destroying work item {0}, {1}", errorList[i].Id, errorList[i].Exception.Message)); } Console.WriteLine(builder.ToString()); } return(destroyIds.Count); }
private static void DeleteWorkItemInternal(IEnumerable <int> workItems) { using (var tfsProjectCollection = GetProjectCollection()) { tfsProjectCollection.Authenticate(); var workItemStore = new WorkItemStore(tfsProjectCollection); workItemStore.DestroyWorkItems(workItems); } }
//Delete all workitems in project public void DeleteWorkItems() { WorkItemCollection workItemCollection = GetWorkItemCollection(); List <int> toDeletes = new List <int>(); foreach (WorkItem workItem in workItemCollection) { System.Diagnostics.Debug.WriteLine(workItem.Id); toDeletes.Add(workItem.Id); } var errors = store.DestroyWorkItems(toDeletes); foreach (var error in errors) { System.Diagnostics.Debug.WriteLine(error.Exception.Message); } }
public static void DeleteWorkItems(string uri, List <int> ids) { try { TfsTeamProjectCollection tfs; tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(uri)); // https://mytfs.visualstudio.com/DefaultCollection tfs.Authenticate(); var workItemStore = new WorkItemStore(tfs); workItemStore.DestroyWorkItems(ids); } catch (Exception ex) { Console.WriteLine("Error while deleting workitems " + ex.Message); } }
private void btnDelete_Click(object sender, EventArgs e) { _deleting = true; var bulkDeleteDialogResult = DialogResult.Cancel; var singleDeleteDialogResult = DialogResult.Cancel; if (Settings.EnabledConfirmationForBulkDelete) { bulkDeleteDialogResult = MessageBox.Show("Are You Sure You Want to Delete (" + dgvWorkItemsQueryResult.SelectedRows.Count + ") Work-items", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); } if ((Settings.EnabledConfirmationForBulkDelete && bulkDeleteDialogResult == DialogResult.OK) || (!Settings.EnabledConfirmationForBulkDelete)) { foreach (DataGridViewRow selectedRow in dgvWorkItemsQueryResult.SelectedRows) { if (Settings.EnabledConfirmationForSinglekDelete) { singleDeleteDialogResult = MessageBox.Show("Are You Sure You Want to Delete The following Work-item:" + Environment.NewLine + "ID: " + selectedRow.Cells[3].FormattedValue + Environment.NewLine + "Type: " + selectedRow.Cells[4].FormattedValue + Environment.NewLine + "Title: " + selectedRow.Cells[5].FormattedValue, "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); } if ((Settings.EnabledConfirmationForSinglekDelete && singleDeleteDialogResult == DialogResult.OK) || (!Settings.EnabledConfirmationForSinglekDelete)) { //_workItemStore.DestroyWorkItems() if (_cancelDelete) { return; } try { //MessageBox.Show(selectedRow.Cells[3].FormattedValue.ToString()); _workItemStore.DestroyWorkItems(new List <int> { int.Parse(selectedRow.Cells[3].FormattedValue.ToString()) }).ToList(); rtxtLog.AppendText("Deleteing The following Work-item:" + Environment.NewLine + "ID: " + selectedRow.Cells[3].FormattedValue + Environment.NewLine + "Type: " + selectedRow.Cells[4].FormattedValue + Environment.NewLine + "Title: " + selectedRow.Cells[5].FormattedValue, Color.DarkOrange); rtxtLog.AppendText(Environment.NewLine); } catch (Exception exception) { rtxtLog.AppendTextWithNewLine(Utilities.ReadException(exception), Color.Red); } } } } _deleting = false; _cancelDelete = false; }
/// <summary> /// Delete a list of items /// </summary> /// <param name="ids">List of ID's to be deleted</param> /// <returns></returns> public List <WorkItemOperationError> DeleteWorkItems(int[] ids) { return(new List <WorkItemOperationError>(wiStore.DestroyWorkItems(ids))); }
public void ClearWorkItems() { var workItems = _workItemStore.Query("SELECT * FROM workitems").Cast <WorkItem>().Select(x => x.Id).ToList(); var errors = _workItemStore.DestroyWorkItems(workItems).Cast <WorkItemOperationError>().ToList(); }