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); } } }
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); } } }
protected override void Create() { // ToDo ChangeStatus targetStatus = Status; SqlChangeGroupManager manager = this.Manager as SqlChangeGroupManager; Debug.Assert(null != manager, "Manager is not a SqlChangeGroupManager for SqlChangeGroup"); // save the group (without child actions) SavePartialChangeGroup(); // bulk save sliced child change actions const int bulkChangeActionInsertionSize = 1000; int changeActionCount = 0; while (Actions.Count > 0) { using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { try { context.Attach(m_runTimeChangeGroup); while (Actions.Count > 0 && changeActionCount < bulkChangeActionInsertionSize) { SqlMigrationAction action = Actions[0] as SqlMigrationAction; Debug.Assert(null != action); action.ChangeGroup = this; IMigrationItemSerializer serializer = ManagerWithMigrationItemSerializers[action.Action]; action.CreateNew(serializer); action.RTChangeAction.ChangeGroup = m_runTimeChangeGroup; // Remove processed child change actions. // When this ObjectModel context is disposed, // the RTChangeAction will be disposed as well. Actions.RemoveAt(0); ++changeActionCount; } context.TrySaveChanges(); } finally { context.Detach(m_runTimeChangeGroup); } } changeActionCount = 0; } // update group status in DB using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance()) { try { context.Attach(m_runTimeChangeGroup); m_runTimeChangeGroup.Status = (int)targetStatus; m_runTimeChangeGroup.UsePagedActions = m_usePagedActions; context.TrySaveChanges(); } finally { context.Detach(m_runTimeChangeGroup); } } }
private void SaveLinkChangeGroupTranslationResult(LinkChangeGroup linkChangeGroup, RuntimeEntityModel context) { Debug.Assert(linkChangeGroup.InternalId != LinkChangeGroup.INVALID_INTERNAL_ID); var linkChangeGroupQuery = from g in context.RTLinkChangeGroupSet where g.Id == linkChangeGroup.InternalId select g; Debug.Assert(linkChangeGroupQuery.Count() == 1); RTLinkChangeGroup rtLinkChangeGroup = linkChangeGroupQuery.First(); // update the source side link change group status rtLinkChangeGroup.Status = (int)linkChangeGroup.Status; if (linkChangeGroup.Status == LinkChangeGroup.LinkChangeGroupStatus.InAnalysisDeferred) { // if the link change group cannot be translated in the current run // we check the number of translation attemps that have been made at the group's current age // if it has reached the max number of retries allowed for this age, we increment its age and reset the retry count rtLinkChangeGroup.RetriesAtCurrAge = rtLinkChangeGroup.RetriesAtCurrAge ?? 0; rtLinkChangeGroup.Age = rtLinkChangeGroup.Age ?? 0; if (++rtLinkChangeGroup.RetriesAtCurrAge >= LinkEngine.AgeInterveralSecAndRetries[rtLinkChangeGroup.Age.Value, 1]) { rtLinkChangeGroup.Age++; rtLinkChangeGroup.RetriesAtCurrAge = 0; } } // identify translated actions in the group List <LinkChangeAction> translatedActions = new List <LinkChangeAction>(); foreach (LinkChangeAction action in linkChangeGroup.Actions) { if (action.Status == LinkChangeAction.LinkChangeActionStatus.Translated) { translatedActions.Add(action); UpdateLinkChangeActionStatus(action.InternalId, LinkChangeAction.LinkChangeActionStatus.DeltaCompleted, context); } else { UpdateLinkChangeActionStatus(action.InternalId, action.Status, context); } } if (AllActionsTranslated(linkChangeGroup)) { // mark group completed when all its actions are successfully translated rtLinkChangeGroup.Status = (int)LinkChangeGroup.LinkChangeGroupStatus.Completed; } else { rtLinkChangeGroup.ContainsConflictedAction = linkChangeGroup.IsConflicted; } // move the translated actions to the target side (current side) and create a new group to store them LinkChangeGroup translatedGroup = new LinkChangeGroup( linkChangeGroup.GroupName, LinkChangeGroup.LinkChangeGroupStatus.InAnalysisTranslated, false); foreach (LinkChangeAction action in translatedActions) { action.InternalId = LinkChangeAction.INVALID_INTERNAL_ID; translatedGroup.AddChangeAction(action); } RTLinkChangeGroup rtLinkChangeGroupTranslated = AddLinkChangeGroup(translatedGroup); if (rtLinkChangeGroupTranslated != null) { context.Attach(rtLinkChangeGroupTranslated); } }