public bool Update( ClearQuestMigrationContext migrationContext, Session cqSession, OAdEntity hostRecord, LinkChangeAction linkChangeAction) { if (null == linkChangeAction) { throw new ArgumentNullException("linkChangeAction"); } if (!linkChangeAction.Link.LinkType.ReferenceName.Equals(REFERENCE_NAME)) { throw new ArgumentException("Link type mismatch."); } string childRecEntityDefName; if (!ClearQuestRecordArtifactHandler.TryExtractRecordDefName(linkChangeAction.Link.TargetArtifact, out childRecEntityDefName)) { return(false); } string childRecDispName; if (!ClearQuestRecordArtifactHandler.TryExtractRecordDispName(linkChangeAction.Link.TargetArtifact, out childRecDispName)) { return(false); } OAdEntity childEntity = CQWrapper.GetEntity(cqSession, childRecEntityDefName, childRecDispName); if (null == childEntity) { return(false); } // check if hostRecord already has a duplicate of this childRecord bool duplicateAlreadyExist = HasDuplicateRecord(hostRecord, childRecEntityDefName, childRecDispName); // find out the child entity's current state // find the current state string childEntityDefName = CQWrapper.GetEntityDefName(childEntity); OAdFieldInfo aFldInfo = CQWrapper.GetEntityFieldValue(childEntity, migrationContext.GetStateField(childEntityDefName)); string srcState = CQWrapper.GetFieldValue(aFldInfo); OAdEntityDef childEntityDef = CQWrapper.GetEntityDef(cqSession, childEntityDefName); if (linkChangeAction.ChangeActionId.Equals(WellKnownChangeActionId.Add)) { if (duplicateAlreadyExist) { // [teyang] TODO return(false); } string[] changeActionNames = CQUtilityMethods.FindAllActionNameByTypeAndSourceState( childEntityDef, srcState, CQConstants.ACTION_DUPLICATE); string changeActionName = string.Empty; if (changeActionNames.Length == 0) { // [teyang] TODO conflict } else if (changeActionNames.Length > 1) { // [teyang] TODO conflict } else { changeActionName = changeActionNames[0]; } if (!string.IsNullOrEmpty(changeActionName)) { CQWrapper.MarkEntityAsDuplicate(cqSession, childEntity, hostRecord, changeActionName); string retVal = CQWrapper.Validate(childEntity); if (string.IsNullOrEmpty(retVal)) { // [teyang] TODO conflict } retVal = CQWrapper.Commmit(childEntity); if (string.IsNullOrEmpty(retVal)) { // [teyang] TODO conflict } } } else if (linkChangeAction.ChangeActionId.Equals(WellKnownChangeActionId.Delete)) { if (!duplicateAlreadyExist) { // [teyang] TODO return(false); } string[] changeActionNames = CQUtilityMethods.FindAllActionNameByTypeAndSourceState( childEntityDef, srcState, CQConstants.ACTION_UNDUPLICATE); string changeActionName = string.Empty; if (changeActionNames.Length == 0) { // [teyang] TODO conflict } else if (changeActionNames.Length > 1) { // [teyang] TODO conflict } else { changeActionName = changeActionNames[0]; } if (!string.IsNullOrEmpty(changeActionName)) { CQWrapper.UnmarkEntityAsDuplicate(cqSession, childEntity, changeActionName); string retVal = CQWrapper.Validate(childEntity); if (string.IsNullOrEmpty(retVal)) { // [teyang] TODO conflict } retVal = CQWrapper.Commmit(childEntity); if (string.IsNullOrEmpty(retVal)) { // [teyang] TODO conflict } } } else { //throw new MigrationException(TfsWITAdapterResources.ErrorUnsupportedChangeAction); } return(true); }