private bool SessionGroupIsRunning(MigrationConflict conflict) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { RTSessionGroup rtSessionGroup = FindSessionGroupForConflictedAction(conflict, context); if (rtSessionGroup == null) { return(false); } Guid sessionGroupId = rtSessionGroup.GroupUniqueId; // first, ask the wcf service if it is managing an active session group of this MigrationServiceClient client = new MigrationServiceClient(); var runningGroupIds = client.GetRunningSessionGroups(); if (!runningGroupIds.Contains(sessionGroupId)) { return(false); } // next, check if the group is not in the "running" sync orchestration state switch (rtSessionGroup.OrchestrationStatus) { case (int)PipelineState.Running: case (int)PipelineState.Starting: return(true); default: return(false); } } }
private bool IsSessionUniDirectional(RuntimeEntityModel context, RTSessionGroup rtSessionGroup) { var sessionGroupConfigQuery = (from sg in context.RTSessionGroupConfigSet where sg.SessionGroup.GroupUniqueId.Equals(rtSessionGroup.GroupUniqueId) orderby sg.Id descending select sg).First(); WorkFlowType workFlowType = new WorkFlowType(sessionGroupConfigQuery.WorkFlowType); return(workFlowType.DirectionOfFlow == DirectionOfFlow.Unidirectional); }
/// <summary> /// Gets the current state of the state machine. /// </summary> /// <param name="ownerType">The type, session or session group, that this state machine represents.</param> /// <param name="ownerUniqueId">The GUID used as the unique Id for the subject session or session group.</param> /// <returns>The current state of the subject session or session group.</returns> public PipelineState GetCurrentState(OwnerType ownerType, Guid ownerUniqueId) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { switch (ownerType) { case OwnerType.Session: var sessionQuery = context.RTSessionSet.Where(s => s.SessionUniqueId.Equals(ownerUniqueId)); RTSession session = sessionQuery.FirstOrDefault(); if (session != null && session.OrchestrationStatus.HasValue) { return((PipelineState)session.OrchestrationStatus.Value); } else { return(PipelineState.Default); } case OwnerType.SessionGroup: var sessionGroupQuery = context.RTSessionGroupSet.Where(sg => sg.GroupUniqueId.Equals(ownerUniqueId)); RTSessionGroup sessionGroup = sessionGroupQuery.FirstOrDefault(); if (sessionGroup != null && sessionGroup.OrchestrationStatus.HasValue) { return((PipelineState)sessionGroupQuery.First().OrchestrationStatus.Value); } else { return(PipelineState.Default); } default: Debug.Assert(false, "Invalid OwnerType"); throw new InvalidOperationException("Invalid OwnerType"); } } }
private ConflictResolutionResult ResolveBySubmitMissingChanges( IServiceContainer serviceContainer, MigrationConflict conflict, ConflictResolutionRule rule, out List <MigrationAction> actions) { actions = null; var retVal = new ConflictResolutionResult(false, ConflictResolutionType.Other); WITTranslationService translationService = serviceContainer.GetService(typeof(ITranslationService)) as WITTranslationService; Debug.Assert(null != translationService, "translationService is not initialized or not a wit translation service"); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { RTSessionGroup rtSessionGroup = FindSessionGroupForConflictedAction(conflict, context); if (null == rtSessionGroup) { return(retVal); } BM.BusinessModelManager bmm = new BM.BusinessModelManager(); BM.Configuration sessionGroupConfig = bmm.LoadConfiguration(rtSessionGroup.GroupUniqueId); // find target-side migration source config var parentChangeGroup = FindChangeGroupForConflictedAction(conflict, context); Guid targetMigrationSourceId = parentChangeGroup.SourceUniqueId; BM.MigrationSource targetMigrationSourceConfig = sessionGroupConfig.SessionGroup.MigrationSources[targetMigrationSourceId]; if (null == targetMigrationSourceConfig) { return(retVal); } // find source-side migration source config RTSession rtSession = FindSessionForConflictedAction(conflict, context); BM.Session parentSession = null; foreach (BM.Session s in sessionGroupConfig.SessionGroup.Sessions.Session) { if (new Guid(s.SessionUniqueId).Equals(rtSession.SessionUniqueId)) { parentSession = s; break; } } if (parentSession == null) { return(retVal); } Guid sourceMigrationSourceId = ((new Guid(parentSession.LeftMigrationSourceUniqueId)).Equals(targetMigrationSourceId)) ? new Guid(parentSession.RightMigrationSourceUniqueId) : new Guid(parentSession.LeftMigrationSourceUniqueId); BM.MigrationSource sourceMigrationSourceConfig = sessionGroupConfig.SessionGroup.MigrationSources[sourceMigrationSourceId]; if (null == sourceMigrationSourceConfig) { return(retVal); } string sourceServerUrl = sourceMigrationSourceConfig.ServerUrl; string sourceTeamProject = sourceMigrationSourceConfig.SourceIdentifier; string targetServerUrl = targetMigrationSourceConfig.ServerUrl; string targetTeamProject = targetMigrationSourceConfig.SourceIdentifier; string srcWorkItemIdStr = TfsMigrationWorkItemStore.GetSourceWorkItemId(conflict.ConflictedChangeAction); Debug.Assert(!string.IsNullOrEmpty(srcWorkItemIdStr), "srcWorkItemId is null or empty"); int srcWorkItemId; if (!int.TryParse(srcWorkItemIdStr, out srcWorkItemId)) { return(retVal); } string srcRevRanges = rule.DataFieldDictionary[HistoryNotFoundSubmitMissingChangesAction.DATAKEY_REVISION_RANGE]; int[] sourceRevToSync = new int[0]; if (string.IsNullOrEmpty(srcRevRanges)) { sourceRevToSync = ExtractMissingRevs(conflict.ConflictedChangeAction); } else { if (!IntegerRange.TryParseRangeString(srcRevRanges, out sourceRevToSync)) { return(retVal); } } if (sourceRevToSync.Length == 0) { return(retVal); } try { // compute delta from source side TfsWITAnalysisProvider analysisProvider = new TfsWITAnalysisProvider(sourceServerUrl, sourceTeamProject); WorkItem sourceWorkItem = analysisProvider.GetWorkItem(srcWorkItemId); Hist.MigrationAction[] sourceRevDetails = new Hist.MigrationAction[sourceRevToSync.Length]; for (int revIndex = 0; revIndex < sourceRevToSync.Length; ++revIndex) { var details = new TfsWITRecordDetails(sourceWorkItem, sourceRevToSync[revIndex]); SanitizeDetails(details); translationService.MapWorkItemTypeFieldValues( sourceWorkItem.Id.ToString(), details.DetailsDocument, sourceMigrationSourceId); TfsConstants.ChangeActionId actionId = (sourceRevToSync[revIndex] == 1 ? TfsConstants.ChangeActionId.Add : TfsConstants.ChangeActionId.Edit); sourceRevDetails[revIndex] = new Hist.MigrationAction(sourceWorkItem.Id.ToString(), details, actionId); } // migrate to target side TfsWITMigrationProvider migrationProvider = new TfsWITMigrationProvider(targetServerUrl, targetTeamProject, string.Empty); Hist.ConversionResult conversionResult = migrationProvider.ProcessChangeGroup(sourceRevDetails); // update conversion history ConversionResult convRslt = new ConversionResult(sourceMigrationSourceId, targetMigrationSourceId); convRslt.ChangeId = HistoryNotFoundResolutionChangeId; convRslt.ContinueProcessing = true; foreach (var itemConvHist in conversionResult.ItemConversionHistory) { convRslt.ItemConversionHistory.Add(new ItemConversionHistory( itemConvHist.SourceItemId, itemConvHist.SourceItemVersion, itemConvHist.TargetItemId, itemConvHist.TargetItemVersion)); } parentChangeGroup.SessionRunReference.Load(); int sessionRunId = parentChangeGroup.SessionRun.Id; convRslt.Save(sessionRunId, sourceMigrationSourceId); } catch (Exception ex) { TraceManager.TraceException(ex); retVal.Comment = ex.ToString(); return(retVal); } } retVal.Resolved = true; return(retVal); }
private void StartDeletion(RTSessionGroup rtSessionGroup) { Debug.Assert(null != rtSessionGroup, "SessionGroup is NULL"); rtSessionGroup.State = (int)BusinessModelManager.SessionStateEnum.MarkedForDeletion; m_context.TrySaveChanges(); }