/// <summary> /// Execute import work items from TFS to Word process. /// </summary> public void Import() { SyncServiceTrace.I(Resources.ImportWorkItems); SyncServiceFactory.GetService <IInfoStorageService>().ClearAll(); // check whether cursor is not inside the table if (WordSyncHelper.IsCursorInTable(WordDocument.ActiveWindow.Selection)) { SyncServiceTrace.W(Resources.WordToTFS_Error_TableInsertInTable); MessageBox.Show(Resources.WordToTFS_Error_TableInsertInTable, Resources.MessageBox_Title, MessageBoxButton.OK, MessageBoxImage.Error); return; } // disable all other functionality if (WordRibbon != null) { WordRibbon.ResetBeforeOperation(DocumentModel); WordRibbon.DisableAllControls(DocumentModel); } // display progress dialog var progressService = SyncServiceFactory.GetService <IProgressService>(); progressService.ShowProgress(); progressService.NewProgress(Resources.GetWorkItems_Title); IsImporting = true; // start background thread to execute the import var backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += DoImport; backgroundWorker.RunWorkerCompleted += ImportFinished; backgroundWorker.RunWorkerAsync(backgroundWorker); }
/// <summary> /// Initializes a new instance of the <see cref="WordTableWorkItem"/> class. /// </summary> /// <param name="table">Table to wrap.</param> /// <param name="workItemType">Work item to wrap.</param> /// <param name="configuration">Configuration of all work items</param> /// <param name="configurationItem">The configuration of this work item</param> /// <exception cref="ConfigurationException">Thrown if the configuration contains invalid cell column or row for standard fields.</exception> internal WordTableWorkItem(Table table, string workItemType, IConfiguration configuration, IConfigurationItem configurationItem) { if (table == null) { throw new ArgumentNullException("table"); } if (workItemType == null) { throw new ArgumentNullException("workItemType"); } if (configurationItem == null) { throw new ArgumentNullException("configurationItem"); } Table = table; TableStart = table.Range.Start; WorkItemType = workItemType; _configuration = configuration; _configurationItem = configurationItem.Clone(); // Create fields IList <IField> fields = new List <IField>(); foreach (var fieldItem in _configurationItem.FieldConfigurations) { if (fieldItem.IsMapped) { var cellRange = WordSyncHelper.GetCellRange(Table, fieldItem.RowIndex, fieldItem.ColIndex); if (fieldItem.FieldValueType == FieldValueType.BasedOnVariable || fieldItem.FieldValueType == FieldValueType.BasedOnSystemVariable) { fields.Add(new StaticValueField(cellRange, fieldItem, true)); } else { fields.Add(new WordTableField(cellRange, fieldItem, _configurationItem.GetConverter(fieldItem.ReferenceFieldName), true)); } } else { // Initialize unmapped fields with default values var hiddenField = new HiddenField(fieldItem, _configurationItem.GetConverter(fieldItem.ReferenceFieldName)); if (fieldItem.DefaultValue != null) { hiddenField.Value = fieldItem.DefaultValue.DefaultValue; } fields.Add(hiddenField); } } Fields = new WordTableFieldCollection(fields); IsNew = Id <= 0; }
/// <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]); }
/// <summary> /// The method creates work items dependent on this work item /// </summary> /// <returns>Collection of dependent work items.</returns> /// <exception cref="ConfigurationException">Thrown if the configuration contains invalid cell column or row for FieldToLinkedItemConfiguration.</exception> public IWorkItemCollection CreateLinkedWorkItems() { var retValue = new WordTableWorkItemCollection(); LinkedWorkItems = new Dictionary <string, IWorkItemCollection>(); // Get the associated configuration if (!_configurationItem.ConfigurationSupportsLinkedItem) { return(retValue); } if (_configurationItem.FieldToLinkedItemConfiguration == null) { return(retValue); } if (_configurationItem.FieldToLinkedItemConfiguration.Count == 0) { return(retValue); } foreach (var configurationLinkedItem in _configurationItem.FieldToLinkedItemConfiguration) { // Get the cell of the table, where the linked work items are defined. var cellRange = WordSyncHelper.GetCellRange(Table, configurationLinkedItem.RowIndex, configurationLinkedItem.ColIndex); if (cellRange == null) { continue; } // At this moment only 'NumberedList' supported if (configurationLinkedItem.WorkItemBindType != WorkItemBindType.NumberedList) { continue; } var numberedListItems = new List <Range>(); foreach (Paragraph paragraph in cellRange.Paragraphs) { if (paragraph.Range.ListFormat != null && paragraph.Range.ListFormat.ListLevelNumber == 1 && paragraph.Range.ListFormat.ListValue > 0) { // We need to store only ranges of 'valid' list items // Valid list item is for us item with level 1 and value bigger as 0 numberedListItems.Add(paragraph.Range); } } for (int index = 0; index < numberedListItems.Count; index++) { var title = numberedListItems[index]; int end = cellRange.End - 1; // -1 to cut the last charactar in the cell - \v if (index + 1 < numberedListItems.Count) { end = numberedListItems[index + 1].Start; } var description = title.Document.Range(title.End, end); var newWorkItem = new WordNumberedListItemWorkItem(configurationLinkedItem, title, description, _configuration); retValue.Add(newWorkItem); if (!LinkedWorkItems.ContainsKey(configurationLinkedItem.LinkType.ToString())) { LinkedWorkItems[configurationLinkedItem.LinkType.ToString()] = new WordTableWorkItemCollection(); } LinkedWorkItems[configurationLinkedItem.LinkType.ToString()].Add(newWorkItem); } } return(retValue); }