示例#1
0
        /// <summary>
        /// Mark all commands as processed for a particular session group.
        /// </summary>
        /// <remarks>
        /// This method is called immediately before a session group is started. If the previous session run crashed,
        /// leaving some "processing" or "active" commands in the queue, this method is expected to clean them up.
        /// </remarks>
        /// <param name="sessionGroupId">The GUID that's used as the unique Id of the subject session group.</param>
        public void ClearUpUnprocessedCommand(Guid sessionGroupId)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                int newStateValue        = (int)PipelineSyncCommandState.New;
                int processingStateValue = (int)PipelineSyncCommandState.Processing;

                var cmdQuery = from c in context.RTOrchestrationCommandSet
                               where (c.Status == newStateValue || c.Status == processingStateValue) &&
                               c.SessionGroup.GroupUniqueId.Equals(sessionGroupId)
                               orderby c.Id
                               select c;

                if (cmdQuery.Count() == 0)
                {
                    return;
                }

                foreach (var cmd in cmdQuery)
                {
                    cmd.Status = (int)PipelineSyncCommandState.Processed;
                }

                context.TrySaveChanges();
            }
        }
示例#2
0
        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);
        }
示例#3
0
        internal IQueryable <RTConflict> GetActiveConflicts(Guid sessionGroupUniqueId)
        {
            RuntimeEntityModel context = RuntimeEntityModel.CreateInstance();

            // hidden conflicts
            Guid chainOnBackloggedItemConflictTypeRefName = new ChainOnBackloggedItemConflictType().ReferenceName; // A7EFC8C6-A6CF-45e7-BFA6-471942A54F37
            Guid chainOnConflictConflictTypeRefName       = Constants.chainOnConflictConflictTypeRefName;          //F6BFB484-EE70-4ffc-AAB3-4F659B0CAF7F

            // runtime conflicts
            Guid witGeneralConflictTypeRefName = Constants.witGeneralConflictTypeRefName; //470F9617-FC96-4166-96EB-44CC2CF73A97
            Guid generalConflictTypeRefName    = new GenericConflictType().ReferenceName; // F6DAB314-2792-40D9-86CC-B40F5B827D86

            var conflictQuery =
                from c in context.RTConflictSet
                where (c.InCollection.SessionGroupRun.Config.SessionGroup.GroupUniqueId.Equals(sessionGroupUniqueId) ||
                       c.InCollection.SessionRun.SessionGroupRun.Config.SessionGroup.GroupUniqueId.Equals(sessionGroupUniqueId)) &&
                c.Status == 0 && // only search for active conflicts
                !c.ConflictType.ReferenceName.Equals(chainOnBackloggedItemConflictTypeRefName) &&
                !c.ConflictType.ReferenceName.Equals(chainOnConflictConflictTypeRefName) &&
                !c.ConflictType.ReferenceName.Equals(witGeneralConflictTypeRefName) &&
                !c.ConflictType.ReferenceName.Equals(generalConflictTypeRefName)
                select c;

            return(conflictQuery);
        }
示例#4
0
        private void MarkSessionRunning()
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var sessionQuery = context.RTSessionSet.Where
                                       (s => s.SessionUniqueId.Equals(SessionId));
                Debug.Assert(sessionQuery.Count() == 1);

                // we want to keep StartedInStandaloneProcess session status untouched
                if (sessionQuery.First().State != (int)BusinessModelManager.SessionStateEnum.StartedInStandaloneProcess)
                {
                    sessionQuery.First().State = (int)BusinessModelManager.SessionStateEnum.Running;
                }
                context.TrySaveChanges();
            }

            if (m_syncStateMachine.TryTransit(PipelineSyncCommand.START))
            {
                m_syncStateMachine.CommandTransitFinished(PipelineSyncCommand.START);
            }
            else
            {
                throw new MigrationException();
            }
        }
        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);
                }
            }
        }
