Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Verifies the template mapping.
        /// </summary>
        /// <param name="wordWorkItems">The work items that are published</param>
        /// <param name="destinationSyncAdapter">The sync adapter.</param>
        /// <param name="configuration">Configuration with the field to check for existence on the server</param>
        public bool VerifyTemplateMapping(IEnumerable <IWorkItem> wordWorkItems, IWorkItemSyncAdapter destinationSyncAdapter, IConfiguration configuration)
        {
            Guard.ThrowOnArgumentNull(wordWorkItems, "workItems");
            Guard.ThrowOnArgumentNull(destinationSyncAdapter, "destinationSyncAdapter");
            Guard.ThrowOnArgumentNull(configuration, "configuration");

            _wrongMappedFieldsDictionary.Clear();

            //Get the service
            var tfsService = destinationSyncAdapter as ITfsService;

            if (tfsService != null)
            {
                //Loop through all itenms
                foreach (WordTableWorkItem singleWorkItem in wordWorkItems)
                {
                    foreach (IField fieldItem in singleWorkItem.Fields)
                    {
                        if (fieldItem is WordTableField)
                        {
                            //Check if the field exists
                            var fieldExists = tfsService.FieldDefinitions.Cast <FieldDefinition>().Any(field => fieldItem.Configuration.ReferenceFieldName.Equals(field.ReferenceName));
                            if (fieldExists)
                            {
                                //If the field on Word is handeled as HTML, check the counterpart on the tfs
                                if (fieldItem.Configuration.FieldValueType == (FieldValueType.HTML))
                                {
                                    //Get the TFS Item and check if it is HTML
                                    var tfsFieldItem = tfsService.FieldDefinitions[fieldItem.Configuration.ReferenceFieldName];
                                    if (tfsFieldItem.FieldType != FieldType.Html)
                                    {
                                        //Add it to the list with files, this list is later used to set the flags, depending on the users decision
                                        List <WordTableField> fieldList;
                                        if (_wrongMappedFieldsDictionary.TryGetValue(singleWorkItem, out fieldList))
                                        {
                                            ((WordTableField)fieldItem).ParseHtmlAsPlaintext = true;
                                            fieldList.Add((WordTableField)fieldItem);
                                        }
                                        else
                                        {
                                            fieldList = new List <WordTableField>();
                                            ((WordTableField)fieldItem).ParseHtmlAsPlaintext = true;
                                            fieldList.Add((WordTableField)fieldItem);
                                            _wrongMappedFieldsDictionary.Add(singleWorkItem, fieldList);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // return true if there were no missing fields or no wrong mapped field, else false.
            return(_wrongMappedFieldsDictionary.Count != 0);
        }
Exemplo n.º 3
0
 private static void EnsureTfsLazyLoadingFinished(IWorkItemSyncAdapter tfsService)
 {
     if (tfsService.WorkItems.Any())
     {
         foreach (var field in tfsService.WorkItems.First().Fields)
         {
             // ReSharper disable once UnusedVariable
             var x = field.Value;
         }
     }
 }
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);
        }
        public void SynchronizedWorkItemViewModel_SynchronizationState_ShouldBeNew()
        {
            var config = CommonConfiguration.GetSimpleFieldConfiguration("Requirement", Direction.OtherToTfs, FieldValueType.PlainText, "System.Title");

            OpenAdapters(CommonConfiguration.TfsTestServerConfiguration(_testContext), config);
            _wordAdapter.CreateNewWorkItem(config.GetConfigurationItems().First());
            _wordAdapter.WorkItems.First().Fields["System.Title"].Value = "Was anderes";
            _wordAdapter = new Word2007TableSyncAdapter(_document, config);
            _wordAdapter.Open(null);

            _synchronizedWorkItemViewModel = new SynchronizedWorkItemViewModel(null, _wordAdapter.WorkItems.First(), _wordAdapter, _documentModel.Object, null);
            _synchronizedWorkItemViewModel.Refresh();
            Assert.AreEqual(SynchronizationState.New, _synchronizedWorkItemViewModel.SynchronizationState);
        }
        private void OpenAdapters(ServerConfiguration serverConfig, IConfiguration configuration)
        {
            _tfsAdapter = new Tfs2012SyncAdapter(serverConfig.TeamProjectCollectionUrl, serverConfig.TeamProjectName, null, configuration);
            _tfsAdapter.Open(new[]
            {
                serverConfig.SynchronizedWorkItemId
            });

            _documentModel = new Mock <ISyncServiceDocumentModel>();
            _documentModel.SetupGet(x => x.Configuration).Returns(configuration);
            _documentModel.SetupGet(x => x.TfsProject).Returns(serverConfig.TeamProjectName);
            _documentModel.SetupGet(x => x.TfsServer).Returns(serverConfig.TeamProjectCollectionUrl);

            _wordAdapter = new Word2007TableSyncAdapter(_document, configuration);
            _wordAdapter.Open(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds multiple links to other work items to this work item.
        /// </summary>
        /// <param name="adapter">Adapter used to look up more information about the referenced work items.</param>
        /// <param name="ids">The ids of the other work items.</param>
        /// <param name="linkType">The reference name of the link type.</param>
        /// <param name="linkedWorkItemTypes">Determines a number of Work Item Types that can be used to filter the links in addition to the linkValueType.</param>
        /// <param name="overwrite">Sets whether the passed links replace all existing links of the given type.</param>
        /// <returns>True if the link was successfully added, false otherwise.</returns>
        public bool AddLinks(IWorkItemSyncAdapter adapter, int[] ids, string linkType, string linkedWorkItemTypes, bool overwrite)
        {
            WorkItemLinkTypeEnd linkTypeEnd;

            if (!WorkItemStore.WorkItemLinkTypes.LinkTypeEnds.TryGetByName(linkType, out linkTypeEnd))
            {
                return(false);
            }

            // only add links to work items that are defined in the LinkedWorkItemTypes-attribute of the link
            if (!string.IsNullOrEmpty(linkedWorkItemTypes))
            {
                // split by comma
                // after that trim each element of the string array that results from the plit operation before
                //if(linkedWorkItemTypes.Contains)
                var linkedWorkItemTypesList = linkedWorkItemTypes.Split(',').Select(s => s.Trim()).ToList();

                foreach (var id in ids)
                {
                    var type = WorkItemStore.GetWorkItem(id).Type.Name;
                    if (!linkedWorkItemTypesList.Contains(type))
                    {
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.LinkWarning_WorkItemTypeViolation, id, type));
                    }
                }
                ids = ids.Where(id => linkedWorkItemTypesList.Contains(WorkItemStore.GetWorkItem(id).Type.Name)).ToArray();
            }

            if (ids == null)
            {
                return(false);
            }

            // Remove all links of specified type
            if (overwrite)
            {
                var lcdelete =
                    WorkItem.Links.OfType <RelatedLink>().Where(link => link.LinkTypeEnd.Id == linkTypeEnd.Id).ToList();

                foreach (var rl in lcdelete)
                {
                    WorkItem.Links.Remove(rl);
                }
            }

            return(this.AddLinks(ids, linkTypeEnd));
        }
        /// <summary>
        /// Creates a new instance of this class.
        /// </summary>
        /// <param name="tfsWorkItem">The TFS version of this work item.</param>
        /// <param name="wordWorkItem">The Word version of this work item.</param>
        /// <param name="wordAdapter">The Word adapter from which to load.</param>
        /// <param name="documentModel">The model of the current document for which to monitor sync state.</param>
        /// <param name="cancellationToken">Token used to cancel synchronization state query.</param>
        public SynchronizedWorkItemViewModel(IWorkItem tfsWorkItem, IWorkItem wordWorkItem, IWorkItemSyncAdapter wordAdapter, ISyncServiceDocumentModel documentModel, CancellationToken?cancellationToken)
        {
            if (cancellationToken.HasValue)
            {
                _cancellationToken = cancellationToken.Value;
            }

            _wordAdapter   = wordAdapter;
            _documentModel = documentModel;

            TfsItem  = tfsWorkItem;
            WordItem = wordWorkItem;

            SynchronizationState = SynchronizationState.Unknown;

            Task.Factory.StartNew(Load, _cancellationToken).ContinueWith(CheckIfCancelled);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Adds multiple links to another work items to this work item.
        /// </summary>
        /// <param name="adapter">Adapter used to look up more information about the referenced work items.</param>
        /// <param name="ids">The ids of the other work items.</param>
        /// <param name="linkType">The reference name of the link type.</param>
        /// <param name="linkedWorkItemTypes">Determines a comma separated list of Work Item Types that can be used to filter the links in addition to the linkValueType.</param>
        /// <param name="overwrite">Not used. Always overwrites cell content</param>
        /// <returns>True when the link was fully added, false otherwise.</returns>
        /// <exception cref="ConfigurationException">Thrown if the configuration contains invalid cell column or row for link configuration.</exception>
        public bool AddLinks(IWorkItemSyncAdapter adapter, int[] ids, string linkType, string linkedWorkItemTypes, bool overwrite)
        {
            if (_configurationItem == null)
            {
                return(false);
            }

            var link = string.IsNullOrEmpty(linkedWorkItemTypes)
                ? _configurationItem.Links.FirstOrDefault(x => x.LinkValueType.Equals(linkType))
                : _configurationItem.Links.FirstOrDefault(x => x.LinkValueType.Equals(linkType) && string.Equals(x.LinkedWorkItemTypes, linkedWorkItemTypes));

            if (link == null)
            {
                return(false);
            }

            var range = GetLinkRange(link);

            if (range == null)
            {
                return(false);
            }

            range.Delete();
            var rangeStart = range.Start;

            // Add links, delete contents of cell before the first item.
            if (ids != null)
            {
                var firstPass = true;
                foreach (var id in ids)
                {
                    if (firstPass == false)
                    {
                        range.InsertAfter(link.LinkSeparator);
                    }

                    firstPass = false;
                    AddLink(adapter, id, link);
                }
            }

            range.Start = rangeStart;
            return(true);
        }
        public void SynchronizedWorkItemViewModel_SynchronizationState_ShouldBeDivergedWithConflicts()
        {
            var config = CommonConfiguration.GetSimpleFieldConfiguration("Requirement", Direction.OtherToTfs, FieldValueType.PlainText, "System.Title");

            config.GetConfigurationItems().First().FieldConfigurations.Add(new ConfigurationFieldItem("System.AreaPath", "", FieldValueType.PlainText, Direction.OtherToTfs, 5, 1, "", false, HandleAsDocumentType.OleOnDemand, null, null, null, ShapeOnlyWorkaroundMode.AddSpace, null, null, null));

            OpenAdapters(CommonConfiguration.TfsTestServerConfiguration(_testContext), config);
            var tfsItem   = _tfsAdapter.WorkItems.First();
            var oldFields = tfsItem.GetWorkItemByRevision(tfsItem.Revision - 1);

            Assert.AreNotEqual(tfsItem.Fields["System.AreaPath"].Value, oldFields["System.AreaPath"].Value);

            _wordAdapter.CreateNewWorkItem(config.GetConfigurationItems().First());
            _wordAdapter.WorkItems.First().Fields["System.Title"].Value    = "Test";
            _wordAdapter.WorkItems.First().Fields["System.Id"].Value       = oldFields["System.Id"].Value;
            _wordAdapter.WorkItems.First().Fields["System.Rev"].Value      = oldFields["System.Rev"].Value;
            _wordAdapter.WorkItems.First().Fields["System.AreaPath"].Value = oldFields["System.AreaPath"].Value;
            _wordAdapter = new Word2007TableSyncAdapter(_document, config);
            _wordAdapter.Open(null);

            _synchronizedWorkItemViewModel = new SynchronizedWorkItemViewModel(_tfsAdapter.WorkItems.First(), null, _wordAdapter, _documentModel.Object, null);
            _synchronizedWorkItemViewModel.Refresh();
            Assert.AreEqual(SynchronizationState.DivergedWithConflicts, _synchronizedWorkItemViewModel.SynchronizationState);
        }
        public void SynchronizedWorkItemViewModel_SynchronizationState_ShouldBeUpToDate_WithStackRankSetToTrue()
        {
            var config = CommonConfiguration.GetSimpleFieldConfiguration("Requirement", Direction.OtherToTfs, FieldValueType.PlainText, "System.Title");

            OpenAdapters(CommonConfiguration.TfsTestServerConfiguration(_testContext), config);
            config.UseStackRank = true;

            //add the stack rank configuration and a value
            _tfsAdapter.WorkItems.First().Configuration.FieldConfigurations.Add(new ConfigurationFieldItem("Microsoft.VSTS.Common.StackRank", string.Empty, FieldValueType.PlainText, Direction.OtherToTfs, 0, 0, string.Empty, false, HandleAsDocumentType.All, null, string.Empty, null, ShapeOnlyWorkaroundMode.AddSpace, false, null, null, null));
            _tfsAdapter.WorkItems.First().Fields["Microsoft.VSTS.Common.StackRank"].Value = "3000";

            _wordAdapter.CreateNewWorkItem(config.GetConfigurationItems().First());
            _wordAdapter.WorkItems.First().Fields["System.Title"].Value = _tfsAdapter.WorkItems.First().Fields["System.Title"].Value;
            _wordAdapter.WorkItems.First().Fields["System.Id"].Value = _tfsAdapter.WorkItems.First().Fields["System.Id"].Value;
            _wordAdapter.WorkItems.First().Fields["System.Rev"].Value = _tfsAdapter.WorkItems.First().Fields["System.Rev"].Value;
            _wordAdapter.WorkItems.First().Configuration.FieldConfigurations.Add(new ConfigurationFieldItem("Microsoft.VSTS.Common.StackRank", string.Empty, FieldValueType.PlainText, Direction.OtherToTfs, 0, 0, string.Empty, false, HandleAsDocumentType.All, null, string.Empty, null, ShapeOnlyWorkaroundMode.AddSpace, false, null, null, null));

            _wordAdapter = new Word2007TableSyncAdapter(_document, config);
            _wordAdapter.Open(null);

            _synchronizedWorkItemViewModel = new SynchronizedWorkItemViewModel(_tfsAdapter.WorkItems.First(), null, _wordAdapter, _documentModel.Object, null);
            _synchronizedWorkItemViewModel.Refresh();
            Assert.AreEqual(SynchronizationState.UpToDate, _synchronizedWorkItemViewModel.SynchronizationState);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Adds multiple links to another work items to this work item.
 /// </summary>
 /// <param name="adapter">Adapter used to look up more information about the referenced work items.</param>
 /// <param name="ids">The ids of the other work items.</param>
 /// <param name="linkType">The reference name of the link type.</param>
 /// <param name="overwrite">Not used. Always overwrites cell content</param>
 /// <returns>True when the link was fully added, false otherwise.</returns>
 /// <exception cref="ConfigurationException">Thrown if the configuration contains invalid cell column or row for link configuration.</exception>
 public bool AddLinks(IWorkItemSyncAdapter adapter, int[] ids, string linkType, bool overwrite)
 {
     return(AddLinks(adapter, ids, linkType, string.Empty, overwrite));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Adds the link.
 /// </summary>
 /// <param name="adapter">Adapter from which to look up missing references </param>
 /// <param name="ids">The id array.</param>
 /// <param name="linkType">The link type.</param>
 /// <param name="overwrite">if set to <c>true</c> overwrites any existing links of that type.</param>
 /// <returns></returns>
 public bool AddLinks(IWorkItemSyncAdapter adapter, int[] ids, string linkType, string linkedWorkItemTypes, bool overwrite)
 {
     // Nothing to do. We don't support this feature.
     return(true);
 }