Beispiel #1
0
        internal void SaveChangeGroupActionStatus(LinkChangeGroup linkGroup)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var groupQuery = from g in context.RTLinkChangeGroupSet
                                 where g.Id == linkGroup.InternalId
                                 select g;

                Debug.Assert(groupQuery.First() != null);
                RTLinkChangeGroup rtLinkChangeGroup = groupQuery.First();
                rtLinkChangeGroup.Status = (int)linkGroup.Status;
                rtLinkChangeGroup.ContainsConflictedAction = linkGroup.IsConflicted;

                foreach (LinkChangeAction linkAction in linkGroup.Actions)
                {
                    if (linkAction.InternalId == LinkChangeAction.INVALID_INTERNAL_ID)
                    {
                        throw new InvalidOperationException("Error updating link change action: action is not persisted in DB.");
                    }

                    RTLinkChangeAction rtLinkChangeAction = context.RTLinkChangeActionSet.Where
                                                                (lcg => lcg.Id == linkAction.InternalId).First();

                    rtLinkChangeAction.Status             = (int)linkAction.Status;
                    rtLinkChangeAction.Conflicted         = linkAction.IsConflicted;
                    rtLinkChangeAction.ServerLinkChangeId = linkAction.ServerLinkChangeId;
                }

                context.TrySaveChanges();
            }
        }
Beispiel #2
0
        internal RTLinkChangeGroup AddLinkChangeGroup(LinkChangeGroup group)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var rtLinkChangeGroup = RTLinkChangeGroup.CreateRTLinkChangeGroup(
                    0, (int)group.Status, false, SessionGroupId, SessionId, SourceId);
                rtLinkChangeGroup.GroupName = group.GroupName;
                context.AddToRTLinkChangeGroupSet(rtLinkChangeGroup);

                int newActiveActionCount = 0;
                foreach (LinkChangeAction a in group.Actions)
                {
                    RTLinkChangeAction rtLinkChangeAction = AddChangeAction(a, context);
                    if (rtLinkChangeAction == null)
                    {
                        continue;
                    }

                    rtLinkChangeAction.LinkChangeGroup = rtLinkChangeGroup;
                    ++newActiveActionCount;
                }

                if (newActiveActionCount <= 0)
                {
                    return(null);
                }

                context.TrySaveChanges();
                group.InternalId = rtLinkChangeGroup.Id;
                context.Detach(rtLinkChangeGroup);
                return(rtLinkChangeGroup);
            }
        }
Beispiel #3
0
        internal LinkChangeAction LoadSingleLinkChangeAction(long actionId)
        {
            Debug.Assert(actionId != LinkChangeAction.INVALID_INTERNAL_ID && actionId > 0);

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var linkChangeActionQuery =
                    from a in context.RTLinkChangeActionSet
                    where a.Id == actionId
                    select a;

                if (linkChangeActionQuery.Count() != 1)
                {
                    return(null);
                }

                linkChangeActionQuery.First().LinkChangeGroupReference.Load();
                RTLinkChangeGroup linkChangeGroup = linkChangeActionQuery.First().LinkChangeGroup;
                Debug.Assert(null != linkChangeGroup);
                var group = new LinkChangeGroup(linkChangeGroup.GroupName,
                                                (LinkChangeGroup.LinkChangeGroupStatus)linkChangeGroup.Status,
                                                linkChangeGroup.ContainsConflictedAction,
                                                linkChangeGroup.Id,
                                                linkChangeGroup.Age ?? 0,
                                                linkChangeGroup.RetriesAtCurrAge ?? 0);
                return(RealizeLinkChangeActionFromEDM(group, linkChangeActionQuery.First()));
            }
        }
 /// <summary>
 /// Batch saves status changes of the change group and its actions
 /// </summary>
 /// <param name="group"></param>
 public void SaveChangeGroupActionStatus(LinkChangeGroup group)
 {
     if (group.InternalId == LinkChangeGroup.INVALID_INTERNAL_ID)
     {
         throw new InvalidOperationException("Error updating link change group: Group is not persisted in DB.");
     }
     m_linkChangeGroupManager.SaveChangeGroupActionStatus(group);
 }
