private IMigrationAction RealizeSingleActionFromEDM(
            RTChangeAction runTimeChangeAction)
        {
            XmlDocument changeActionData = null;

            if (!string.IsNullOrEmpty(runTimeChangeAction.ActionData))
            {
                changeActionData = new XmlDocument();
                changeActionData.LoadXml(runTimeChangeAction.ActionData);
            }

            IMigrationItemSerializer itemSerializer = ManagerWithMigrationItemSerializers[runTimeChangeAction.ActionId];

            DemandUnlocked("Cannot Create an action on a group after the initial Create");

            SqlMigrationAction migrationAction = new SqlMigrationAction(
                this, runTimeChangeAction.ChangeActionId, runTimeChangeAction.ActionId,
                itemSerializer.LoadItem(runTimeChangeAction.SourceItem, Manager),
                runTimeChangeAction.FromPath, runTimeChangeAction.ToPath, runTimeChangeAction.Version,
                runTimeChangeAction.MergeVersionTo, runTimeChangeAction.ItemTypeReferenceName, changeActionData,
                runTimeChangeAction.IsSubstituted ? ActionState.Skipped : ActionState.Pending);

            if (!m_usePagedActions)
            {
                AddAction(migrationAction);
            }

            migrationAction.IsDirty = false;
            return(migrationAction);
        }
        private IMigrationAction CreateAction(
            Guid action,
            IMigrationItem sourceItem,
            string fromPath,
            string path,
            string version,
            string mergeVersionTo,
            string itemTypeRefName,
            XmlDocument actionDetails,
            long internalChangeActionId,
            bool isSubstituted)
        {
            if (!Manager.TargetActionids.ContainsKey(action))
            {
                // ToDo - Action not supported conflict
            }
            DemandUnlocked("Cannot Create an action on a group after the initial Create");

            SqlMigrationAction createdAction = new SqlMigrationAction(
                this, internalChangeActionId, action, sourceItem,
                fromPath, path, version, mergeVersionTo, itemTypeRefName, actionDetails,
                isSubstituted ? ActionState.Skipped : ActionState.Pending);

            this.AddAction(createdAction);
            return(createdAction);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Realize a SqlMigrationAction from DB RTChangeAction.
        /// Note properties ChangeGroup, SourceItem and ActionData are not populated.
        /// </summary>
        /// <param name="RTChangeAction"></param>
        /// <returns></returns>
        internal static SqlMigrationAction RealizeFromDB(RTChangeAction RTChangeAction)
        {
            SqlMigrationAction migrationAction = new SqlMigrationAction(null, RTChangeAction.ChangeActionId, RTChangeAction.ActionId, null, RTChangeAction.FromPath, RTChangeAction.ToPath,
                                                                        RTChangeAction.Version, RTChangeAction.MergeVersionTo, RTChangeAction.ItemTypeReferenceName, null);

            return(migrationAction);
        }
Exemplo n.º 4
0
 public void StorePage(int startIndex, IList <IMigrationAction> page)
 {
     // Verify that there is something to save and the first change action in the
     // page has not been persisted.  This implementation relies on page level granularity
     // in save/load.
     if (page != null && page.Count != 0)
     {
         SqlMigrationAction sqlMigrationAction = (SqlMigrationAction)page[0];
         m_sqlChangeGroupManager.BatchSaveGroupedChangeActions(page);
     }
 }
        private IMigrationAction CreateDeleteAttachmentAction(IMigrationAction action)
        {
            SqlMigrationAction sqlMigrationAction = action as SqlMigrationAction;

            System.Diagnostics.Debug.Assert(null != sqlMigrationAction, "cannot convert action to SqlMigrationAction");

            SqlMigrationAction copy = new SqlMigrationAction(
                action.ChangeGroup, 0, WellKnownChangeActionId.DelAttachment, action.SourceItem,
                action.FromPath, action.Path, action.Version, action.MergeVersionTo, action.ItemTypeReferenceName,
                action.MigrationActionDescription, action.State);

            return(copy);
        }
Exemplo n.º 6
0
        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());
        }
        /// <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;
                }
            }
        }
        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);
                }
            }
        }