示例#6
0
        public bool IsActionInDelta(LinkChangeAction linkChangeAction)
        {
            ILink link = linkChangeAction.Link;

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var duplicateActionInDelta = context.FindLinkChangeActionInDelta(
                    SessionGroupId,
                    SessionId,
                    SourceId,
                    linkChangeAction.ChangeActionId,
                    link.SourceArtifactId,
                    link.SourceArtifact.Uri,
                    link.TargetArtifact.Uri,
                    link.Comment,
                    link.LinkType.ReferenceName,
                    link.LinkType.FriendlyName,
                    GetExtendedPropertyString(link),
                    link.LinkType.SourceArtifactType.ReferenceName,
                    link.LinkType.SourceArtifactType.FriendlyName,
                    link.LinkType.SourceArtifactType.ContentTypeReferenceName,
                    link.LinkType.TargetArtifactType.ReferenceName,
                    link.LinkType.TargetArtifactType.FriendlyName,
                    link.LinkType.TargetArtifactType.ContentTypeReferenceName);

                return(duplicateActionInDelta.Count() > 0);
            }
        }
        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();
            }
        }
示例#8
0
        public override Interfaces.ICommandResult Run()
        {
            try
            {
                MigrationServiceClient serviceClient          = new MigrationServiceClient();
                List <Guid>            runningSessionGroupIds = serviceClient.GetRunningSessionGroups();

                Dictionary <Guid, string> sessionGroupDescription = new Dictionary <Guid, string>();
                using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
                {
                    foreach (var sessionGroupId in runningSessionGroupIds)
                    {
                        var sessionGroupQuery = context.RTSessionGroupSet.Where(g => g.GroupUniqueId == sessionGroupId);
                        if (sessionGroupQuery.Count() > 0)
                        {
                            sessionGroupDescription[sessionGroupId] = sessionGroupQuery.First().FriendlyName ?? string.Empty;
                        }
                    }
                }

                return(new StatusRslt(sessionGroupDescription, this));
            }
            catch (MigrationServiceEndpointNotFoundException)
            {
                return(new StatusRslt(ResourceStrings.IntegrationServiceNotRunningInfo, this, true));
            }
            catch (Exception e)
            {
                return(new StatusRslt(e.Message, this, false));
            }
        }
示例#9
0
        public void ValidateAndSaveProviderConflictRegistration(int providerInternalId)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                RTProvider providerCache = (from p in context.RTProviderSet
                                            where p.Id == providerInternalId
                                            select p).First();
                Debug.Assert(null != providerCache, "null == providerCache");
                Guid providerReferenceName = providerCache.ReferenceName;

                List <ConflictType> unsavedTypes  = new List <ConflictType>(this.RegisteredConflictTypes.Count);
                bool validateToolkitConflictTypes = providerReferenceName.Equals(Constants.FrameworkSourceId);
                if (validateToolkitConflictTypes)
                {
                    foreach (var c in this.RegisteredToolkitConflictTypes)
                    {
                        unsavedTypes.Add(c.Value);
                    }
                }
                else
                {
                    foreach (var c in this.RegisteredConflictTypes)
                    {
                        if (!this.RegisteredToolkitConflictTypes.ContainsKey(c.Key))
                        {
                            unsavedTypes.Add(c.Value);
                        }
                    }
                }
                ValidateSaveConflictType(context, providerReferenceName, providerCache, unsavedTypes, validateToolkitConflictTypes);
                ValidateSaveResolutionAction(context, providerReferenceName, providerCache, unsavedTypes, validateToolkitConflictTypes);

                context.TrySaveChanges();
            }
        }
