private void populateMetaData(RTChangeGroup runtimeChangeGroup) { runtimeChangeGroup.Owner = Owner; runtimeChangeGroup.Comment = Comment; runtimeChangeGroup.ExecutionOrder = ExecutionOrder; runtimeChangeGroup.UsePagedActions = m_usePagedActions; }
protected override void Update() { if (m_usePagedActions) { PagedCollection <IMigrationAction> pagedActions = this.Actions as PagedCollection <IMigrationAction>; pagedActions.SaveActivePage(); } using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { RTChangeGroup rtChangeGroupCache = context.GetObjectByKey(m_runTimeChangeGroup.EntityKey) as RTChangeGroup; switch (Status) { case ChangeStatus.InProgress: rtChangeGroupCache.StartTime = DateTime.UtcNow; break; case ChangeStatus.DeltaComplete: case ChangeStatus.Complete: rtChangeGroupCache.FinishTime = DateTime.UtcNow; break; default: break; } rtChangeGroupCache.Status = (int)Status; rtChangeGroupCache.ReflectedChangeGroupId = ReflectedChangeGroupId; populateMetaData(rtChangeGroupCache); context.TrySaveChanges(); } }
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); }
private void SavePartialChangeGroup() { if (null != m_runTimeChangeGroup) { return; } SqlChangeGroupManager manager = this.Manager as SqlChangeGroupManager; Debug.Assert(null != manager, "Manager is not a SqlChangeGroupManager for SqlChangeGroup"); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { try { context.Attach(manager.RunTimeMigrationSource); context.Attach(manager.RuntimeSessionRun); // save group attributes m_runTimeChangeGroup = RTChangeGroup.CreateRTChangeGroup(-1, ExecutionOrder, SessionId, SourceId, (int)ChangeStatus.ChangeCreationInProgress, false); m_runTimeChangeGroup.Owner = Owner; m_runTimeChangeGroup.Comment = Comment; // Store the ChangeTimeUtc value in the RevsionTime column unless the ChangeTimeUtc is not set (MinValue) // If it's not set, store DateTime.MaxValue to indicate that because DateTime.MinValue is outside the range allowed by SQL m_runTimeChangeGroup.RevisionTime = ChangeTimeUtc.Equals(DateTime.MinValue) ? DateTime.MaxValue : ChangeTimeUtc; m_runTimeChangeGroup.StartTime = DateTime.UtcNow; m_runTimeChangeGroup.Name = Name; m_runTimeChangeGroup.ReflectedChangeGroupId = ReflectedChangeGroupId; m_runTimeChangeGroup.UsePagedActions = m_usePagedActions; m_runTimeChangeGroup.IsForcedSync = IsForcedSync; // establish SessionRun association m_runTimeChangeGroup.SessionRun = manager.RuntimeSessionRun; // estabilish MigrationSource association m_runTimeChangeGroup.SourceSideMigrationSource = manager.RunTimeMigrationSource; // save the group context.AddToRTChangeGroupSet(m_runTimeChangeGroup); context.TrySaveChanges(); // record internal Id this.ChangeGroupId = m_runTimeChangeGroup.Id; } finally { context.Detach(m_runTimeChangeGroup); context.Detach(manager.RunTimeMigrationSource); context.Detach(manager.RuntimeSessionRun); } } }
public SqlChangeGroupProvider( RTChangeGroup runtimeChangeGroup, SqlChangeGroupManager parentSqlChangeGroupManager) { if (null == runtimeChangeGroup) { throw new ArgumentNullException("runtimeChangeGroup"); } m_runtimeChangeGroup = runtimeChangeGroup; m_sqlChangeGroupManager = parentSqlChangeGroupManager; }
private void SavePartialChangeGroup() { if (null != m_runTimeChangeGroup) { return; } SqlChangeGroupManager manager = this.Manager as SqlChangeGroupManager; Debug.Assert(null != manager, "Manager is not a SqlChangeGroupManager for SqlChangeGroup"); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { try { context.Attach(manager.RunTimeMigrationSource); context.Attach(manager.RuntimeSessionRun); // save group attributes m_runTimeChangeGroup = RTChangeGroup.CreateRTChangeGroup(-1, ExecutionOrder, SessionId, SourceId, (int)ChangeStatus.ChangeCreationInProgress, false); m_runTimeChangeGroup.Owner = Owner; m_runTimeChangeGroup.Comment = Comment; m_runTimeChangeGroup.RevisionTime = RevisionTime; m_runTimeChangeGroup.StartTime = DateTime.UtcNow; m_runTimeChangeGroup.Name = Name; m_runTimeChangeGroup.ReflectedChangeGroupId = ReflectedChangeGroupId; m_runTimeChangeGroup.UsePagedActions = m_usePagedActions; // establish SessionRun association m_runTimeChangeGroup.SessionRun = manager.RuntimeSessionRun; // estabilish MigrationSource association m_runTimeChangeGroup.SourceSideMigrationSource = manager.RunTimeMigrationSource; // save the group context.AddToRTChangeGroupSet(m_runTimeChangeGroup); context.TrySaveChanges(); // record internal Id this.ChangeGroupId = m_runTimeChangeGroup.Id; } finally { context.Detach(m_runTimeChangeGroup); context.Detach(manager.RunTimeMigrationSource); context.Detach(manager.RuntimeSessionRun); } } }
public override ReadOnlyCollection <KeyValuePair <MigrationAction, MigrationAction> > DetectContentConflict() { List <KeyValuePair <MigrationAction, MigrationAction> > conflictActions = new List <KeyValuePair <MigrationAction, MigrationAction> >(); Dictionary <long, SqlChangeGroup> loadedChangeGroups = new Dictionary <long, SqlChangeGroup>(); using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { foreach (VCContentConflictResult contentConflictResults in context.QueryContentConflict(SourceId, new Guid(Session.SessionUniqueId))) { RTChangeAction migrationInstructionAction = context.RTChangeActionSet.Where(a => a.ChangeActionId == contentConflictResults.MigrationInstructionChangeActionId).First(); RTChangeAction deltaAction = context.RTChangeActionSet.Where(a => a.ChangeActionId == contentConflictResults.DeltaChangeActionId).First(); SqlMigrationAction conflictActionSource = SqlMigrationAction.RealizeFromDB(migrationInstructionAction); if (loadedChangeGroups.ContainsKey(migrationInstructionAction.ChangeGroupId)) { conflictActionSource.ChangeGroup = loadedChangeGroups[migrationInstructionAction.ChangeGroupId]; } else { RTChangeGroup migrationInstructionChangeGroup = context.RTChangeGroupSet.Where(c => c.Id == migrationInstructionAction.ChangeGroupId).First(); SqlChangeGroup conflictChangeGroupSource = new SqlChangeGroup(this); conflictChangeGroupSource.RealizeFromEDMWithSingleAction(migrationInstructionChangeGroup, migrationInstructionAction); loadedChangeGroups.Add(migrationInstructionAction.ChangeGroupId, conflictChangeGroupSource); conflictActionSource.ChangeGroup = conflictChangeGroupSource; } SqlMigrationAction conflictActionTarget = SqlMigrationAction.RealizeFromDB(deltaAction); if (loadedChangeGroups.ContainsKey(deltaAction.ChangeGroupId)) { conflictActionTarget.ChangeGroup = loadedChangeGroups[deltaAction.ChangeGroupId]; } else { RTChangeGroup deltaChangeGroup = context.RTChangeGroupSet.Where(c => c.Id == deltaAction.ChangeGroupId).First(); SqlChangeGroup conflictChangeGroupTarget = new SqlChangeGroup(this); conflictChangeGroupTarget.RealizeFromEDMWithSingleAction(deltaChangeGroup, deltaAction); loadedChangeGroups.Add(deltaAction.ChangeGroupId, conflictChangeGroupTarget); conflictActionTarget.ChangeGroup = conflictChangeGroupTarget; } conflictActions.Add(new KeyValuePair <MigrationAction, MigrationAction>(conflictActionSource, conflictActionTarget)); } } return(conflictActions.AsReadOnly()); }
public void RealizeFromEDM( RTChangeGroup runTimeChangeGroup) { RealizeChangeGroupProperties(runTimeChangeGroup); if (!m_usePagedActions) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { // load actions proactively only when the use-paged-action threshold is not reached foreach (RTChangeAction runTimeChangeAction in context.LoadChangeAction(this.ChangeGroupId)) { RealizeSingleActionFromEDM(runTimeChangeAction); } } } }
private void RealizeChangeGroupProperties(RTChangeGroup runTimeChangeGroup) { this.m_runTimeChangeGroup = runTimeChangeGroup; this.ChangeGroupId = runTimeChangeGroup.Id; this.ChangeTimeUtc = (DateTime)runTimeChangeGroup.StartTime; this.Comment = runTimeChangeGroup.Comment; this.RevisionTime = runTimeChangeGroup.RevisionTime; this.ExecutionOrder = runTimeChangeGroup.ExecutionOrder; this.Locked = false; this.Name = runTimeChangeGroup.Name; this.Owner = runTimeChangeGroup.Owner; this.SessionId = runTimeChangeGroup.SessionUniqueId; this.SourceId = runTimeChangeGroup.SourceUniqueId; this.Status = (ChangeStatus)runTimeChangeGroup.Status; this.ContainsBackloggedAction = runTimeChangeGroup.ContainsBackloggedAction; this.m_usePagedActions = (runTimeChangeGroup.UsePagedActions.HasValue && runTimeChangeGroup.UsePagedActions.Value); }
public DualChangeGroupViewModel(RTChangeGroup deltaTables, RTChangeGroup migrationInstructions, int count) { Name = deltaTables.Name; DeltaTables = deltaTables; MigrationInstructions = migrationInstructions; ChangeActionCount = count; IsMilestone = false; m_context = RuntimeEntityModel.CreateInstance(); RuntimeManager host = RuntimeManager.GetInstance(); IRefreshService refresh = (IRefreshService)host.GetService(typeof(IRefreshService)); refresh.AutoRefresh += this.AutoRefresh; Refresh(); m_deltaTablesStatus = (ChangeStatus)DeltaTables.Status; m_migrationInstructionsStatus = (ChangeStatus)MigrationInstructions.Status; }
internal void PersistCurrentStatus(RuntimeEntityModel context) { RTChangeGroup rtChangeGroupCache = context.GetObjectByKey(m_runTimeChangeGroup.EntityKey) as RTChangeGroup; switch (Status) { case ChangeStatus.InProgress: rtChangeGroupCache.StartTime = DateTime.UtcNow; break; case ChangeStatus.DeltaComplete: case ChangeStatus.Complete: rtChangeGroupCache.FinishTime = DateTime.UtcNow; break; default: break; } rtChangeGroupCache.Status = (int)Status; }
public IMigrationAction RealizeFromEDMWithSingleAction(RTChangeGroup runTimeChangeGroup, RTChangeAction runTimeChangeAction) { RealizeChangeGroupProperties(runTimeChangeGroup); UseOtherSideMigrationItemSerializers = true; switch (Status) { case ChangeStatus.ChangeCreationInProgress: case ChangeStatus.Delta: case ChangeStatus.DeltaComplete: case ChangeStatus.DeltaPending: case ChangeStatus.DeltaSynced: UseOtherSideMigrationItemSerializers = false; break; default: break; } return(RealizeSingleActionFromEDM(runTimeChangeAction)); }
private RTSession FindSessionForConflictedAction( MigrationConflict conflict, RuntimeEntityModel context) { // figure out which session the conflicted change action belongs to Guid sessionId = Guid.Empty; if (conflict.ConflictedChangeAction.ChangeGroup == null) { RTChangeGroup rtChangeGroup = FindChangeGroupForConflictedAction(conflict, context); if (null != rtChangeGroup) { sessionId = rtChangeGroup.SessionUniqueId; } } else { sessionId = conflict.ConflictedChangeAction.ChangeGroup.SessionId; } if (sessionId.Equals(Guid.Empty)) { Debug.Assert(false, "cannot find session for the conflicted action"); return(null); } var sessionQuery = context.RTSessionSet.Where(s => s.SessionUniqueId.Equals(sessionId)); if (sessionQuery.Count() > 0) { return(sessionQuery.First()); } else { return(null); } }
/// <summary> /// Discard a migration instruction change group and reactivate the corresponding delta table entry /// </summary> /// <param name="migrationInstructionEntry"></param> /// <returns>The corresponding delta table entry</returns> internal override ChangeGroup DiscardMigrationInstructionAndReactivateDelta(ChangeGroup migrationInstructionEntry) { Debug.Assert(migrationInstructionEntry.ReflectedChangeGroupId.HasValue, "migrationInstructionEntry.ReflectedChangeGroupId does not have value"); RTChangeGroup rtChangeGroup = null; using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { long migrInstrId = migrationInstructionEntry.ChangeGroupId; var migrInstr = context.RTChangeGroupSet.Where(g => g.Id == migrInstrId); long deltaId = migrationInstructionEntry.ReflectedChangeGroupId.Value; var delta = context.RTChangeGroupSet.Where(g => g.Id == deltaId); if (migrInstr.Count() != 1 || delta.Count() != 1) { return(null); } migrInstr.First().Status = (int)ChangeStatus.Obsolete; rtChangeGroup = delta.First(); rtChangeGroup.Status = (int)ChangeStatus.DeltaPending; context.TrySaveChanges(); context.Detach(rtChangeGroup); } SqlChangeGroup changeGroup = new SqlChangeGroup(this); changeGroup.UseOtherSideMigrationItemSerializers = true; changeGroup.RealizeFromEDM(rtChangeGroup); return(changeGroup); }
public ChangeGroupViewModel(RTChangeGroup changeGroup) { m_changeGroup = changeGroup; m_host = RuntimeManager.GetInstance(); }
/// <summary> /// bulk save sliced child change actions /// </summary> /// <param name="page">a page/slice of child change actions</param> internal void BatchSaveChangeActions(IList <IMigrationAction> page) { Debug.Assert(m_runTimeChangeGroup != null); const int bulkChangeActionInsertionSize = 1000; int changeActionCount = 0; int pageIndex = 0; while (pageIndex < page.Count) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { RTChangeGroup rtChangeGroupCache = getNativeRTChangeGroup(context); Debug.Assert(null != rtChangeGroupCache); while (pageIndex < page.Count && changeActionCount < bulkChangeActionInsertionSize) { SqlMigrationAction action = page[pageIndex] as SqlMigrationAction; Debug.Assert(null != action); // cache "Dirty" flag, as assignin 'this' to its ChangeGroup will set the flag to true bool actionWasDirty = action.IsDirty; action.ChangeGroup = this; if (!action.IsPersisted) { IMigrationItemSerializer serializer = ManagerWithMigrationItemSerializers[action.Action]; action.CreateNew(serializer); context.AddToRTChangeActionSet(action.RTChangeAction); action.RTChangeAction.ChangeGroup = rtChangeGroupCache; ++changeActionCount; } else if (actionWasDirty) { IMigrationItemSerializer serializer = ManagerWithMigrationItemSerializers[action.Action]; RTChangeAction rtChangeAction = action.RTChangeAction; if (null != rtChangeAction) { rtChangeAction = context.GetObjectByKey(rtChangeAction.EntityKey) as RTChangeAction; } else { rtChangeAction = context.RTChangeActionSet.Where(ca => ca.ChangeActionId == action.ActionId).First(); } rtChangeAction.Recursivity = action.Recursive; rtChangeAction.IsSubstituted = action.State == ActionState.Skipped ? true : false; rtChangeAction.ActionId = action.Action; rtChangeAction.SourceItem = serializer.SerializeItem(action.SourceItem); rtChangeAction.ToPath = action.Path; rtChangeAction.ItemTypeReferenceName = action.ItemTypeReferenceName; rtChangeAction.FromPath = action.FromPath; rtChangeAction.Version = action.Version; rtChangeAction.MergeVersionTo = action.MergeVersionTo; if (action.MigrationActionDescription != null && action.MigrationActionDescription.DocumentElement != null) { rtChangeAction.ActionData = action.MigrationActionDescription.DocumentElement.OuterXml; } ++changeActionCount; } ++pageIndex; } context.TrySaveChanges(); changeActionCount = 0; } } }