/// <summary>
        /// This method allows the implementing class to add file property metadata for any files
        /// that are added or changed during a migration/sync session.
        /// </summary>
        /// <param name="serviceContainer">A service container that provides access to services provided by the
        /// TFS Integration Platform Toolkit</param>
        /// <param name="changeGroup">The change group being migrated for file property metadata can be generated
        /// by adding FileProperty change actions to the ChangeGroup</param>
        private void AddCheckinNotesFilePropertiesToChangeGroup(IServiceContainer serviceContainer, ChangeGroup changeGroup)
        {
            // Add the changeset number as a file property
            FileMetadataProperties fileProperties = new FileMetadataProperties();

            // Try to parse the changeGroup.Name property to the TFS changeset ID.
            // This is true in most cases but not all
            int tfsChangesetId;

            if (int.TryParse(changeGroup.Name, out tfsChangesetId))
            {
                try
                {
                    Changeset changeset = GetTfsClient(serviceContainer).GetChangeset(tfsChangesetId);
                    if (changeset.CheckinNote != null)
                    {
                        foreach (CheckinNoteFieldValue checkinNote in changeset.CheckinNote.Values)
                        {
                            string propertyName = MakeSimplePropertyName(checkinNote.Name);
                            fileProperties.Add(propertyName, checkinNote.Value);
                        }
                    }
                }
                catch
                {
                }
            }

            XmlDocument filePropertiesXmlDoc = fileProperties.ToXmlDocument();

            IMigrationAction[] currentActions = new IMigrationAction[changeGroup.Actions.Count];
            changeGroup.Actions.CopyTo(currentActions, 0);
            foreach (IMigrationAction action in currentActions)
            {
                if (string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlledFile.ReferenceName, StringComparison.Ordinal) ||
                    string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlledFolder.ReferenceName, StringComparison.Ordinal))
                {
                    if (action.Action == WellKnownChangeActionId.Add ||
                        action.Action == WellKnownChangeActionId.Edit ||
                        action.Action == WellKnownChangeActionId.Rename ||
                        action.Action == WellKnownChangeActionId.Undelete)
                    {
                        IMigrationAction addFilePropertiesAction = changeGroup.CreateAction(
                            WellKnownChangeActionId.AddFileProperties,
                            action.SourceItem,
                            action.FromPath,
                            action.Path,
                            action.Version,
                            null,
                            action.ItemTypeReferenceName,
                            filePropertiesXmlDoc);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// This method allows the implementing class to add file property metadata for any files
        /// that are added or changed during a migration/sync session.
        /// </summary>
        /// <param name="serviceContainer">A service container that provides access to services provided by the
        /// TFS Integration Platform Toolkit</param>
        /// <param name="changeGroup">The change group being migrated for file property metadata can be generated
        /// by adding FileProperty change actions to the ChangeGroup</param>
        private void AddFilePropertiesToChangeGroup(IServiceContainer serviceContainer, ChangeGroup changeGroup)
        {
            ChangeGroupService changeGroupService = (ChangeGroupService)serviceContainer.GetService(typeof(ChangeGroupService));

            // This FilePropertiesAnalysisAddin adds two single properties to each item:
            //      The change group identifier from the source from which is was migrated
            //      The owner of the change group
            FileMetadataProperties fileProperties = new FileMetadataProperties();

            fileProperties.Add(FilePropertiesAnalysisAddinResources.SourceChangeGroupIdKey, changeGroup.Name);
            fileProperties.Add(FilePropertiesAnalysisAddinResources.SourceChangeGroupOwnerKey, changeGroup.Owner);
            XmlDocument filePropertiesXmlDoc = fileProperties.ToXmlDocument();

            IMigrationAction[] currentActions = new IMigrationAction[changeGroup.Actions.Count];
            changeGroup.Actions.CopyTo(currentActions, 0);
            foreach (IMigrationAction action in currentActions)
            {
                if (string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlledFile.ReferenceName, StringComparison.Ordinal) ||
                    string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlledFolder.ReferenceName, StringComparison.Ordinal))
                {
                    if (action.Action == WellKnownChangeActionId.Add ||
                        action.Action == WellKnownChangeActionId.Edit ||
                        action.Action == WellKnownChangeActionId.Rename ||
                        action.Action == WellKnownChangeActionId.Undelete)
                    {
                        IMigrationAction addFilePropertiesAction = changeGroup.CreateAction(
                            WellKnownChangeActionId.AddFileProperties,
                            action.SourceItem,
                            action.FromPath,
                            action.Path,
                            action.Version,
                            null,
                            action.ItemTypeReferenceName,
                            filePropertiesXmlDoc);
                    }
                }
            }
        }