示例#10
0
        /// <summary>
        /// Returns a SyncPoint object containg data about the last migrated items for the
        /// last time one direction of a sync or migration operation completed
        /// </summary>
        /// <param name="session">A Session object</param>
        /// <returns>A SyncPoint object or null if there have been no sync points completed for the specified session</returns>
        public static List <SyncPoint> GetSyncPointsForDiff(Session session, Guid leftMigrationSourceId, Guid rightMigrationSourceId)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                List <SyncPoint> syncPointList = new List <SyncPoint>();

                foreach (Guid migrationSourceGuid in new Guid[] { leftMigrationSourceId, rightMigrationSourceId })
                {
                    Guid sessionGuid    = new Guid(session.SessionUniqueId);
                    var  syncPointQuery =
                        (from sp in context.RTSyncPointSet
                         where (sp.SessionUniqueId == sessionGuid && sp.SourceUniqueId == migrationSourceGuid)
                         orderby sp.Id descending
                         select sp).Take(1);

                    if (syncPointQuery.Count() > 0)
                    {
                        RTSyncPoint rtSyncPoint = syncPointQuery.First();
                        SyncPoint   syncPoint   = new SyncPoint();
                        syncPoint.SourceMigrationSourceId       = rtSyncPoint.SourceUniqueId;
                        syncPoint.SourceHighWaterMarkName       = rtSyncPoint.SourceHighWaterMarkName;
                        syncPoint.SourceHighWaterMarkValue      = rtSyncPoint.SourceHighWaterMarkValue;
                        syncPoint.LastMigratedTargetItemId      = rtSyncPoint.LastMigratedTargetItemId;
                        syncPoint.LastMigratedTargetItemVersion = rtSyncPoint.LastMigratedTargetItemVersion;
                        syncPointList.Add(syncPoint);
                    }
                }

                return(syncPointList);
            }
        }
        private bool SessionGroupIsRunning(MigrationConflict conflict)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                RTSessionGroup rtSessionGroup = FindSessionGroupForConflictedAction(conflict, context);

                if (rtSessionGroup == null)
                {
                    return(false);
                }
                Guid sessionGroupId = rtSessionGroup.GroupUniqueId;

                // first, ask the wcf service if it is managing an active session group of this
                MigrationServiceClient client = new MigrationServiceClient();
                var runningGroupIds           = client.GetRunningSessionGroups();
                if (!runningGroupIds.Contains(sessionGroupId))
                {
                    return(false);
                }

                // next, check if the group is not in the "running" sync orchestration state
                switch (rtSessionGroup.OrchestrationStatus)
                {
                case (int)PipelineState.Running:
                case (int)PipelineState.Starting:
                    return(true);

                default:
                    return(false);
                }
            }
        }
示例#12
0
        private RTMigrationItem QueryCachedCSSNode(RuntimeEntityModel context, string nodeUri)
        {
            var nodeCache = context.RTMigrationItemSet.Where(
                i => i.MigrationSource.UniqueId.Equals(SourceId) && i.ItemId == nodeUri).FirstOrDefault();

            return(nodeCache);
        }
示例#13
0
        private bool TryIgnoreNonFieldConflict(MigrationConflict conflict)
        {
            long targetChangeActionId;
            bool retVal = WITEditEditConflictType.TryGetConflictedTargetChangeActionId(conflict.ConflictDetails, out targetChangeActionId);

            if (!retVal)
            {
                // backward compatibility:
                // old-style edit/edit conflict details does not include target change action id
                // in that case, we can't find a change action to complete the anlaysis
                return(false);
            }

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                // find the target-side change action (should be a delta table entry)
                var targetChangeActionQuery = context.RTChangeActionSet.Where(a => a.ChangeActionId == targetChangeActionId);
                if (targetChangeActionQuery.Count() != 1)
                {
                    return(false);
                }
                RTChangeAction targetChangeAction = targetChangeActionQuery.First();

                XmlDocument targetSideChanges = new XmlDocument();
                targetSideChanges.LoadXml(targetChangeAction.ActionData);

                // if there are edits on the same field, we *cannot* ignore the conflict
                return(!(EditOnSameField(conflict.ConflictedChangeAction.MigrationActionDescription, targetSideChanges)));
            }
        }
