internal void Initialize(int sessionRunId) { m_session.Initialize(sessionRunId); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { RTSessionRun sessionRun = context.RTSessionRunSet.Where (sr => sr.Id == m_session.InternalSessionRunId).First(); Debug.Assert(sessionRun != null, "Cannot find session run in the Tfs Migration DB"); sessionRun.ConflictCollectionReference.Load(); // finishing the conflict manager initialization by assigning the current // ConflictCollection Id to them foreach (var serviceContainer in this.m_serviceContainers.Values) { ConflictManager conflictManager = serviceContainer.GetService(typeof(ConflictManager)) as ConflictManager; Debug.Assert(null != conflictManager, "null == conflictManager"); conflictManager.InitializePhase2(sessionRun.ConflictCollection.Id); } } foreach (KeyValuePair <Guid, IMigrationProvider> provider in m_migrationProviders) { try { provider.Value.InitializeClient(); } catch (Exception e) { ConflictManager manager = m_serviceContainers[provider.Key].GetService(typeof(ConflictManager)) as ConflictManager; ErrorManager.TryHandleException(e, manager); } } }
/// <summary> /// Heavier-weight Phase2 initialization /// </summary> /// <param name="sessionRunId"></param> internal void Initialize(int sessionRunId, ISessionOrchestrator sessionOrchestrator) { m_session.Initialize(sessionRunId); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { RTSessionRun sessionRun = context.RTSessionRunSet.Where (sr => sr.Id == m_session.InternalSessionRunId).First(); Debug.Assert(sessionRun != null, "Cannot find session run in the Tfs Migration DB"); sessionRun.ConflictCollectionReference.Load(); // finishing the conflict manager initialization by assigning the current // ConflictCollection Id to them foreach (var serviceContainer in this.m_serviceContainers.Values) { ConflictManager conflictManager = serviceContainer.GetService(typeof(ConflictManager)) as ConflictManager; Debug.Assert(null != conflictManager, "null == conflictManager"); conflictManager.InitializePhase2(sessionRun.ConflictCollection.Id); } } foreach (var provider in m_analysisProviders.Values) { provider.InitializeClient(); } }
public SessionRunViewModel(RTSessionRun sessionRun) { m_sessionRun = sessionRun; m_host = RuntimeManager.GetInstance(); IRefreshService refresh = (IRefreshService)m_host.GetService(typeof(IRefreshService)); refresh.AutoRefresh += this.AutoRefresh; // Avoid race by driving through top level refresh instead of relying upon background thread. Refresh(); }
private RTConversionHistory UpdateGroupConvHist( RuntimeEntityModel context, RTSessionRun rtSessionRun, RTMigrationSource rtMigrationSource) { RTConversionHistory runTimeConverHistory = RTConversionHistory.CreateRTConversionHistory( DateTime.UtcNow, -1, false); runTimeConverHistory.SessionRun = rtSessionRun; runTimeConverHistory.SourceMigrationSource = rtMigrationSource; context.AddToRTConversionHistorySet(runTimeConverHistory); return(runTimeConverHistory); }
/// <summary> /// Saves the conversion history and associate it with a particular session run and migration source; /// Additionally, mark the Reflected Change Group (the delta table entry of this processed change group) to be sync-ed. /// </summary> /// <param name="sessionRunId">int.MinValue if sessionRunId is not available</param> /// <param name="migrationSourceId"></param> /// <param name="sessionId"></param> /// <param name="reflectedChangeGroupId"></param> /// <returns></returns> internal bool Save( int sessionRunId, Guid migrationSourceId, Guid sessionId, long?reflectedChangeGroupId) { if (string.IsNullOrEmpty(ChangeId)) { return(false); } using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { if (ItemConversionHistory.Count > 0) { var sessionRunQuery = (sessionRunId == int.MinValue) ? from sr in context.RTSessionRunSet where sr.Config.LeftSourceConfig.MigrationSource.UniqueId.Equals(migrationSourceId) || sr.Config.RightSourceConfig.MigrationSource.UniqueId.Equals(migrationSourceId) select sr : context.RTSessionRunSet.Where(sr => sr.Id == sessionRunId); if (sessionRunQuery.Count() == 0) { return(false); } RTSessionRun rtSessionRun = sessionRunQuery.First(); var migrationSourceQuery = context.RTMigrationSourceSet.Where(ms => ms.UniqueId.Equals(migrationSourceId)); if (migrationSourceQuery.Count() == 0) { return(false); } RTMigrationSource rtMigrationSource = migrationSourceQuery.First(); RTConversionHistory rtConvHist = UpdateGroupConvHist(context, rtSessionRun, rtMigrationSource); UpdateItemConversionHistory(rtConvHist, context); } if (!sessionId.Equals(Guid.Empty) && reflectedChangeGroupId.HasValue) { MarkDeltaTableSynced(context, sessionId, reflectedChangeGroupId.Value); } context.TrySaveChanges(); return(true); } }
public void FinishTrackingEvent(Guid eventReferenceName) { lock (m_eventTrackCacheLock) { if (!m_eventTrackCache.ContainsKey(eventReferenceName)) { return; } using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { RTSessionRun rtSessionRun = context.RTSessionRunSet.Where (s => s.Id == m_session.InternalSessionRunId).First <RTSessionRun>(); Debug.Assert(rtSessionRun != null, string.Format("Cannot find session run with Id ({0}) to track event", m_session.InternalSessionRunId)); EventTrackingCache cache = m_eventTrackCache[eventReferenceName]; RTGeneralPerformanceData perfData = (from p in context.RTGeneralPerformanceDataSet where p.RuntimeSessionGroupRun.Id == rtSessionRun.SessionGroupRun.Id && p.SessionUniqueId.Equals(rtSessionRun.Config.SessionUniqueId) && p.SourceUniqueId.Equals(m_sourceId) && p.CriterionReferenceName.Equals(eventReferenceName) select p).First <RTGeneralPerformanceData>(); if (null == perfData) { perfData = RTGeneralPerformanceData.CreateRTGeneralPerformanceData( 0, rtSessionRun.Config.SessionUniqueId, m_sourceId, eventReferenceName, cache.FriendlyName); perfData.RuntimeSessionGroupRun = rtSessionRun.SessionGroupRun; } perfData.PerfCounter = cache.Counter; perfData.PerfStartTime = cache.StartTime; perfData.PerfFinishTime = DateTime.Now; context.TrySaveChanges(); } m_eventTrackCache.Remove(eventReferenceName); } }
private bool updateConversionHistory(MigrationConflict conflict, ConflictResolutionRule rule) { if (!rule.DataFieldDictionary.ContainsKey(VCContentConflictUserMergeChangeAction.MigrationInstructionChangeId) || !rule.DataFieldDictionary.ContainsKey(VCContentConflictUserMergeChangeAction.DeltaTableChangeId)) { return(false); } string migrationInstructionName = rule.DataFieldDictionary[VCContentConflictUserMergeChangeAction.MigrationInstructionChangeId]; string deltaTableName = rule.DataFieldDictionary[VCContentConflictUserMergeChangeAction.DeltaTableChangeId]; using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { ChangeGroup conflictChangeGroup = conflict.ConflictedChangeAction.ChangeGroup; Guid deltaSideSourceId; // Mark all delta table entry as DeltaComplete var deltaTableEntries = from d in context.RTChangeGroupSet where d.SessionUniqueId == conflictChangeGroup.SessionId && d.Status == (int)ChangeStatus.DeltaPending select d; foreach (RTChangeGroup deltaTableEntry in deltaTableEntries) { deltaTableEntry.Status = (int)ChangeStatus.DeltaComplete; deltaTableEntry.ContainsBackloggedAction = false; } // Mark all migration instruction entry as Complete var migrationInstructionEntries = from d in context.RTChangeGroupSet where d.SessionUniqueId == conflictChangeGroup.SessionId && (d.Status == (int)ChangeStatus.Pending || d.Status == (int)ChangeStatus.InProgress || d.Status == (int)ChangeStatus.PendingConflictDetection) select d; foreach (RTChangeGroup migrationInstructionEntry in migrationInstructionEntries) { migrationInstructionEntry.Status = (int)ChangeStatus.Complete; migrationInstructionEntry.ContainsBackloggedAction = false; } // Mark the source side highwatermark var sourceSideHighWaterMark = (from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId == conflictChangeGroup.SessionId && hwm.SourceUniqueId != conflictChangeGroup.SourceId && hwm.Name == Constants.HwmDelta select hwm).First(); Debug.Assert(sourceSideHighWaterMark != null, "Can't find the source side HWM"); sourceSideHighWaterMark.Value = deltaTableName; deltaSideSourceId = sourceSideHighWaterMark.SourceUniqueId; // Mark the target side highwatermark var targetHighWaterMark = (from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId == conflictChangeGroup.SessionId && hwm.SourceUniqueId == conflictChangeGroup.SourceId && hwm.Name == Constants.HwmDelta select hwm).First(); Debug.Assert(targetHighWaterMark != null, "Can't find the target side HWM"); targetHighWaterMark.Value = migrationInstructionName; // Create the conversion history entry RTConversionHistory conversionHistory = RTConversionHistory.CreateRTConversionHistory( DateTime.UtcNow, -1, true); conversionHistory.Comment = rule.RuleDescription; var session = (from s in context.RTSessionConfigSet where s.SessionUniqueId == conflictChangeGroup.SessionId select s).First(); Debug.Assert(session != null, "Cannot find session in DB"); RTSessionRun sessionRun = (from sr in context.RTSessionRunSet where sr.Id == session.Id select sr).First(); Debug.Assert(sessionRun != null, "Cannot find session run in DB"); conversionHistory.SessionRun = sessionRun; RTMigrationSource migrationSource = (from ms in context.RTMigrationSourceSet where ms.UniqueId.Equals(conflictChangeGroup.SourceId) select ms).First(); Debug.Assert(migrationSource != null, "Cannot find the migration source to persist conversion history"); RTMigrationSource deltaSideMigrationSource = (from ms in context.RTMigrationSourceSet where ms.UniqueId.Equals(deltaSideSourceId) select ms).First(); Debug.Assert(deltaSideMigrationSource != null, "Cannot find the migration source to persist conversion history"); conversionHistory.SourceMigrationSource = migrationSource; context.AddToRTConversionHistorySet(conversionHistory); RTMigrationItem sourceItem = RTMigrationItem.CreateRTMigrationItem(0, deltaTableName, Constants.ChangeGroupGenericVersionNumber); sourceItem.MigrationSource = migrationSource; RTMigrationItem targetItem = RTMigrationItem.CreateRTMigrationItem(0, migrationInstructionName, Constants.ChangeGroupGenericVersionNumber); targetItem.MigrationSource = deltaSideMigrationSource; RTItemRevisionPair pair = RTItemRevisionPair.CreateRTItemRevisionPair( sourceItem.Id, targetItem.Id); pair.LeftMigrationItem = sourceItem; pair.RightMigrationItem = targetItem; pair.ConversionHistory = conversionHistory; // Create a new HistoryNotFoundConflict Resolution Rule context.TrySaveChanges(); } return(true); }
/// <summary> /// Update the conversion history with the given migration instruction and delta table entry. This will add the entry to conversion history and remove all pending change groups. /// </summary> /// <param name="migrationInstructionName"></param> /// <param name="deltaTableName"></param> /// <param name="comment"></param> /// <returns></returns> public override bool UpdateConversionHistoryAndRemovePendingChangeGroups(string migrationInstructionName, string deltaTableName, string comment) { if (string.IsNullOrEmpty(migrationInstructionName) || (string.IsNullOrEmpty(deltaTableName))) { return(false); } using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { Guid deltaSideSourceId; Guid sessionId = new Guid(Session.SessionUniqueId); // Mark all delta table entry as DeltaComplete var deltaTableEntries = from d in context.RTChangeGroupSet where d.SessionUniqueId == sessionId && d.Status == (int)ChangeStatus.DeltaPending select d; foreach (RTChangeGroup deltaTableEntry in deltaTableEntries) { deltaTableEntry.Status = (int)ChangeStatus.DeltaComplete; deltaTableEntry.ContainsBackloggedAction = false; } // Mark all migration instruction entry as Complete var migrationInstructionEntries = from d in context.RTChangeGroupSet where d.SessionUniqueId == sessionId && (d.Status == (int)ChangeStatus.Pending || d.Status == (int)ChangeStatus.InProgress || d.Status == (int)ChangeStatus.PendingConflictDetection) select d; foreach (RTChangeGroup migrationInstructionEntry in migrationInstructionEntries) { migrationInstructionEntry.Status = (int)ChangeStatus.Complete; migrationInstructionEntry.ContainsBackloggedAction = false; } // Mark the source side highwatermark var sourceSideHighWaterMark = (from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId == sessionId && hwm.SourceUniqueId != SourceId && hwm.Name == Constants.HwmDelta select hwm).First(); Debug.Assert(sourceSideHighWaterMark != null, "Can't find the source side HWM"); sourceSideHighWaterMark.Value = deltaTableName; deltaSideSourceId = sourceSideHighWaterMark.SourceUniqueId; // Mark the target side highwatermark var targetHighWaterMark = (from hwm in context.RTHighWaterMarkSet where hwm.SessionUniqueId == sessionId && hwm.SourceUniqueId == SourceId && hwm.Name == Constants.HwmDelta select hwm).First(); Debug.Assert(targetHighWaterMark != null, "Can't find the target side HWM"); targetHighWaterMark.Value = migrationInstructionName; // Prepare to create the conversion history entry (unless a matching one exists) RTMigrationSource migrationSource = (from ms in context.RTMigrationSourceSet where ms.UniqueId.Equals(SourceId) select ms).First(); Debug.Assert(migrationSource != null, "Cannot find the migration source to persist conversion history"); RTMigrationSource deltaSideMigrationSource = (from ms in context.RTMigrationSourceSet where ms.UniqueId.Equals(deltaSideSourceId) select ms).First(); Debug.Assert(deltaSideMigrationSource != null, "Cannot find the migration source to persist conversion history"); // A MigrationItem row may already exist; if so use it bool sourceMigrationItemExists; var sourceItemQuery = (from mi in context.RTMigrationItemSet where mi.MigrationSource.UniqueId.Equals(migrationSource.UniqueId) && mi.ItemId == deltaTableName && mi.ItemVersion == Constants.ChangeGroupGenericVersionNumber select mi); RTMigrationItem sourceItem; if (sourceItemQuery.Count() > 0) { sourceItem = sourceItemQuery.First(); sourceMigrationItemExists = true; } else { sourceItem = RTMigrationItem.CreateRTMigrationItem(0, deltaTableName, Constants.ChangeGroupGenericVersionNumber); sourceItem.MigrationSource = migrationSource; sourceMigrationItemExists = false; } // A MigrationItem row may already exist; if so use it bool targetMigrationItemExists; var targetItemQuery = (from mi in context.RTMigrationItemSet where mi.MigrationSource.UniqueId.Equals(deltaSideMigrationSource.UniqueId) && mi.ItemId == migrationInstructionName && mi.ItemVersion == Constants.ChangeGroupGenericVersionNumber select mi); RTMigrationItem targetItem; if (targetItemQuery.Count() > 0) { targetItem = targetItemQuery.First(); targetMigrationItemExists = true; } else { targetItem = RTMigrationItem.CreateRTMigrationItem(0, migrationInstructionName, Constants.ChangeGroupGenericVersionNumber); targetItem.MigrationSource = deltaSideMigrationSource; targetMigrationItemExists = false; } // If both the source and target migration items exist in the DB, there is no need to create a duplicate conversion // history record, and attempting to do so will cause a constraint violation. if (!sourceMigrationItemExists || !targetMigrationItemExists) { // Create the conversion history entry RTConversionHistory conversionHistory = RTConversionHistory.CreateRTConversionHistory( DateTime.UtcNow, -1, true); conversionHistory.Comment = comment; var session = (from s in context.RTSessionConfigSet where s.SessionUniqueId == sessionId select s).First(); Debug.Assert(session != null, "Cannot find session in DB"); RTSessionRun sessionRun = (from sr in context.RTSessionRunSet where sr.Id == session.Id select sr).First(); Debug.Assert(sessionRun != null, "Cannot find session run in DB"); conversionHistory.SessionRun = sessionRun; conversionHistory.SourceMigrationSource = migrationSource; context.AddToRTConversionHistorySet(conversionHistory); RTItemRevisionPair pair = RTItemRevisionPair.CreateRTItemRevisionPair( sourceItem.Id, targetItem.Id); pair.LeftMigrationItem = sourceItem; pair.RightMigrationItem = targetItem; pair.ConversionHistory = conversionHistory; } // Create a new HistoryNotFoundConflict Resolution Rule context.TrySaveChanges(); } return(true); }