Exemple #1
0
        /// <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>
        /// 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="RunWorkerCompletedEventArgs"/> that contains the event data</param>
        private void DoImport(object sender, DoWorkEventArgs e)
        {
            SyncServiceTrace.I(Resources.ImportWorkItems);

            if (_workItemSyncService == null || _configService == null)
            {
                SyncServiceTrace.D(Resources.ServicesNotExists);
                throw new Exception(Resources.ServicesNotExists);
            }

            _documentModel.Save();

            _destination.ProcessOperations(_configuration.PreOperations);
            var importWorkItems = (from wim in FoundWorkItems

                                   select wim.Item).ToList();

            SyncServiceTrace.D(Resources.NumberOfFoundWorkItems + FoundWorkItems.Count);

            // display progress dialog
            var progressService = SyncServiceFactory.GetService <IProgressService>();

            progressService.ShowProgress();
            progressService.NewProgress(Resources.GetWorkItems_Title);

            // search for already existing work items in word and ask whether to overide them
            if (!(_source.Open(importWorkItems.Select(x => x.TfsItem.Id).ToArray()) && _destination.Open(null)))
            {
                return;
            }
            if (importWorkItems.Select(x => x.TfsItem.Id).Intersect(_destination.WorkItems.Select(x => x.Id)).Any())
            {
            }
            if (!_testSpecByQuery)
            {
                _workItemSyncService.Refresh(_source, _destination, importWorkItems.Select(x => x.TfsItem), _configuration);
            }

            if (_testSpecByQuery)
            {
                var testAdapter       = SyncServiceFactory.CreateTfsTestAdapter(_documentModel.TfsServer, _documentModel.TfsProject, _documentModel.Configuration);
                var model             = new TestSpecificationReportByQueryModel(_tfsService, _documentModel, testAdapter, _workItems);
                var expandSharedsteps = _configuration.ConfigurationTest.ExpandSharedSteps;
                var testCases         = model.GetTestCasesFromWorkItems(importWorkItems, expandSharedsteps);
                var sharedSteps       = model.GetSharedStepsFromWorkItems(importWorkItems);
                // Get any pre and post operations for the reports
                var preOperations    = _configuration.ConfigurationTest.GetPreOperationsForTestSpecification();
                var postOperations   = _configuration.ConfigurationTest.GetPostOperationsForTestSpecification();
                var testReport       = SyncServiceFactory.CreateWord2007TestReportAdapter(_wordDocument, _configuration);
                var testReportHelper = new TestReportHelper(testAdapter, testReport, _configuration, () => !IsImporting);

                testReportHelper.ProcessOperations(preOperations);
                if (sharedSteps.Count > 0)
                {
                    _workItemSyncService.RefreshAndSubstituteSharedStepItems(_source, _destination, importWorkItems.Select(x => x.TfsItem), _configuration, testReportHelper, sharedSteps);
                }
                if (testCases.Count > 0)
                {
                    _workItemSyncService.RefreshAndSubstituteTestItems(_source, _destination, importWorkItems.Select(x => x.TfsItem), _configuration, testReportHelper, testCases);
                }
                if (_testReportingProgressCancellationService.CheckIfContinue())
                {
                    testReportHelper.CreateSummaryPage(_wordDocument, null);
                    testReportHelper.ProcessOperations(postOperations);
                }
                else
                {
                    SyncServiceTrace.I(Resources.DoImportError);
                }

                _documentModel.TestReportGenerated = true;
            }

            _destination.ProcessOperations(_configuration.PostOperations);
        }