/// <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); }
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++; } }
/// <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++; } }
/// <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); }
/// <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; }
/// <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; }