private async Task OnSaveClicked(object arg) { ErrorHeader = "Error(s) occurred during save"; Errors = string.Empty;//clear previous error messages var workItemDetail = WorkItemDetails.FirstOrDefault(x => x.IsChecked); if (workItemDetail != null) { IsLoading = Visibility.Visible; var workItem = workItemDetail.WorkItemCache; await Task.Run(() => { int[] changesetIds = VersionControlExt.History.ActiveWindow.SelectedChangesets.Select(x => x.ChangesetId).ToArray(); foreach (int changesetId in changesetIds) { Changeset changeset = VersionControlServer.GetChangeset(changesetId); try { workItem.Links.Add(new ExternalLink( WorkItemStore.RegisteredLinkTypes[ArtifactLinkIds.Changeset], changeset.ArtifactUri.AbsoluteUri)); var validationErrors = workItem.Validate(); if (validationErrors.Count == 0) { workItem.Save(); } else { foreach (var validationError in validationErrors) { Errors += string.Format("{0}{1}", validationError, Environment.NewLine); } HasErrors = Visibility.Visible; IsLoading = Visibility.Collapsed; } } catch (Exception exception) { //TODO:Logging //To catch duplicate links HasErrors = Visibility.Visible; IsLoading = Visibility.Collapsed; Errors += string.Format("{0}{1}", exception.Message, Environment.NewLine); } } }); if (HasErrors == Visibility.Collapsed) { //no errors CloseWindow(); } IsLoading = Visibility.Collapsed; } }
private void OnOpenWorkItemClicked(object arg) { var workItemDetail = WorkItemDetails.FirstOrDefault(x => x.IsChecked); var workItemDocumentService = DocumentService; if (workItemDetail != null && workItemDocumentService != null) { IsLoading = Visibility.Visible; var workItemDocument = workItemDocumentService.GetWorkItem(TeamFoundationContext.TeamProjectCollection, workItemDetail.Id, this); try { if (!workItemDocument.IsLoaded) { workItemDocument.Load(); } workItemDocumentService.ShowWorkItem(workItemDocument); } catch (Exception exception) { //TODO: Logging } finally { workItemDocument.Release(this); } IsLoading = Visibility.Collapsed; } else { HasErrors = Visibility.Visible; IsLoading = Visibility.Collapsed; ErrorHeader = "Error(s)"; Errors = "Error occurred while opening the work item."; } }