コード例 #1
0
ファイル: SnapshotOidMap.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Creates the SnapshotOidMap for source object.
        /// </summary>
        /// <param name="sourceObject">The source object.</param>
        /// <param name="targetObject">The target object.</param>
        /// <returns></returns>
        public static SnapshotOidMap Create(object sourceObject, object targetObject)
        {
            var targetSession = ((ISessionProvider)targetObject).Session;
            var sourceSession = ((ISessionProvider)sourceObject).Session;

            /* 11.2.7 */
            var modelClass = XafDeltaModule.XafApp.FindModelClass(targetObject.GetType());

            var result = new SnapshotOidMap(targetSession)
            {
                Target = new XPWeakReference(targetSession, targetObject),
                // 11.2.7 StoredClassName = targetObject.GetType().FullName
                StoredClassName = modelClass.TypeInfo.FullName
            };

            var sb = new StringBuilder();

            sb.AppendFormat("{0}\a{1}\n", XafDeltaModule.Instance.CurrentNodeId,
                            XPWeakReference.KeyToString(sourceSession.GetKeyValue(sourceObject)));

            var maps = OidMap.GetOidMaps((IXPObject)sourceObject);

            foreach (var oidMap in maps)
            {
                sb.AppendFormat("{0}\a{1}\n", oidMap.NodeId, oidMap.ObjectId);
            }
            result.KnownMapping = sb.ToString();

            return(result);
        }
コード例 #2
0
        private void createSnapshotMaps(BuildContext context)
        {
            var i = 0;

            while (context.MapQueue.Count > 0)
            {
                var sourceObject = context.MapQueue.Dequeue();
                var targetObject = context.DoneObjects[sourceObject];
                SnapshotOidMap.Create(sourceObject, targetObject).OrdNo = i++;
            }
        }
コード例 #3
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Creates the snapshot maps.
        /// </summary>
        /// <param name="context">The context.</param>
        private void createSnapshotMaps(BuildContext context)
        {
            context.Worker.ReportProgress(Localizer.BuildObjectMaps);
            var i = 0;

            while (context.DoneObjects.Count > 0)
            {
                context.Worker.ReportPercent((double)i / (double)context.DoneObjects.Count);
                var sourceObject = context.DoneObjects.Dequeue();
                var snapObject   = context.Map[sourceObject];
                SnapshotOidMap.Create(sourceObject, snapObject).OrdNo = i++;
            }
        }
コード例 #4
0
        /// <summary>
        /// Loads the snapshot object.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceMap">The source map.</param>
        /// <returns></returns>
        private object loadSnapshotObject(SnapshotLoadContext context, SnapshotOidMap sourceMap)
        {
            // look for existing object in app database
            var result = OidMap.FindApplicationObject(context.ObjectSpace, sourceMap, context.Package.SenderNodeId);

            // if not found then create new one
            if (result == null)
            {
                var typeInfo = context.ObjectSpace.TypesInfo.FindTypeInfo(sourceMap.Target.Target.GetType());
                result = context.ObjectSpace.CreateObject(typeInfo.Type);
            }
            // register mapping
            updateObjectMapping(context, sourceMap, result);

            // restore object's state from snapshot
            restoreSnapshotObjectState(context, (IXPObject)sourceMap.Target.Target, (IXPObject)result);
            return(result);
        }
コード例 #5
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Loads the snapshot object.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceMap">The source map.</param>
        /// <returns></returns>
        private object loadSnapshotObject(SnapLoadContext context, SnapshotOidMap sourceMap)
        {
            // look for existing object in app database
            var result = OidMap.FindApplicationObject(context.ObjectSpace, sourceMap, context.Package.SenderNodeId);

            // if not found then create new one
            if (result == null)
            {
                var typeInfo = context.ObjectSpace.TypesInfo.FindTypeInfo(sourceMap.StoredClassName);
                result = context.ObjectSpace.CreateObject(typeInfo.Type);
            }
            // register mapping
            updateObjectMapping(context, sourceMap, result);

            // restore object's state from snapshot
            restoreSnapshotObjectState(context, (IXPObject) sourceMap.Target.Target, (IXPObject) result);
            return result;
        }
コード例 #6
0
ファイル: SnapshotOidMap.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Creates the SnapshotOidMap for source object.
        /// </summary>
        /// <param name="sourceObject">The source object.</param>
        /// <param name="targetObject">The target object.</param>
        /// <returns></returns>
        public static SnapshotOidMap Create(object sourceObject, object targetObject)
        {
            var targetSession = ((ISessionProvider) targetObject).Session;
            var sourceSession = ((ISessionProvider) sourceObject).Session;

            /* 11.2.7 */
            var modelClass = XafDeltaModule.XafApp.FindModelClass(targetObject.GetType());

            var result = new SnapshotOidMap(targetSession)
                             {
                                 Target = new XPWeakReference(targetSession, targetObject),
                                 // 11.2.7 StoredClassName = targetObject.GetType().FullName
                                 StoredClassName = modelClass.TypeInfo.FullName
                             };

            var sb = new StringBuilder();
            sb.AppendFormat("{0}\a{1}\n", XafDeltaModule.Instance.CurrentNodeId,
                XPWeakReference.KeyToString(sourceSession.GetKeyValue(sourceObject)));

            var maps = OidMap.GetOidMaps((IXPObject)sourceObject);
            foreach (var oidMap in maps)
                sb.AppendFormat("{0}\a{1}\n", oidMap.NodeId, oidMap.ObjectId);
            result.KnownMapping = sb.ToString();

            return result;
        }