示例#1
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);
        }
示例#2
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);
        }