/// <summary> /// Background method to import the work items from TFS. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="DoWorkEventArgs"/> that contains the event data.</param> private void DoImport(object sender, DoWorkEventArgs e) { SyncServiceTrace.I(Resources.ImportWorkItems); var workItemSyncService = SyncServiceFactory.GetService <IWorkItemSyncService>(); var configService = SyncServiceFactory.GetService <IConfigurationService>(); // save query configuration to document DocumentModel.SaveQueryConfiguration(_queryConfiguration); DocumentModel.Save(); // set actual selected configuration var configuration = configService.GetConfiguration(WordDocument); var ignoreFormatting = configuration.IgnoreFormatting; var conflictOverwrite = configuration.ConflictOverwrite; configuration.ActivateMapping(DocumentModel.MappingShowName); DocumentModel.Configuration.IgnoreFormatting = ignoreFormatting; configuration.ConflictOverwrite = conflictOverwrite; configuration.IgnoreFormatting = ignoreFormatting; var config = SyncServiceFactory.GetService <IConfigurationService>().GetConfiguration(WordDocument); var source = SyncServiceFactory.CreateTfs2008WorkItemSyncAdapter(DocumentModel.TfsServer, DocumentModel.TfsProject, null, config); _importWordAdapter = SyncServiceFactory.CreateWord2007TableWorkItemSyncAdapter(WordDocument, configuration); _importWordAdapter.PrepareDocumentForLongTermOperation(); ////////// _importWordAdapter.ProcessOperations(configuration.PreOperations); var importWorkItems = (from wim in FoundWorkItems where wim.IsChecked select wim.Item).ToList(); // search for already existing work items in word and ask whether to overide them if (!(source.Open(importWorkItems.Select(x => x.TfsItem.Id).ToArray()) && _importWordAdapter.Open(null))) { return; } if (importWorkItems.Select(x => x.TfsItem.Id).Intersect(_importWordAdapter.WorkItems.Select(x => x.Id)).Any()) { SyncServiceTrace.W(Resources.TFSExport_ExistingWorkItems); if ( System.Windows.Forms.MessageBox.Show((IWin32Window)WordRibbon, Resources.TFSExport_ExistingWorkItems, Resources.MessageBox_Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0) == DialogResult.No) { return; } } workItemSyncService.Refresh(source, _importWordAdapter, importWorkItems.Select(x => x.TfsItem), configuration); _importWordAdapter.ProcessOperations(configuration.PostOperations); }
/// <summary> /// Get the necessary services /// </summary> private void GetService() { _workItemSyncService = SyncServiceFactory.GetService <IWorkItemSyncService>(); _configService = SyncServiceFactory.GetService <IConfigurationService>(); _configuration = _configService.GetConfiguration(_wordDocument); _tfsService = SyncServiceFactory.CreateTfsService(_documentModel.TfsServer, _documentModel.TfsProject, _documentModel.Configuration); _source = SyncServiceFactory.CreateTfs2008WorkItemSyncAdapter(_documentModel.TfsServer, _documentModel.TfsProject, null, _configuration); _destination = SyncServiceFactory.CreateWord2007TableWorkItemSyncAdapter(_wordDocument, _configuration); }