示例#14
0
        /// <summary>
        /// Saves the current state of the state machine.
        /// </summary>
        /// <param name="ownerType">The type, session or session group, that this state machine represents.</param>
        /// <param name="ownerUniqueId">The GUID used as the unique Id for the subject session or session group.</param>
        /// <param name="currentState">The current state of the subject session or session group.</param>
        public void SaveCurrentState(OwnerType ownerType, Guid ownerUniqueId, PipelineState currentState)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                switch (ownerType)
                {
                case OwnerType.Session:
                    var sessionQuery = context.RTSessionSet.Where(s => s.SessionUniqueId.Equals(ownerUniqueId));
                    Debug.Assert(sessionQuery.Count() == 1, "sessionQuery.Count() != 1");
                    if (sessionQuery.Count() != 1)
                    {
                        return;
                    }
                    sessionQuery.First().OrchestrationStatus = (int)currentState;
                    context.SaveChanges();
                    break;

                case OwnerType.SessionGroup:
                    var sessionGroupQuery = context.RTSessionGroupSet.Where(sg => sg.GroupUniqueId.Equals(ownerUniqueId));
                    Debug.Assert(sessionGroupQuery.Count() == 1, "sessionGroupQuery.Count() != 1");
                    if (sessionGroupQuery.Count() != 1)
                    {
                        return;
                    }
                    sessionGroupQuery.First().OrchestrationStatus = (int)currentState;
                    context.SaveChanges();
                    break;

                default:
                    Debug.Assert(false, "Invalid OwnerType");
                    return;
                }
            }
        }
示例#15
0
        public void PromoteInAnalysisChangesToReadyForMigration()
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                //todo: convert to sproc
                int inAnalysisVal   = (int)LinkChangeGroup.LinkChangeGroupStatus.InAnalysisTranslated;
                int translatedVal   = LinkChangeAction.GetStatusStorageValue(LinkChangeAction.LinkChangeActionStatus.Translated);
                int readyForMigrVal = (int)LinkChangeGroup.LinkChangeGroupStatus.ReadyForMigration;
                var linkActionQuery = from a in context.RTLinkChangeActionSet
                                      where a.LinkChangeGroup.SessionGroupUniqueId.Equals(SessionGroupId) &&
                                      a.LinkChangeGroup.SessionUniqueId.Equals(SessionId) &&
                                      a.LinkChangeGroup.SourceId.Equals(SourceId) &&
                                      a.LinkChangeGroup.Status == inAnalysisVal &&
                                      !a.LinkChangeGroup.ContainsConflictedAction &&
                                      a.Status == translatedVal &&
                                      a.Conflicted == false
                                      select a;

                foreach (RTLinkChangeAction linkChangeAction in linkActionQuery)
                {
                    linkChangeAction.Status = LinkChangeAction.GetStatusStorageValue(LinkChangeAction.LinkChangeActionStatus.ReadyForMigration);
                }
                context.TrySaveChanges();

                context.BatchUpdateLinkChangeGroupStatus(SessionGroupId, SessionId, SourceId, false,
                                                         inAnalysisVal, readyForMigrVal);
            }
        }
示例#16
0
        /// <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();
            }
        }
示例#17
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);
            }
        }
示例#18
0
        private void MarkSessionRunning()
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var sessionQuery = context.RTSessionSet.Where
                    (s => s.SessionUniqueId.Equals(SessionId));
                Debug.Assert(sessionQuery.Count() == 1);

                // we want to keep StartedInStandaloneProcess session status untouched
                if (sessionQuery.First().State != (int)BusinessModelManager.SessionStateEnum.StartedInStandaloneProcess)
                {
                    sessionQuery.First().State = (int)BusinessModelManager.SessionStateEnum.Running;
                }
                context.TrySaveChanges();
            }

            // If the OrchestrationStatus for the session is PausedByConflict, it should stay in that state
            // until all conflict for the session are resolved
            if (m_syncStateMachine.CurrentState != PipelineState.PausedByConflict)
            {
                if (m_syncStateMachine.TryTransit(PipelineSyncCommand.START))
                {
                    m_syncStateMachine.CommandTransitFinished(PipelineSyncCommand.START);
                }
                else
                {
                    throw new MigrationException();
                }
            }
        }