Beispiel #5
0
 public LinkChangeAction(
     Guid changeActionId,
     ILink link,
     LinkChangeActionStatus status,
     bool isConflicted,
     int executionOrder,
     LinkChangeGroup group)
 {
     Initialize(changeActionId, link, status, isConflicted, executionOrder, group, INVALID_INTERNAL_ID);
 }
Beispiel #6
0
        internal ReadOnlyCollection <LinkChangeGroup> GetPagedLinkChangeGroups(
            long firstGroupId,
            int pageSize,
            LinkChangeGroup.LinkChangeGroupStatus status,
            bool?getConflictedGroup,
            int maxAge,
            out long lastGroupId)
        {
            lastGroupId = firstGroupId - 1;
            var linkChangeGroups = new List <LinkChangeGroup>();
            int statusVal        = (int)status;

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var linkGroupQuery = getConflictedGroup.HasValue
                                     ? (from g in context.RTLinkChangeGroupSet
                                        where g.Status == statusVal &&
                                        g.ContainsConflictedAction == getConflictedGroup &&
                                        g.SessionGroupUniqueId.Equals(SessionGroupId) &&
                                        g.SessionUniqueId.Equals(SessionId) &&
                                        g.SourceId.Equals(SourceId) &&
                                        (g.Age == null || g.Age.Value <= maxAge) &&
                                        g.Id >= firstGroupId
                                        orderby g.Id
                                        select g).Take(pageSize)
                                     : (from g in context.RTLinkChangeGroupSet
                                        where g.Status == statusVal &&
                                        g.SessionGroupUniqueId.Equals(SessionGroupId) &&
                                        g.SessionUniqueId.Equals(SessionId) &&
                                        g.SourceId.Equals(SourceId) &&
                                        (g.Age == null || g.Age.Value <= maxAge) &&
                                        g.Id >= firstGroupId
                                        orderby g.Id
                                        select g).Take(pageSize);

                foreach (RTLinkChangeGroup rtLinkChangeGroup in linkGroupQuery)
                {
                    var group = new LinkChangeGroup(rtLinkChangeGroup.GroupName,
                                                    status,
                                                    rtLinkChangeGroup.ContainsConflictedAction,
                                                    rtLinkChangeGroup.Id,
                                                    rtLinkChangeGroup.Age ?? 0,
                                                    rtLinkChangeGroup.RetriesAtCurrAge ?? 0);
                    group.IsForcedSync = rtLinkChangeGroup.IsForcedSync.HasValue ? (bool)rtLinkChangeGroup.IsForcedSync : false;

                    GetLinkChangeActions(group, context);
                    linkChangeGroups.Add(group);

                    lastGroupId = rtLinkChangeGroup.Id;
                }
            }

            return(linkChangeGroups.AsReadOnly());
        }
