Esempio n. 1
0
        /// <summary>
        /// Registers the protocol event.
        /// </summary>
        /// <param name="protocolEvent">The protocol event.</param>
        public void RegisterProtocolEvent(ProtocolEvent protocolEvent)
        {
            // prevent event registration at loading and inside registered method
            if (Collector.ProtocolService.IsSessionInMethod(Session) ||
                Collector.ProtocolService.LoadService.IsLoading)
            {
                return;
            }

            if (protocolEvent.Target != null)
            {
                if (Collector.IsNotForProtocol(protocolEvent.Target.GetType()))
                {
                    return;
                }

                if (!string.IsNullOrEmpty(protocolEvent.PropertyName) &&
                    Collector.IsNotForProtocol(protocolEvent.Target.GetType(), protocolEvent.PropertyName))
                {
                    return;
                }
            }

            sessionEvents.ProtocolEvents.Add(protocolEvent);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the CollectionChanged event of the collection control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DevExpress.Xpo.XPCollectionChangedEventArgs"/> instance containing the event data.</param>
        private void collection_CollectionChanged(object sender, XPCollectionChangedEventArgs e)
        {
            if (TrackedObjectBag.SessionData.Collector.ProtocolService.LoadService.IsLoading)
            {
                return;
            }

            ProtocolEventType protocolEventType;

            switch (e.CollectionChangedType)
            {
            case XPCollectionChangedType.AfterAdd:
                protocolEventType = ProtocolEventType.AddedToCollection;
                break;

            case XPCollectionChangedType.AfterRemove:
                protocolEventType = ProtocolEventType.RemovedFromCollection;
                break;

            default:
                return;
            }
            var protEvent = new ProtocolEvent
            {
                Target            = TargetObject,
                OldValue          = e.ChangedObject,
                PropertyName      = Collections[(XPBaseCollection)sender],
                ProtocolEventType = protocolEventType,
                ReplicationKey    = ExtensionsHelper.GetReplicationKey(TargetObject)
            };
            var session = ((ISessionProvider)TargetObject).Session;

            TrackedObjectBag.SessionData.Collector.RegisterProtocolEvent(session, protEvent);
        }
Esempio n. 3
0
        /// <summary>
        /// Registers the object creation.
        /// </summary>
        /// <param name="newObject">The new object.</param>
        /// <param name="createDateTime">The create date time.</param>
        /// <param name="eventId">The event id.</param>
        internal void RegisterObjectCreation(object newObject, DateTime createDateTime, long eventId)
        {
            if (newObject == null)
            {
                throw new ArgumentNullException("newObject");
            }

            if (!isMaintenanceObject(newObject) && !Collector.IsNotForProtocol(newObject.GetType()))
            {
                var newEvent = new ProtocolEvent
                {
                    Target            = newObject,
                    ProtocolEventType = ProtocolEventType.ObjectCreated,
                    EventDateTime     = createDateTime,
                    EventId           = eventId
                };



                RegisterProtocolEvent(newEvent);

                // load initial values for brand new object
                trackedObjects.Refresh(newObject);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates an object of the specified type.
        /// Registers object creation in collector.
        /// </summary>
        /// <param name="type">A <see cref="T:System.Type"/> object which represents the type of the object to be created.</param>
        /// <returns>
        /// An object that represents the created object of the specified type.
        /// </returns>
        public override object CreateObject(Type type)
        {
            var createDateTime = DateTime.UtcNow;
            var eventId        = ProtocolEvent.GetNextId();
            var result         = base.CreateObject(type);

            XafDeltaModule.Instance.ProtocolService.Collector.RegisterObjectCreation(result, createDateTime, eventId);
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Registers the protocol event.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="protocolEvent">The protocol event.</param>
        internal void RegisterProtocolEvent(Session session, ProtocolEvent protocolEvent)
        {
            if (collectorDisabled)
            {
                return;
            }

            if (!sessionRegistry.ContainsKey(session))
            {
                RegisterSession(session);
            }
            sessionRegistry[session].RegisterProtocolEvent(protocolEvent);
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the new BLOB value property.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        private byte[] getNewBlobValueProperty(ProtocolEvent item)
        {
            if (item == null)
            {
                return(null);
            }
            // check for operation type: NewBlobValue stored for InitialValueAssigned && ObjectChanged operation
            if (!(new[] { ProtocolEventType.InitialValueAssigned, ProtocolEventType.ObjectChanged }).Contains(item.ProtocolEventType))
            {
                return(null);
            }
            // convert item.NewValue to blob if needed
            var blobValue = ValueTransform.ConvertToBlob(item.NewValue);

            return(blobValue);
        }
Esempio n. 7
0
        private void registerDcManyToManyChange(object linkObject, XPMemberInfo propMember, object element, ProtocolEventType protocolEventType, bool recurse)
        {
            var oppositeProp =
                (from p in propMember.Owner.ObjectProperties.Cast <XPMemberInfo>()
                 where p.Name.EndsWith(SpecificWords.LinkedPostfix) && p != propMember
                 select p).FirstOrDefault();

            if (oppositeProp != null)
            {
                var targetObject = oppositeProp.GetValue(linkObject);
                if (targetObject != null)
                {
                    var targetModelClass = XafDeltaModule.XafApp.FindModelClass(targetObject.GetType());
                    if (targetModelClass != null)
                    {
                        var nameArray = propMember.Name.Split('_').ToList();
                        if (nameArray.Count > 2)
                        {
                            nameArray.RemoveAt(0);
                            nameArray.RemoveAt(nameArray.Count - 1);
                            var targetListName = string.Join("_", nameArray.ToArray());

                            var protEvent = new ProtocolEvent
                            {
                                Target            = targetObject,
                                OldValue          = element,
                                PropertyName      = targetListName,
                                ProtocolEventType = protocolEventType,
                                ReplicationKey    = ExtensionsHelper.GetReplicationKey(targetObject)
                            };

                            var session = ((ISessionProvider)targetObject).Session;

                            Collector.RegisterProtocolEvent(session, protEvent);

                            if (!recurse)
                            {
                                registerDcManyToManyChange(linkObject, oppositeProp, targetObject, protocolEventType, true);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Gets the new BLOB value property.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 private byte[] getNewBlobValueProperty(ProtocolEvent item)
 {
     if (item == null) return null;
     // check for operation type: NewBlobValue stored for InitialValueAssigned && ObjectChanged operation
     if (!(new[] { ProtocolEventType.InitialValueAssigned, ProtocolEventType.ObjectChanged }).Contains(item.ProtocolEventType))
         return null;
     // convert item.NewValue to blob if needed
     var blobValue = ValueTransform.ConvertToBlob(item.NewValue);
     return blobValue;
 }
Esempio n. 9
0
        /// <summary>
        /// Enters the method.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="callContext">The call context.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="args">The args.</param>
        public void EnterMethod(Session session, object callContext, string methodName, params object[] args)
        {
            if (AuditTrailService.Instance.AuditDataStore != null) return;
            if(LoadService.IsLoading) return;

            if (session == null) throw new ArgumentNullException("session");
            if (callContext == null) throw new ArgumentNullException("callContext");
            if (methodName == null) throw new ArgumentNullException("methodName");

            var contextObject = callContext is Type ? null : callContext;
            var contextClass = callContext is Type ? (Type)callContext : callContext.GetType();
            var methodInfo = contextClass.GetMethod(methodName);
            if (methodInfo == null) return;

            var replicationKey = "";
            if (contextObject != null)
                replicationKey = ExtensionsHelper.GetReplicationKey(contextObject);

            var protocolEvent = new ProtocolEvent
                                    {
                                        Target = contextObject,
                                        ProtocolEventType = ProtocolEventType.MethodCall,
                                        OldValue = MethodCallParams.CreateForArgs(DevExpress.ExpressApp.ObjectSpace.FindObjectSpaceByObject(contextObject), args),
                                        PropertyName = methodName,
                                        ReplicationKey = replicationKey
                                    };
            Collector.RegisterProtocolEvent(session, protocolEvent);

            lock (callRegistry)
            {
                Dictionary<Thread, Stack<string>> sessionThreads;
                if (!callRegistry.TryGetValue(session, out sessionThreads))
                {
                    sessionThreads = new Dictionary<Thread, Stack<string>>();
                    callRegistry.Add(session, sessionThreads);
                }

                var currentThread = Thread.CurrentThread;
                Stack<string> callsStack;
                if (!sessionThreads.TryGetValue(currentThread, out callsStack))
                {
                    callsStack = new Stack<string>();
                    sessionThreads.Add(currentThread, callsStack);
                }

                callsStack.Push(methodName);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Registers the protocol event.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="protocolEvent">The protocol event.</param>
        internal void RegisterProtocolEvent(Session session, ProtocolEvent protocolEvent)
        {
            if (collectorDisabled) return;

            if (!sessionRegistry.ContainsKey(session))
                RegisterSession(session);
            sessionRegistry[session].RegisterProtocolEvent(protocolEvent);
        }
Esempio n. 11
0
        /// <summary>
        /// Enters the method.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="callContext">The call context.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="args">The args.</param>
        public void EnterMethod(Session session, object callContext, string methodName, params object[] args)
        {
            if (AuditTrailService.Instance.AuditDataStore != null)
            {
                return;
            }
            if (LoadService.IsLoading)
            {
                return;
            }

            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (callContext == null)
            {
                throw new ArgumentNullException("callContext");
            }
            if (methodName == null)
            {
                throw new ArgumentNullException("methodName");
            }

            var contextObject = callContext is Type ? null : callContext;
            var contextClass  = callContext is Type ? (Type)callContext : callContext.GetType();
            var methodInfo    = contextClass.GetMethod(methodName);

            if (methodInfo == null)
            {
                return;
            }

            var replicationKey = "";

            if (contextObject != null)
            {
                replicationKey = ExtensionsHelper.GetReplicationKey(contextObject);
            }

            var protocolEvent = new ProtocolEvent
            {
                Target            = contextObject,
                ProtocolEventType = ProtocolEventType.MethodCall,
                OldValue          = MethodCallParams.CreateForArgs(DevExpress.ExpressApp.ObjectSpace.FindObjectSpaceByObject(contextObject), args),
                PropertyName      = methodName,
                ReplicationKey    = replicationKey
            };

            Collector.RegisterProtocolEvent(session, protocolEvent);

            lock (callRegistry)
            {
                Dictionary <Thread, Stack <string> > sessionThreads;
                if (!callRegistry.TryGetValue(session, out sessionThreads))
                {
                    sessionThreads = new Dictionary <Thread, Stack <string> >();
                    callRegistry.Add(session, sessionThreads);
                }

                var            currentThread = Thread.CurrentThread;
                Stack <string> callsStack;
                if (!sessionThreads.TryGetValue(currentThread, out callsStack))
                {
                    callsStack = new Stack <string>();
                    sessionThreads.Add(currentThread, callsStack);
                }

                callsStack.Push(methodName);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Handles the CollectionChanged event of the collection control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="DevExpress.Xpo.XPCollectionChangedEventArgs"/> instance containing the event data.</param>
        private void collection_CollectionChanged(object sender, XPCollectionChangedEventArgs e)
        {
            if (TrackedObjectBag.SessionData.Collector.ProtocolService.LoadService.IsLoading) return;

            ProtocolEventType protocolEventType;
            switch (e.CollectionChangedType)
            {
                case XPCollectionChangedType.AfterAdd:
                    protocolEventType = ProtocolEventType.AddedToCollection;
                    break;
                case XPCollectionChangedType.AfterRemove:
                    protocolEventType = ProtocolEventType.RemovedFromCollection;
                    break;
                default:
                    return;
            }
            var protEvent = new ProtocolEvent
                                {
                                    Target = TargetObject,
                                    OldValue = e.ChangedObject,
                                    PropertyName = Collections[(XPBaseCollection)sender],
                                    ProtocolEventType = protocolEventType,
                                    ReplicationKey = ExtensionsHelper.GetReplicationKey(TargetObject)
                                };
            var session = ((ISessionProvider)TargetObject).Session;
            TrackedObjectBag.SessionData.Collector.RegisterProtocolEvent(session, protEvent);
        }
Esempio n. 13
0
        private void registerDcManyToManyChange(object linkObject, XPMemberInfo propMember, object element, ProtocolEventType protocolEventType, bool recurse)
        {
            var oppositeProp =
                (from p in propMember.Owner.ObjectProperties.Cast<XPMemberInfo>()
                 where p.Name.EndsWith(SpecificWords.LinkedPostfix) && p != propMember
                 select p).FirstOrDefault();

            if(oppositeProp != null)
            {
                var targetObject = oppositeProp.GetValue(linkObject);
                if(targetObject != null)
                {
                    var targetModelClass = XafDeltaModule.XafApp.FindModelClass(targetObject.GetType());
                    if (targetModelClass != null)
                    {
                        var nameArray = propMember.Name.Split('_').ToList();
                        if(nameArray.Count > 2)
                        {
                            nameArray.RemoveAt(0);
                            nameArray.RemoveAt(nameArray.Count-1);
                            var targetListName = string.Join("_", nameArray.ToArray());

                            var protEvent = new ProtocolEvent
                            {
                                Target = targetObject,
                                OldValue = element,
                                PropertyName = targetListName,
                                ProtocolEventType = protocolEventType,
                                ReplicationKey = ExtensionsHelper.GetReplicationKey(targetObject)
                            };

                            var session = ((ISessionProvider)targetObject).Session;

                            Collector.RegisterProtocolEvent(session, protEvent);

                            if (!recurse)
                                registerDcManyToManyChange(linkObject, oppositeProp, targetObject, protocolEventType, true);
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Registers the object creation.
        /// </summary>
        /// <param name="newObject">The new object.</param>
        /// <param name="createDateTime">The create date time.</param>
        /// <param name="eventId">The event id.</param>
        internal void RegisterObjectCreation(object newObject, DateTime createDateTime, long eventId)
        {
            if (newObject == null) throw new ArgumentNullException("newObject");

            if (!isMaintenanceObject(newObject) && !Collector.IsNotForProtocol(newObject.GetType()))
            {
                var newEvent = new ProtocolEvent
                                   {
                                       Target = newObject,
                                       ProtocolEventType = ProtocolEventType.ObjectCreated,
                                       EventDateTime = createDateTime,
                                       EventId = eventId
                                   };

                RegisterProtocolEvent(newEvent);

                // load initial values for brand new object
                trackedObjects.Refresh(newObject);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Registers the protocol event.
        /// </summary>
        /// <param name="protocolEvent">The protocol event.</param>
        public void RegisterProtocolEvent(ProtocolEvent protocolEvent)
        {
            // prevent event registration at loading and inside registered method
            if (Collector.ProtocolService.IsSessionInMethod(Session)
                || Collector.ProtocolService.LoadService.IsLoading) return;

            if(protocolEvent.Target != null)
            {
                if(Collector.IsNotForProtocol(protocolEvent.Target.GetType()))
                    return;

                if (!string.IsNullOrEmpty(protocolEvent.PropertyName) &&
                    Collector.IsNotForProtocol(protocolEvent.Target.GetType(), protocolEvent.PropertyName))
                        return;
            }

            sessionEvents.ProtocolEvents.Add(protocolEvent);
        }