示例#19
0
        internal bool IsLinkMigratedBefore(ILink link)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                int    completedStatus        = (int)LinkChangeAction.LinkChangeActionStatus.Completed;
                string extendedLinkProperties = GetExtendedPropertyString(link);
                var    query =
                    (from lcAction in context.RTLinkChangeActionSet
                     where lcAction.SessionGroupUniqueId.Equals(SessionGroupId) &&
                     lcAction.SessionUniqueId.Equals(SessionId) &&
                     lcAction.SourceId.Equals(SourceId) &&
                     lcAction.Status == completedStatus &&
                     lcAction.ArtifactLink.SourceArtifactId.Equals(link.SourceArtifactId) &&
                     lcAction.ArtifactLink.SourceArtifactUri.Equals(link.SourceArtifact.Uri) &&
                     lcAction.ArtifactLink.TargetArtifactUri.Equals(link.TargetArtifact.Uri) &&
                     lcAction.ArtifactLink.Comment.Equals(link.Comment) &&
                     lcAction.ArtifactLink.LinkType.ReferenceName.Equals(link.LinkType.ReferenceName) &&
                     lcAction.ArtifactLink.LinkType.ExtendedProperty.Equals(extendedLinkProperties) &&
                     lcAction.ArtifactLink.LinkType.SourceArtifactType.ReferenceName.Equals(link.LinkType.SourceArtifactType.ReferenceName) &&
                     lcAction.ArtifactLink.LinkType.SourceArtifactType.ArtifactContentType.Equals(link.LinkType.SourceArtifactType.ContentTypeReferenceName) &&
                     lcAction.ArtifactLink.LinkType.TargetArtifactType.ReferenceName.Equals(link.LinkType.TargetArtifactType.ReferenceName) &&
                     lcAction.ArtifactLink.LinkType.TargetArtifactType.ArtifactContentType.Equals(link.LinkType.TargetArtifactType.ContentTypeReferenceName)
                     orderby lcAction.Id descending
                     select lcAction).Take(1);

                return(query.Count() > 0);
            }
        }
        private void InsertServerDiffResultInDB(DateTime diffStartTime, bool allContentsMatch, int durationOfDiffInSeconds, string leftQualifier, string rightQualifier)
        {
            using (RuntimeEntityModel runtimeEntityModel = RuntimeEntityModel.CreateInstance())
            {
                RTServerDiffResult serverDiffResult =
                    RTServerDiffResult.CreateRTServerDiffResult(
                        0,
                        Session.SessionType.ToString(),
                        diffStartTime,
                        durationOfDiffInSeconds,
                        Session.SessionUniqueIdGuid,
                        allContentsMatch,
                        BuildOptionsStringForServerDiffResult(leftQualifier, rightQualifier));

                runtimeEntityModel.AddToRTServerDiffResultSet(serverDiffResult);

                foreach (string serverDiffResultDetail in m_serverDiffResultDetails)
                {
                    RTServerDiffResultDetail rtServerDiffResultDetail = RTServerDiffResultDetail.CreateRTServerDiffResultDetail(
                        0, serverDiffResultDetail);

                    rtServerDiffResultDetail.ServerDiffResult = serverDiffResult;

                    runtimeEntityModel.AddToRTServerDiffResultDetailSet(rtServerDiffResultDetail);
                }

                runtimeEntityModel.TrySaveChanges();
            }
        }
        /// <summary>
        /// Updates child action's status to the data store.
        /// </summary>
        /// <param name="action"></param>
        protected override void UpdateChildAction(MigrationAction action)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var changeActionQuery = context.RTChangeActionSet.Where
                                            (ca => ca.ChangeActionId == action.ActionId);
                int changeActionQueryCount = changeActionQuery.Count();
                if (changeActionQueryCount == 0)
                {
                    return;
                }

                Debug.Assert(changeActionQueryCount == 1);
                RTChangeAction rtChangeAction = changeActionQuery.First();

                bool needToUpdateRTChangeAction = false;

                if (action.State == ActionState.Skipped)
                {
                    rtChangeAction.IsSubstituted = true;
                    needToUpdateRTChangeAction   = true;
                }
                if (rtChangeAction.ActionId != action.Action)
                {
                    rtChangeAction.ActionId    = action.Action;
                    needToUpdateRTChangeAction = true;
                }

                if (needToUpdateRTChangeAction)
                {
                    context.TrySaveChanges();
                }
            }
        }