Beispiel #7
0
        private LinkChangeAction RealizeLinkChangeActionFromEDM(LinkChangeGroup linkChangeGroup, RTLinkChangeAction rtLinkChangeAction)
        {
            rtLinkChangeAction.ArtifactLinkReference.Load();
            ILink artifactLink = RealizeArtifactLinkFromEDM(rtLinkChangeAction.ArtifactLink);

            var linkChangeAction = new LinkChangeAction(rtLinkChangeAction.ActionId, artifactLink, (LinkChangeAction.LinkChangeActionStatus)rtLinkChangeAction.Status,
                                                        rtLinkChangeAction.Conflicted, rtLinkChangeAction.ExecutionOrder ?? 0, linkChangeGroup,
                                                        rtLinkChangeAction.Id);

            return(linkChangeAction);
        }
        public bool ContainsSpecialSkipActions(LinkChangeGroup changeGroup)
        {
            foreach (LinkChangeAction action in changeGroup.Actions)
            {
                if (action.Status == LinkChangeAction.LinkChangeActionStatus.SkipScopedOutVCLinks ||
                    action.Status == LinkChangeAction.LinkChangeActionStatus.SkipScopedOutWILinks)
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool ChangeGroupIsCompleted(LinkChangeGroup changeGroup)
        {
            foreach (LinkChangeAction action in changeGroup.Actions)
            {
                if (action.Status != LinkChangeAction.LinkChangeActionStatus.Skipped &&
                    action.Status != LinkChangeAction.LinkChangeActionStatus.Completed &&
                    action.Status != LinkChangeAction.LinkChangeActionStatus.DeltaCompleted)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #10
0
 internal LinkChangeAction(
     Guid changeActionId,
     ILink link,
     LinkChangeActionStatus status,
     bool isConflicted,
     int executionOrder,
     LinkChangeGroup group,
     long internalId)
 {
     if (internalId <= 0)
     {
         throw new ArgumentOutOfRangeException("internalId", "internalId must be a positive integer");
     }
     Initialize(changeActionId, link, status, isConflicted, executionOrder, group, internalId);
 }
Beispiel #11
0
        private void GetLinkChangeActions(LinkChangeGroup linkChangeGroup, RuntimeEntityModel context)
        {
            int skippedWILinkValue = LinkChangeAction.GetStatusStorageValue(LinkChangeAction.LinkChangeActionStatus.SkipScopedOutWILinks);
            int skippedVCLinkValue = LinkChangeAction.GetStatusStorageValue(LinkChangeAction.LinkChangeActionStatus.SkipScopedOutVCLinks);
            var changeActionQuery  = from a in context.RTLinkChangeActionSet
                                     where a.LinkChangeGroup.Id == linkChangeGroup.InternalId &&
                                     a.Status != skippedVCLinkValue &&
                                     a.Status != skippedWILinkValue
                                     select a;

            foreach (RTLinkChangeAction rtLinkChangeAction in changeActionQuery)
            {
                if (rtLinkChangeAction.SourceId.Equals(SourceId))
                {
                    linkChangeGroup.AddChangeAction(RealizeLinkChangeActionFromEDM(linkChangeGroup, rtLinkChangeAction));
                }
            }
        }
Beispiel #12
0
        private bool AllActionsTranslated(LinkChangeGroup linkChangeGroup)
        {
            foreach (LinkChangeAction action in linkChangeGroup.Actions)
            {
                switch (action.Status)
                {
                case LinkChangeAction.LinkChangeActionStatus.Created:
                case LinkChangeAction.LinkChangeActionStatus.SkipScopedOutVCLinks:
                case LinkChangeAction.LinkChangeActionStatus.SkipScopedOutWILinks:
                    if (action.IsConflicted)
                    {
                        linkChangeGroup.IsConflicted = true;
                    }
                    return(false);

                default:
                    continue;
                }
            }

            return(true);
        }
Beispiel #13
0
        private void Initialize(
            Guid changeActionId,
            ILink link,
            LinkChangeActionStatus status,
            bool isConflicted,
            int executionOrder,
            LinkChangeGroup group,
            long internalId)
        {
            if (null == link)
            {
                throw new ArgumentNullException("link");
            }

            ChangeActionId = changeActionId;
            Link           = link;
            Status         = status;
            IsConflicted   = isConflicted;
            InternalId     = internalId;
            ExecutionOrder = executionOrder;
            Group          = group;
        }
        public bool AllLinkMigrationInstructionsAreConflicted(LinkChangeGroup changeGroup)
        {
            bool allMigrationInstructionAreConflicted   = true;
            bool containsConflictedMigrationInstruction = false;

            foreach (LinkChangeAction action in changeGroup.Actions)
            {
                if (action.Status == LinkChangeAction.LinkChangeActionStatus.ReadyForMigration)
                {
                    if (action.IsConflicted)
                    {
                        containsConflictedMigrationInstruction = true;
                    }
                    else
                    {
                        allMigrationInstructionAreConflicted = false;
                        break;
                    }
                }
            }

            return(allMigrationInstructionAreConflicted & containsConflictedMigrationInstruction);
        }
Beispiel #15
0
        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);
            }
        }