Esempio n. 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();
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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()));
            }
        }
Esempio n. 4
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);
            }
        }