示例#22
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()));
            }
        }
        private string GetLastMigratedChangeName()
        {
            string lastMigratedChangeName = null;

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                int changeGroupStatusComplete = (int)ChangeStatus.Complete;
                var changeGroupQuery          =
                    (from cg in context.RTChangeGroupSet
                     where cg.SourceSideMigrationSource.Id == this.PeerRTMigrationSource.Id &&
                     cg.SessionUniqueId == Session.SessionUniqueIdGuid &&
                     cg.Status == changeGroupStatusComplete &&
                     cg.Name != "Context Information"
                     orderby cg.Id descending
                     select cg.Name).Take(1);
                if (changeGroupQuery.Count() > 0)
                {
                    lastMigratedChangeName = changeGroupQuery.First();
                }
                else
                {
                    m_monitorWatcher.LogVerbose(String.Format(CultureInfo.InvariantCulture,
                                                              MigrationToolkitResources.GetLastMigratedChangeNameFoundNoRows, this.FriendlyName));
                }
            }

            return(lastMigratedChangeName);
        }
示例#24
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();
            }
        }
示例#25
0
 public override void RemoveIncompleteChangeGroups()
 {
     using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
     {
         context.DeleteIncompeleteChangeGroups(new Guid(Session.SessionUniqueId), SourceId);
     }
 }
示例#26
0
        private RTArtifactLink FindCreateLink(ILink link, RuntimeEntityModel context)
        {
            var rtLink = context.FindArtifactLink(
                link.SourceArtifactId,
                link.SourceArtifact.Uri,
                link.TargetArtifact.Uri,
                link.Comment,
                link.LinkType.ReferenceName,
                link.LinkType.FriendlyName,
                GetExtendedPropertyString(link),
                link.LinkType.SourceArtifactType.ReferenceName,
                link.LinkType.SourceArtifactType.FriendlyName,
                link.LinkType.SourceArtifactType.ContentTypeReferenceName,
                link.LinkType.TargetArtifactType.ReferenceName,
                link.LinkType.TargetArtifactType.FriendlyName,
                link.LinkType.TargetArtifactType.ContentTypeReferenceName,
                true
                ).First();

            rtLink.IsLocked = link.IsLocked;
            return(rtLink);

            //var rtArtifactLink = RTArtifactLink.CreateRTArtifactLink(0, link.SourceArtifact.Uri, link.TargetArtifact.Uri);
            //rtArtifactLink.Comment = link.Comment;
            //rtArtifactLink.SourceArtifactId = link.SourceArtifactId;

            //var rtLinkTypeId = FindCreateLinkType(link.LinkType);

            //var rtLinkType = context.RTLinkTypeSet.Where(lt => lt.Id == rtLinkTypeId).First();
            //Debug.Assert(null != rtLinkType);

            //rtArtifactLink.LinkType = rtLinkType;
            //return rtArtifactLink;
        }
