Exemplo n.º 1
0
        /// <summary>
        /// Creates hyperlinks to selected work items at the current cursor position.
        /// </summary>
        public void CreateHyperlink()
        {
            SyncServiceTrace.I(Resources.CreateHyperlinks);

            // set actual selected configuration
            var ignoreFormatting  = DocumentModel.Configuration.IgnoreFormatting;
            var conflictOverwrite = DocumentModel.Configuration.ConflictOverwrite;

            DocumentModel.Configuration.ActivateMapping(DocumentModel.MappingShowName);
            DocumentModel.Configuration.IgnoreFormatting  = ignoreFormatting;
            DocumentModel.Configuration.ConflictOverwrite = conflictOverwrite;
            DocumentModel.Configuration.IgnoreFormatting  = ignoreFormatting;

            var source          = SyncServiceFactory.CreateTfs2008WorkItemSyncAdapter(DocumentModel.TfsServer, DocumentModel.TfsProject, null, DocumentModel.Configuration);
            var destination     = SyncServiceFactory.CreateWord2007TableWorkItemSyncAdapter(WordDocument, DocumentModel.Configuration);
            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()) && destination.Open(null)))
            {
                return;
            }

            foreach (var workItem in importWorkItems)
            {
                destination.CreateWorkItemHyperlink(workItem.TfsItem.Title, source.GetWorkItemEditorUrl(workItem.TfsItem.Id));
            }
        }
        /// <summary>
        /// Background method to find the work items from TFS.
        /// </summary>
        private void DoFind()
        {
            SyncServiceTrace.D(Resources.DoFindProccessMessage);
            DocumentModel.SaveQueryConfiguration(_queryConfiguration);

            //var config = SyncServiceFactory.GetService<IConfigurationService>().GetConfiguration(WordDocument);
            var config      = DocumentModel.Configuration;
            var tfsService  = SyncServiceFactory.CreateTfs2008WorkItemSyncAdapter(DocumentModel.TfsServer, DocumentModel.TfsProject, _queryConfiguration, config);
            var wordAdapter = SyncServiceFactory.CreateWord2007TableWorkItemSyncAdapter(DocumentModel.WordDocument, DocumentModel.Configuration);

            wordAdapter.Open(null);
            tfsService.Open(null);

            EnsureTfsLazyLoadingFinished(tfsService);

            // Cancel all queries in case there are still some running
            Cancel();
            _cancellationTokenSource = new CancellationTokenSource();
            var token = _cancellationTokenSource.Token;

            var tfsItems = (from wi in tfsService.WorkItems
                            select new DataItemModel <SynchronizedWorkItemViewModel>(new SynchronizedWorkItemViewModel(wi, null, wordAdapter, DocumentModel, token))
            {
                IsChecked = true
            }).ToList();

            var wordItems = (from wi in wordAdapter.WorkItems
                             where wi.IsNew
                             select new DataItemModel <SynchronizedWorkItemViewModel>(new SynchronizedWorkItemViewModel(null, wi, wordAdapter, DocumentModel, token))
            {
                IsChecked = true
            }).ToList();

            FoundWorkItems = tfsItems.Concat(wordItems).ToList();
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        /// <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);
        }
        /// <summary>
        /// Execute find work items process to fill up the Find list box.
        /// </summary>
        public void FindWorkItems()
        {
            SaveQueryConfiguration();
            SyncServiceTrace.I(Resources.FindWorkItems);

            if (SelectedQuery == null)
            {
                QueryConfiguration.ImportOption = QueryImportOption.IDs;

                var wordAdapter = SyncServiceFactory.CreateWord2007TableWorkItemSyncAdapter(DocumentModel.WordDocument, DocumentModel.Configuration);
                wordAdapter.Open(null);

                QueryConfiguration.ByIDs.Clear();

                foreach (var workItem in wordAdapter.WorkItems)
                {
                    if (!workItem.IsNew)
                    {
                        QueryConfiguration.ByIDs.Add(workItem.Id);
                    }
                }
            }

            // check whether is at least one link type selected
            if (QueryConfiguration.UseLinkedWorkItems && IsCustomLinkType && QueryConfiguration.LinkTypes.Count == 0)
            {
                MessageBox.Show(Resources.WordToTFS_Error_LinkTypesNotSelected, Resources.MessageBox_Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                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.QueryWorkItems_Title);
            IsFinding = true;

            Task.Factory.StartNew(DoFind).ContinueWith(FindFinished, TaskScheduler.FromCurrentSynchronizationContext());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Background method to find the work items from TFS.
        /// </summary>
        private void DoFind()
        {
            SyncServiceTrace.D(Resources.FindWorkItems);
            //var config = SyncServiceFactory.GetService<IConfigurationService>().GetConfiguration(WordDocument);
            var config      = DocumentModel.Configuration;
            var tfsService  = SyncServiceFactory.CreateTfs2008WorkItemSyncAdapter(DocumentModel.TfsServer, DocumentModel.TfsProject, _queryConfiguration, config);
            var wordAdapter = SyncServiceFactory.CreateWord2007TableWorkItemSyncAdapter(DocumentModel.WordDocument, DocumentModel.Configuration);

            wordAdapter.Open(null);
            tfsService.Open(null);

            EnsureTfsLazyLoadingFinished(tfsService);

            _cancellationTokenSource.Cancel();
            _cancellationTokenSource = new CancellationTokenSource();
            var token = _cancellationTokenSource.Token;

            FoundWorkItems = (from wi in tfsService.WorkItems
                              select new DataItemModel <SynchronizedWorkItemViewModel>(new SynchronizedWorkItemViewModel(wi, null, wordAdapter, DocumentModel, token))
            {
                IsChecked = true
            }).ToList();
            var foundIds = string.Join(",", FoundWorkItems.Select(w => w.Item.Id.ToString(CultureInfo.InvariantCulture)));

            SyncServiceTrace.I("Found work items: {0}", string.Equals(string.Empty, foundIds) ? "<none>" : foundIds);

            var colors = tfsService.WorkItemColors;

            foreach (var foundItem in FoundWorkItems)
            {
                foundItem.Item.CanShowColor = false;
                if (colors != null && colors.ContainsKey(foundItem.Item.TfsItem.WorkItemType))
                {
                    foundItem.Item.WorkItemColor = $"#{colors[foundItem.Item.TfsItem.WorkItemType].PrimaryColor}";
                    foundItem.Item.CanShowColor  = true;
                }
            }

            var allWorkItems              = tfsService.AvailableWorkItemsFromTFS;
            var idsOfFilteredWorkItems    = FoundWorkItems.Select(w => w.Item.Id);
            var amountOfFilteredWorkItems = FoundWorkItems.Count();

            ShowResultsOfComparison(allWorkItems, tfsService.WorkItems.Count(), idsOfFilteredWorkItems);
        }
        /// <summary>
        /// Background method to find the work items from TFS.
        /// </summary>
        private void DoFind()
        {
            SyncServiceTrace.D(Resources.FindWorkItems);
            //var config = SyncServiceFactory.GetService<IConfigurationService>().GetConfiguration(WordDocument);
            var config      = DocumentModel.Configuration;
            var tfsService  = SyncServiceFactory.CreateTfs2008WorkItemSyncAdapter(DocumentModel.TfsServer, DocumentModel.TfsProject, _queryConfiguration, config);
            var wordAdapter = SyncServiceFactory.CreateWord2007TableWorkItemSyncAdapter(DocumentModel.WordDocument, DocumentModel.Configuration);

            wordAdapter.Open(null);
            tfsService.Open(null);

            EnsureTfsLazyLoadingFinished(tfsService);

            _cancellationTokenSource.Cancel();
            _cancellationTokenSource = new CancellationTokenSource();
            var token = _cancellationTokenSource.Token;

            FoundWorkItems = (from wi in tfsService.WorkItems
                              select new DataItemModel <SynchronizedWorkItemViewModel>(new SynchronizedWorkItemViewModel(wi, null, wordAdapter, DocumentModel, token))
            {
                IsChecked = true
            }).ToList();
        }
        /// <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>
        public 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);

            _importTestReport = SyncServiceFactory.CreateWord2007TestReportAdapter(WordDocument, configuration);

            var ignoreFormatting  = configuration.IgnoreFormatting;
            var conflictOverwrite = configuration.ConflictOverwrite;

            configuration.ActivateMapping(DocumentModel.MappingShowName);
            DocumentModel.Configuration.IgnoreFormatting = ignoreFormatting;
            configuration.ConflictOverwrite = conflictOverwrite;
            configuration.IgnoreFormatting  = ignoreFormatting;

            var source          = SyncServiceFactory.CreateTfs2008WorkItemSyncAdapter(DocumentModel.TfsServer, DocumentModel.TfsProject, null, configuration);
            var destination     = SyncServiceFactory.CreateWord2007TableWorkItemSyncAdapter(WordDocument, configuration);
            var importWorkItems = (from wim in FoundWorkItems
                                   where wim.IsChecked
                                   select wim.Item).ToList();

            if (!(source.Open(importWorkItems.Select(x => x.TfsItem.Id).ToArray()) && destination.Open(null)))
            {
                return;
            }

            // Check for test cases.
            var expandSharedsteps = configuration.ConfigurationTest.ExpandSharedSteps;
            var testCases         = GetTestCasesFromWorkItems(importWorkItems, expandSharedsteps);

            // Check for shared steps
            var sharedSteps = GetSharedStepsFromWorkItems(importWorkItems);

            //Get any pre and post operations for the reports
            var preOperations  = configuration.ConfigurationTest.GetPreOperationsForTestSpecification();
            var postOperations = configuration.ConfigurationTest.GetPostOperationsForTestSpecification();

            var testReportHelper = new TestReportHelper(_testAdapter, _importTestReport, configuration, () => !IsImporting);

            _importTestReport.PrepareDocumentForLongTermOperation();
            testReportHelper.ProcessOperations(preOperations);

            if (testCases.Count > 0 && sharedSteps.Count > 0)
            {
                throw new ConfigurationException("Function can only be used for either shared steps or test cases. Select only work items of one Type.");
            }
            if (testCases.Count > 0)
            {
                workItemSyncService.RefreshAndSubstituteTestItems(source, destination, importWorkItems.Select(x => x.TfsItem), configuration, testReportHelper, testCases);
            }
            if (sharedSteps.Count > 0)
            {
                workItemSyncService.RefreshAndSubstituteSharedStepItems(source, destination, importWorkItems.Select(x => x.TfsItem), configuration, testReportHelper, sharedSteps);
            }
            // when cancelled by the user skip further steps
            var progressService = SyncServiceFactory.GetService <IProgressService>();

            if (null != progressService && !progressService.ProgressCanceled)
            {
                testReportHelper.CreateSummaryPage(WordDocument, null);
                testReportHelper.ProcessOperations(postOperations);
            }
            else
            {
                SyncServiceTrace.I("Skipped");
            }

            DocumentModel.TestReportGenerated = true;
        }