/// <summary> /// Adds a single link to another work item /// </summary> /// <param name="adapter">Adapter used to look up more information about the referenced work items.</param> /// <param name="id">The id of the other work item.</param> /// <param name="link">Link type.</param> private void AddLink(IWorkItemSyncAdapter adapter, int id, IConfigurationLinkItem link) { var range = GetLinkRange(link); if (range == null) { return; } range.Collapse(WdCollapseDirection.wdCollapseEnd); var bookmarks = Table.Range.Document.Bookmarks; var workItem = adapter.WorkItems.Find(id); // if we can look up the work item, format the output. Otherwise only display the work item id var linkTitle = workItem == null?id.ToString(CultureInfo.InvariantCulture) : link.Format(workItem); // insert hyper link to target work item bookmark range.Text = linkTitle; if (bookmarks.Exists(id)) { range.Hyperlinks.Add(range, SubAddress: bookmarks.Item(id)); range.SetRange(range.End + 1, range.End + 1); } range.Collapse(WdCollapseDirection.wdCollapseEnd); }
private void RemoveExistingLinksOfGivenLinkTypeFromWorkItem(IConfigurationLinkItem linkConfiguration, IWorkItem workItem) { workItem.AddLinks( _adapter, new int[] { }, linkConfiguration.LinkValueType, true); InvalidateTestIfNotEqual(0, GetIdsOfLinksOfGivenLinkTypeFromWorkItem(linkConfiguration, workItem).Length, "workItem.AddLinks() did not deleted all links successfully."); }
/// <summary> /// Wraps cached access to the ranges of link fields. /// </summary> private Range GetLinkRange(IConfigurationLinkItem linkConfiguration) { if (_linkRangeCache.ContainsKey(linkConfiguration) == false) { var range = WordSyncHelper.GetCellRange(Table, linkConfiguration.RowIndex, linkConfiguration.ColIndex); _linkRangeCache.Add(linkConfiguration, range); } return(_linkRangeCache[linkConfiguration]); }
private int[] GetIdsOfLinksOfGivenLinkTypeFromWorkItem(IConfigurationLinkItem linkConfiguration, IWorkItem workItem) { return(workItem.Links.First(x => x.Key.LinkValueType == linkConfiguration.LinkValueType).Value); }