Beispiel #1
0
        /// <summary>
        /// Persists the session events.
        /// </summary>
        /// <param name="persistSession">The session.</param>
        private void persistSessionEvents(Session persistSession)
        {
            if(ProtocolEvents.Count == 0 && AllChildren.Count == 0) return;

            // create or find protocol session for current session data
            var protocolSession = getProtocolSession(persistSession);
            protocolSession.StartedOn = StartedOn;
            protocolSession.CommitedOn = CommitedOn;

            double timeOffset = 0;

            // for each protocol event create protocol record
            foreach (var protocolEvent in ProtocolEvents.OrderBy(x => x.EventId))
            {
                if (protocolEvent.IsNotForProtocol) continue;

                var protocolRecord = new ProtocolRecord(persistSession);

                if (protocolEvent.Target != null)
                    protocolRecord.AuditedObject = new AuditedObjectWeakReference(persistSession, protocolEvent.Target);

                protocolRecord.ProtocolSession = protocolSession;
                protocolRecord.OperationType = protocolEvent.ProtocolEventType.ToString();
                protocolRecord.UserName = SecuritySystem.CurrentUserName;
                protocolRecord.Description = protocolEvent.Description;
                protocolRecord.ModifiedOn = protocolEvent.EventDateTime.AddMilliseconds(timeOffset += 3);
                protocolRecord.PropertyName = protocolEvent.PropertyName;

                if (protocolEvent.NewValue != null)
                {
                    protocolRecord.NewValue = ValueTransform.ObjectToString(protocolEvent.NewValue);

                    if (protocolEvent.NewValue is IXPObject)
                        protocolRecord.NewObject = new XPWeakReference(persistSession, protocolEvent.NewValue);
                }

                if (protocolEvent.OldValue != null)
                {
                    protocolRecord.OldValue = ValueTransform.ObjectToString(protocolEvent.OldValue);

                    if (protocolEvent.OldValue is IXPObject)
                        protocolRecord.OldObject = new XPWeakReference(persistSession, protocolEvent.OldValue);
                }

                protocolRecord.NewBlobValue = getNewBlobValueProperty(protocolEvent);

                // for ObjectCreated events replication key to current replication key value; otherwise
                // use event's replication key value
                protocolRecord.ReplicationKey = protocolEvent.ProtocolEventType == ProtocolEventType.ObjectCreated
                                                    ? ExtensionsHelper.GetReplicationKey(protocolEvent.Target)
                                                    : protocolEvent.ReplicationKey;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Persists the session events.
        /// </summary>
        /// <param name="persistSession">The session.</param>
        private void persistSessionEvents(Session persistSession)
        {
            if (ProtocolEvents.Count == 0 && AllChildren.Count == 0)
            {
                return;
            }

            // create or find protocol session for current session data
            var protocolSession = getProtocolSession(persistSession);

            protocolSession.StartedOn  = StartedOn;
            protocolSession.CommitedOn = CommitedOn;

            double timeOffset = 0;

            // for each protocol event create protocol record
            foreach (var protocolEvent in ProtocolEvents.OrderBy(x => x.EventId))
            {
                if (protocolEvent.IsNotForProtocol)
                {
                    continue;
                }

                var protocolRecord = new ProtocolRecord(persistSession);

                if (protocolEvent.Target != null)
                {
                    protocolRecord.AuditedObject = new AuditedObjectWeakReference(persistSession, protocolEvent.Target);
                }

                protocolRecord.ProtocolSession = protocolSession;
                protocolRecord.OperationType   = protocolEvent.ProtocolEventType.ToString();
                protocolRecord.UserName        = SecuritySystem.CurrentUserName;
                protocolRecord.Description     = protocolEvent.Description;
                protocolRecord.ModifiedOn      = protocolEvent.EventDateTime.AddMilliseconds(timeOffset += 3);
                protocolRecord.PropertyName    = protocolEvent.PropertyName;

                if (protocolEvent.NewValue != null)
                {
                    protocolRecord.NewValue = ValueTransform.ObjectToString(protocolEvent.NewValue);


                    if (protocolEvent.NewValue is IXPObject)
                    {
                        protocolRecord.NewObject = new XPWeakReference(persistSession, protocolEvent.NewValue);
                    }
                }

                if (protocolEvent.OldValue != null)
                {
                    protocolRecord.OldValue = ValueTransform.ObjectToString(protocolEvent.OldValue);

                    if (protocolEvent.OldValue is IXPObject)
                    {
                        protocolRecord.OldObject = new XPWeakReference(persistSession, protocolEvent.OldValue);
                    }
                }

                protocolRecord.NewBlobValue = getNewBlobValueProperty(protocolEvent);

                // for ObjectCreated events replication key to current replication key value; otherwise
                // use event's replication key value
                protocolRecord.ReplicationKey = protocolEvent.ProtocolEventType == ProtocolEventType.ObjectCreated
                                                    ? ExtensionsHelper.GetReplicationKey(protocolEvent.Target)
                                                    : protocolEvent.ReplicationKey;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SaveProtocolRecordParams"/> class.
 /// </summary>
 /// <param name="baseParams">The base params.</param>
 /// <param name="protocolRecord">The protocol record.</param>
 public SaveProtocolRecordParams(SaveProtocolSessionParams baseParams, ProtocolRecord protocolRecord)
     : base(baseParams, baseParams.ProtocolSession)
 {
     ProtocolRecord = protocolRecord;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetRecipientsEventArgs"/> class.
 /// </summary>
 /// <param name="protocolRecord">The protocol record.</param>
 /// <param name="objectSpace">The object space.</param>
 /// <param name="recipients">The recipients.</param>
 public GetRecipientsEventArgs(ProtocolRecord protocolRecord, IObjectSpace objectSpace,
                               List<ReplicationNode> recipients)
 {
     ProtocolRecord = protocolRecord;
     ObjectSpace = objectSpace;
     Recipients = recipients;
 }
Beispiel #5
0
        /// <summary>
        /// Creates package record based on protocol record.
        /// </summary>
        /// <param name="packageSession">The package session.</param>
        /// <param name="protocolRecord">The protocol record.</param>
        /// <param name="targetNode">The target node.</param>
        /// <returns>Package record</returns>
        public static PackageRecord CreateForProtocolRecord(PackageSession packageSession, 
            ProtocolRecord protocolRecord, ReplicationNode targetNode)
        {
            var destinationSession = packageSession.Session;
            var result = new PackageRecord(destinationSession)
            {
                PackageSession = packageSession,
                UserName = protocolRecord.UserName,
                Description = protocolRecord.Description,
                ModifiedOn = protocolRecord.ModifiedOn,
                NewBlobValue = protocolRecord.NewBlobValue,
                PropertyName = protocolRecord.PropertyName,
                NewValue = protocolRecord.NewValue,
                OldValue = protocolRecord.OldValue,
                OperationType = protocolRecord.OperationType
            };

            if(protocolRecord.AuditedObject != null && protocolRecord.AuditedObject.Target != null)
            {
                result.AuditedObject =
                    PackageObjectReference.CreatePackageObjectReference(protocolRecord.AuditedObject.Target,
                        destinationSession, targetNode);

                result.AuditedObject.ReplicationKey = protocolRecord.ReplicationKey;
            }

            if (protocolRecord.NewObject != null)
                result.NewObject = PackageObjectReference.CreatePackageObjectReference(protocolRecord.NewObject.Target,
                    destinationSession, targetNode);

            if (protocolRecord.OldObject != null)
                result.OldObject = PackageObjectReference.CreatePackageObjectReference(protocolRecord.OldObject.Target,
                    destinationSession, targetNode);

            return result;
        }