/// <summary> /// Creates an active conflict of this type /// </summary> /// <param name="conflictDetails"></param> /// <returns></returns> public virtual MigrationConflict CreateConflict( string conflictDetails, string scopeHint, IMigrationAction conflictedAction) { return(MigrationConflictInitializer(conflictDetails, MigrationConflict.Status.Unresolved, scopeHint, conflictedAction)); }
public static void AddLabelActionsToChangeGroup(ChangeGroup changeGroup, ILabel label) { if (changeGroup != null && changeGroup.Actions.Count > 0 && label != null && label.LabelItems.Count > 0) { LabelProperties labelProperties = new LabelProperties(label); changeGroup.CreateAction( WellKnownChangeActionId.Add, null, null, // HACK: This is the ToPath which we shouldn't need for a label, but it is not currently nullable, so we use the first action Path changeGroup.Actions[0].Path, null, null, WellKnownContentType.VersionControlLabel.ReferenceName, labelProperties.ToXmlDocument()); // Create a MigrationAction for each item in the label foreach (ILabelItem labelItem in label.LabelItems) { IMigrationAction action = changeGroup.CreateAction( WellKnownChangeActionId.Add, null, null, labelItem.ItemCanonicalPath, labelItem.ItemVersion, null, labelItem.Recurse ? WellKnownContentType.VersionControlRecursiveLabelItem.ReferenceName : WellKnownContentType.VersionControlLabelItem.ReferenceName, null); } } }
private static string ExtractDocRootAttributeValue(IMigrationAction action, string attrName) { Debug.Assert(null != action.MigrationActionDescription.DocumentElement, "MigrationAction description is null"); XmlAttribute attrNode = action.MigrationActionDescription.DocumentElement.Attributes[attrName]; return(attrNode == null ? string.Empty : attrNode.Value); }
private static void CommitMigration(IMigrationAction migrationAction, IDocumentStore store) { var host = new MigrationHost(store); host.Actions.Add(migrationAction); host.PerformActions(); }
private void UpdateConversionHistory( IMigrationAction action, string newRecordDisplayName, string newRecordVersion, ConversionResult convRslt) { string sourceWorkItemId = UtilityMethods.ExtractSourceWorkItemId(action); string sourceWorkItemRevision = UtilityMethods.ExtractSourceWorkItemRevision(action); // update conversion history cache if (action.Action.Equals(WellKnownChangeActionId.Add) || action.Action.Equals(WellKnownChangeActionId.Edit)) { // insert conversion history for pushing to db convRslt.ItemConversionHistory.Add( new ItemConversionHistory(sourceWorkItemId, sourceWorkItemRevision, newRecordDisplayName, newRecordVersion)); convRslt.ChangeId = newRecordDisplayName + ":" + newRecordVersion; } else if (action.Action.Equals(WellKnownChangeActionId.AddAttachment) || action.Action.Equals(WellKnownChangeActionId.DelAttachment)) { // insert conversion history for pushing to db convRslt.ItemConversionHistory.Add( new ItemConversionHistory(sourceWorkItemId, "Attachment", newRecordDisplayName, newRecordVersion)); convRslt.ChangeId = newRecordDisplayName + ":" + newRecordVersion + " (Attachments)"; } }
private void UpdateActionDescription(Field f, IMigrationAction action, object newValue) { TraceManager.TraceInformation("Correcting field '{0}' with new value '{1}'", f.ReferenceName, newValue ?? "null"); XmlNode fieldCol = action.MigrationActionDescription.SelectSingleNode( string.Format("/WorkItemChanges/Columns/Column[@ReferenceName='{0}']", f.ReferenceName)); if (fieldCol == null) { // field column does not exist in the update document XmlNode columnsNode = action.MigrationActionDescription.SelectSingleNode("/WorkItemChanges/Columns"); var newFieldCol = (newValue == null) ? TfsMigrationWorkItem.CreateFieldColumn(action.MigrationActionDescription, f) : TfsMigrationWorkItem.CreateFieldColumn(action.MigrationActionDescription, f, newValue); columnsNode.AppendChild(newFieldCol); } else { object translatedValue = (newValue == null) ? TfsMigrationWorkItem.TranslateFieldValue(f) : TfsMigrationWorkItem.TranslateFieldValue(f, newValue); string updatedFieldValue = (translatedValue == null ? string.Empty : translatedValue.ToString()); fieldCol.FirstChild.InnerText = updatedFieldValue; } }
private void EditRecord(IMigrationAction action, ConversionResult convRslt) { string ownerRecordDisplayName = FindTargetWorkItemId(action); string ownerRecordType = UtilityMethods.ExtractRecordType(action); string changeAuthor = UtilityMethods.ExtractAuthor(action); // find the entity OAdEntity entity = CQWrapper.GetEntity(m_userSession, ownerRecordType, ownerRecordDisplayName); XmlNodeList columns = action.MigrationActionDescription.SelectNodes("/WorkItemChanges/Columns/Column"); if (null == columns) { throw new MigrationException(ClearQuestResource.ClearQuest_Error_InvalidActionDescription, action.ActionId); } string stateField = m_migrationContext.GetStateField(ownerRecordType); XmlNode stateTransitFieldNode = UtilityMethods.ExtractSingleFieldNodeFromMigrationDescription( action.MigrationActionDescription, stateField); bool containsStateTransit = (stateTransitFieldNode != null); if (containsStateTransit) { // change contains state transition List <string> skipFields; if (ChangeRecordState(entity, action, convRslt, stateTransitFieldNode, out skipFields)) { ModifyRecordContent(entity, action, convRslt, skipFields); } } else { ModifyRecordContent(entity, action, convRslt, null); } }
public override IMigrationAction LoadSingleAction(long actionInternalId) { IMigrationAction retAction = null; using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { Guid sessionUniqueId = new Guid(Session.SessionUniqueId); var actions = (from ca in context.RTChangeActionSet where ca.ChangeActionId == actionInternalId select ca); if (actions.Count() > 0) { RTChangeAction rtChangeAction = actions.First(); rtChangeAction.ChangeGroupReference.Load(); RTChangeGroup parentRTGroup = rtChangeAction.ChangeGroup; SqlChangeGroup parentChangeGroup = new SqlChangeGroup(this); retAction = parentChangeGroup.RealizeFromEDMWithSingleAction(parentRTGroup, rtChangeAction); } } return(retAction); }
internal List <IMigrationAction> LoadPagedActions(IEnumerable <RTChangeAction> rtChangeActions) { List <IMigrationAction> realizedMigrationActions = new List <IMigrationAction>(); SqlChangeGroup parentChangeGroup = null; RTChangeGroup parentRTGroup = null; foreach (RTChangeAction rtChangeAction in rtChangeActions) { if (parentRTGroup == null) { parentChangeGroup = new SqlChangeGroup(this); rtChangeAction.ChangeGroupReference.Load(); parentRTGroup = rtChangeAction.ChangeGroup; } IMigrationAction migrationAction = parentChangeGroup.RealizeFromEDMWithSingleAction(parentRTGroup, rtChangeAction); if (null != migrationAction) { realizedMigrationActions.Add(migrationAction); } } return(realizedMigrationActions); }
public ChangeGroupLabelItem(IMigrationAction action) { if (string.IsNullOrEmpty(action.Path)) { throw new ArgumentException(); } m_itemPath = action.Path; }
internal static string ExtractAttachmentComment(IMigrationAction action) { Debug.Assert(null != action.MigrationActionDescription.DocumentElement, "MigrationAction description is null"); XmlElement rootNode = action.MigrationActionDescription.DocumentElement; XmlNode attachmentNode = rootNode.FirstChild; return(attachmentNode.FirstChild.InnerText); }
internal static string ExtractAttachmentLength(IMigrationAction action) { Debug.Assert(null != action.MigrationActionDescription.DocumentElement, "MigrationAction description is null"); XmlElement rootNode = action.MigrationActionDescription.DocumentElement; XmlNode attachmentNode = rootNode.FirstChild; return(attachmentNode.Attributes["Length"].Value); }
public LabelFromMigrationAction(IMigrationAction labelMigrationAction) { LabelProperties labelProperties = new LabelProperties(FileMetadataProperties.CreateFromXmlDocument(labelMigrationAction.MigrationActionDescription)); m_name = labelProperties[LabelProperties.LabelNameKey]; m_comment = labelProperties[LabelProperties.LabelCommentKey]; m_owner = labelProperties[LabelProperties.LabelOwnerKey]; m_scope = labelProperties[LabelProperties.LabelScopeKey]; m_labelItems = new List <ILabelItem>(); }
private IEnumerable <ICommandData> GetCommandsForMigrationAction(IMigrationAction action) { var loop = new AyendesJSonQueryResultsLoop(_store, action.IndexName, action.QueryContents); var commands = loop.GetCommandToModifyJSONItems(action.GetReplacement); return(commands); }
/// <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); } } } }
public TFSHistoryNotFoundConflict(ConflictType conflictType, string changesetId, IMigrationAction conflictAction) : base(conflictType, Status.Unresolved, string.Format("Migration history of changeset {0} cannot be found", changesetId), changesetId) { if (conflictAction != null) { ConflictedChangeAction = conflictAction; } }
/// <summary> /// Creates a conflict of this type. /// </summary> /// <param name="sourceWorkItemType">The source Work Item Type that does not have a mapping in the configuration.</param> /// <param name="conflictedAction">The conflicted change action</param> /// <returns></returns> public static MigrationConflict CreateConflict(string sourceWorkItemType, IMigrationAction conflictedAction) { var newConflict = new MigrationConflict( new WITUnmappedWITConflictType(), MigrationConflict.Status.Unresolved, CreateConflictDetails(sourceWorkItemType), CreateScopeHint(sourceWorkItemType)); newConflict.ConflictedChangeAction = conflictedAction; return(newConflict); }
private MigrationConflict MigrationConflictInitializer( string conflictDetails, MigrationConflict.Status status, string scopeHint, IMigrationAction conflictedAction) { // using default details to readable description translator MigrationConflict conflict = new MigrationConflict(this, status, conflictDetails, scopeHint); conflict.ConflictedChangeAction = conflictedAction; return(conflict); }
public void Update(string workItemId, IMigrationAction action) { FileAttachmentMetadata attchMetadata = FileAttachmentMetadata.Create(action.MigrationActionDescription); if (null != attchMetadata) { var queryByItem = QueryByItem(workItemId); if (action.Action == WellKnownChangeActionId.AddAttachment) { if (queryByItem.Count() > 0) { queryByItem.First().RelationshipExistsOnServer = true; if (queryByItem.First().OtherProperty.HasValue) { queryByItem.First().OtherProperty = queryByItem.First().OtherProperty.Value + 1; } else { queryByItem.First().OtherProperty = 1; } } else { var newAttchRecord = CreateNewAttachmentStoreRecord( workItemId, FileAttachmentMetadata.CreateAttachmentStorageId(action.MigrationActionDescription), 1); } } else if (action.Action == WellKnownChangeActionId.DelAttachment) { if (queryByItem.Count() > 0) { if (queryByItem.First().RelationshipExistsOnServer) { if (queryByItem.First().OtherProperty.HasValue&& queryByItem.First().OtherProperty.Value > 0) { queryByItem.First().OtherProperty = queryByItem.First().OtherProperty.Value - 1; if (queryByItem.First().OtherProperty == 0) { queryByItem.First().RelationshipExistsOnServer = false; } } else { queryByItem.First().OtherProperty = 0; queryByItem.First().RelationshipExistsOnServer = false; } } } } m_context.TrySaveChanges(); } }
internal ChangeGroup GetChangeGroupForLatestFieldValues(ChangeGroupService changeGroupService) { string author = (string)WorkItem.Fields[CoreField.ChangedBy].Value; if (string.IsNullOrEmpty(author)) { author = (string)WorkItem.Fields[CoreField.AuthorizedAs].Value; } DateTime changedDate = (DateTime)WorkItem.Fields[CoreField.ChangedDate].Value; List <Field> fieldsForSync = new List <Field>(); foreach (Field f in WorkItem.Fields) { // filter out System.History with empty new value if (TFStringComparer.FieldName.Equals(f.ReferenceName, CoreFieldReferenceNames.History)) { if (string.IsNullOrEmpty(f.Value as string)) { continue; } } if (MustTakeField(f.FieldDefinition)) { fieldsForSync.Add(f); } } if (fieldsForSync.Count == 0) { return(null); } XmlDocument migrationActionDetails = CreateFieldRevisionDescriptionDoc( WorkItem.Rev, author, changedDate, fieldsForSync, new List <Field>()); ChangeGroup changeGroup = changeGroupService.CreateChangeGroupForDeltaTable( string.Format("{0}:{1}", WorkItem.Id, WorkItem.Rev)); IMigrationAction action = changeGroup.CreateAction( // Always generate Edit even for rev 1 in force sync case // Action will be changed to Add later if history not found for rev 1 WellKnownChangeActionId.Edit, new TfsWITMigrationItem(WorkItem, WorkItem.Rev), WorkItem.Id.ToString(), "", WorkItem.Rev.ToString(), "", WellKnownContentType.WorkItem.ReferenceName, migrationActionDetails); return(changeGroup); }
public override bool IsSyncGeneratedAction(IMigrationAction action, Guid migrationSourceIdOfChangeGroup) { if (action.ChangeGroup != null && !string.IsNullOrEmpty(action.ChangeGroup.Name)) { return(IsSyncGeneratedItemVersion(action.ChangeGroup.Name, Constants.ChangeGroupGenericVersionNumber, migrationSourceIdOfChangeGroup)); } else { throw new ArgumentException("action.ChangeGroup is unknown", "action"); } }
public static MigrationConflict CreateConflict( string changesetId, IMigrationAction conflictAction) { if (string.IsNullOrEmpty(changesetId)) { throw new ArgumentNullException("changesetId"); } TFSHistoryNotFoundConflictType conflictInstance = new TFSHistoryNotFoundConflictType(); return(new TFSHistoryNotFoundConflict(conflictInstance, changesetId, conflictAction)); }
internal static Microsoft.TeamFoundation.Migration.Toolkit.MigrationConflict CreateConflict( CQTextParser.RecordValidationResult rslt, IMigrationAction action) { var newConflict = new MigrationConflict( new ClearQuestInvalidFieldValueConflictType(), MigrationConflict.Status.Unresolved, CreateConflictDetails(rslt, action), CreateScopeHint(rslt, action)); newConflict.ConflictedChangeAction = action; return(newConflict); }
private bool SetMandatoryFields(IMigrationAction action, ref OAdEntity newRecord, out List <string> processedFields) { XmlNodeList columns = action.MigrationActionDescription.SelectNodes("/WorkItemChanges/Columns/Column"); if (null == columns) { throw new MigrationException(ClearQuestResource.ClearQuest_Error_InvalidActionDescription, action.ActionId); } StringBuilder updateLog = new StringBuilder(); PrintUpdateLogHeader(action, updateLog); processedFields = new List <string>(); foreach (XmlNode columnData in columns) { string stringVal = columnData.FirstChild.InnerText; string fieldName = columnData.Attributes["ReferenceName"].Value; Debug.Assert(!string.IsNullOrEmpty(fieldName), "Field ReferenceName is absent in the Migration Description"); OAdFieldInfo aFieldInfo = CQWrapper.GetEntityFieldValue(newRecord, fieldName); int fieldRequiredness = CQWrapper.GetRequiredness(aFieldInfo); if (fieldRequiredness != CQConstants.MANDATORY) { // skipping all non-mandatory fields continue; } string originalFieldValue = CQWrapper.GetFieldValue(aFieldInfo); int attempt1Count = 0; if (!SetFieldValue(action, newRecord, fieldName, stringVal, ref attempt1Count)) { return(false); } AddFieldToUpdateLog(fieldName, stringVal, updateLog); processedFields.Add(fieldName); } AddLineToUpdateLog(updateLog); int attempt2Count = 0; if (!SetFieldValue(action, newRecord, NoteEntryFieldName, updateLog.ToString(), ref attempt2Count)) { return(false); } return(true); }
private IMigrationAction CreateDeleteAttachmentAction(IMigrationAction action) { SqlMigrationAction sqlMigrationAction = action as SqlMigrationAction; System.Diagnostics.Debug.Assert(null != sqlMigrationAction, "cannot convert action to SqlMigrationAction"); SqlMigrationAction copy = new SqlMigrationAction( action.ChangeGroup, 0, WellKnownChangeActionId.DelAttachment, action.SourceItem, action.FromPath, action.Path, action.Version, action.MergeVersionTo, action.ItemTypeReferenceName, action.MigrationActionDescription, action.State); return(copy); }
public override bool IsSyncGeneratedAction(IMigrationAction action, Guid migrationSourceIdOfChangeGroup) { XmlElement rootNode = action.MigrationActionDescription.DocumentElement; if (null == rootNode) { throw new MigrationException(MigrationToolkitResources.InvalideChangeActionDescription, action.ActionId); } string sourceItemId = rootNode.Attributes["WorkItemID"].Value; string sourceItemRevision = rootNode.Attributes["Revision"].Value; return(IsSyncGeneratedItemVersion(sourceItemId, sourceItemRevision, migrationSourceIdOfChangeGroup)); }
/// <summary> /// For testing /// </summary> /// <param name="configuration"></param> /// <param name="contextFactory"></param> /// <param name="updateAction"></param> /// <param name="rollbackAction"></param> internal EfPersistenceMigrator(IMigrationAction updateAction, IMigrationAction rollbackAction) { if (updateAction == null) { throw new ArgumentNullException(nameof(updateAction)); } if (rollbackAction == null) { throw new ArgumentNullException(nameof(rollbackAction)); } _updateAction = updateAction; _rollbackAction = rollbackAction; }
internal IMigrationAction CreateChangeAction(ChangeGroup hostChangeGroup, string lastVersion) { IMigrationAction action = hostChangeGroup.CreateAction(WellKnownChangeActionId.AddAttachment, this, MigrationRecordId, "", null, "", WellKnownContentType.WorkItem.ReferenceName, CreateAttachmentDescriptionDoc(lastVersion)); return(action); }
private void createMigrationAction(ChangeGroup changeGroup, Guid actionId, string localPath, bool isDirectory) { IMigrationAction action = changeGroup.CreateAction( actionId, new TfsFileSystemMigrationItem(localPath, isDirectory), null, localPath, null, null, isDirectory ? WellKnownContentType.VersionControlledFolder.ReferenceName : WellKnownContentType.VersionControlledFile.ReferenceName, null, m_contentConflictDetectionOnly); }
private void createRelativeMigrationAction(ChangeGroup changeGroup, Guid actionId, String relatedBranchLocalPath, String localPath, Boolean isDirectory) { IMigrationAction action = changeGroup.CreateAction( actionId, new TfsFileSystemMigrationItem(localPath, isDirectory), relatedBranchLocalPath, localPath, "T", "T", isDirectory ? WellKnownContentType.VersionControlledFolder.ReferenceName : WellKnownContentType.VersionControlledFile.ReferenceName, null, m_contentConflictDetectionOnly); }