示例#1
0
        /// <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
        /// <summary>
        /// Creates for package record.
        /// </summary>
        /// <param name="objectSpace">The object space.</param>
        /// <param name="record">The record.</param>
        /// <param name="nodeId">The node id.</param>
        /// <returns></returns>
        public static ProtocolRecord CreateForPackageRecord(IObjectSpace objectSpace,
                                                            PackageRecord record, string nodeId)
        {
            if (objectSpace == null)
            {
                throw new ArgumentNullException("objectSpace");
            }
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }


            var session = ((ObjectSpace)objectSpace).Session;
            var result  = objectSpace.CreateObject <ProtocolRecord>();

            if (record.AuditedObject != null && record.AuditedObject.IsAssigned)
            {
                result.AuditedObject = new AuditedObjectWeakReference(session,
                                                                      OidMap.FindApplicationObject(objectSpace, record.AuditedObject, nodeId));
            }

            result.OperationType = record.OperationType;
            result.ModifiedOn    = record.ModifiedOn;
            result.Description   = record.Description;
            result.NewBlobValue  = record.NewBlobValue;

            if (record.NewObject != null)
            {
                result.NewObject = new XPWeakReference(session,
                                                       OidMap.FindApplicationObject(objectSpace, record.NewObject, nodeId));
            }

            if (record.OldObject != null)
            {
                result.OldObject = new XPWeakReference(session,
                                                       OidMap.FindApplicationObject(objectSpace, record.OldObject, nodeId));
            }

            result.NewValue     = record.NewValue;
            result.OldValue     = record.OldValue;
            result.PropertyName = record.PropertyName;

            if (record.AuditedObject != null && record.AuditedObject.IsAssigned)
            {
                result.ReplicationKey = record.AuditedObject.ReplicationKey;
            }

            return(result);
        }
示例#3
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);
        }
示例#4
0
        /// <summary>
        /// Updates the object mapping.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceMap">The source map.</param>
        /// <param name="appObject">The app object.</param>
        private void updateObjectMapping(SnapshotLoadContext context,
                                         IPackageObjectReference sourceMap, object appObject)
        {
            if (context.UpdatedMapping.Contains(appObject))
            {
                return;
            }
            context.UpdatedMapping.Add(appObject);

            foreach (var mappingStr in sourceMap.KnownMapping.Split(new[] { '\n' },
                                                                    StringSplitOptions.RemoveEmptyEntries))
            {
                var mapArray = mappingStr.Split('\a');
                var nodeId   = mapArray[0];
                var objectId = mapArray[1];
                var oidMap   = OidMap.GetOidMap(appObject, nodeId);
                if (oidMap == null)
                {
                    OidMap.CreateOidMap(context.ObjectSpace, objectId, nodeId, (IXPObject)appObject);
                }
            }
        }