示例#27
0
        internal override long?GetFirstConflictedChangeGroup(ChangeStatus status)
        {
            Guid sessionUniqueId = new Guid(Session.SessionUniqueId);

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                int statusVal = (int)status;

                var query = (from cg in context.RTChangeGroupSet
                             where cg.SessionUniqueId.Equals(sessionUniqueId) &&
                             cg.SourceUniqueId.Equals(SourceId) &&
                             cg.Status == statusVal &&
                             cg.ContainsBackloggedAction
                             orderby cg.Id
                             select cg.Id).Take(1);

                if (query.Count() > 0)
                {
                    return(query.First());
                }
                else
                {
                    return(null);
                }
            }
        }
示例#28
0
        private int FindCreateArtifactType(ArtifactType artifactType)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                if (string.IsNullOrEmpty(artifactType.ReferenceName))
                {
                    throw new ArgumentException(string.Format(MigrationToolkitResources.MissingArtifactTypeRefName));
                }


                if (string.IsNullOrEmpty(artifactType.FriendlyName))
                {
                    throw new ArgumentException(string.Format(MigrationToolkitResources.MissingArtifactTypeDispName));
                }

                var artifactTypeQuery = from t in context.RTArtifactTypeSet
                                        where t.ReferenceName.Equals(artifactType.ReferenceName) &&
                                        t.DisplayName.Equals(artifactType.FriendlyName) &&
                                        t.ArtifactContentType.Equals(artifactType.ContentTypeReferenceName)
                                        select t;

                if (artifactTypeQuery.Count() > 0)
                {
                    return(artifactTypeQuery.First().Id);
                }

                var newType = RTArtifactType.CreateRTArtifactType(0, artifactType.ReferenceName, artifactType.FriendlyName,
                                                                  artifactType.ContentTypeReferenceName);
                context.AddToRTArtifactTypeSet(newType);
                context.TrySaveChanges();
                return(newType.Id);
            }
        }
        private string PrintDetailedConflictInfo(string[] splits)
        {
            // [0]source_item_id
            // [1]source_item_version
            // [2]target_item_id
            // [3]target_item_version
            // [4]source_change_action_id
            // [5]target_change_action_id
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Source item {0} (revision {1}) has edit/edit conflict on target item {2} (revision {3}).\n",
                            splits[0], splits[1], splits[2], splits[3]);
            sb.AppendLine();
            //sb.AppendLine("Source item {0} (revision {1} changes:");

            XmlDocument sourceChanges = null;
            XmlDocument targetChanges = null;

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                sourceChanges = LoadChangeDocumentByActionId(splits[4], context);
                targetChanges = LoadChangeDocumentByActionId(splits[5], context);
            }

            if (sourceChanges == null || targetChanges == null)
            {
                return(sb.ToString());
            }

            AppendChangeDetails(sb, splits[0], splits[1], sourceChanges);
            sb.AppendLine();
            AppendChangeDetails(sb, splits[2], splits[3], targetChanges);

            return(sb.ToString());
        }
示例#30
0
        /// <summary>
        /// Marks a command to be processed.
        /// </summary>
        /// <param name="sessionGroupId">The GUID that's used as the unique Id of the subject session group.</param>
        /// <param name="command">The command to be marked as processed.</param>
        public void MarkCommandProcessed(Guid sessionGroupId, PipelineSyncCommand command)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                int commandValue         = (int)command;
                int processingStateValue = (int)PipelineSyncCommandState.Processing;
                var cmdQuery             = from c in context.RTOrchestrationCommandSet
                                           where c.Command == commandValue &&
                                           c.Status == processingStateValue &&
                                           c.SessionGroup.GroupUniqueId.Equals(sessionGroupId)
                                           select c;

                if (cmdQuery.Count() == 0)
                {
                    return;
                }

                foreach (var cmd in cmdQuery)
                {
                    cmd.Status = (int)PipelineSyncCommandState.Processed;
                }

                context.TrySaveChanges();
            }
        }