Ticket Q480741
Visible to All Users

Unique audit info popup

created 12 years ago

Hi, i need to show audit info about a master object and his childs in a unique popup.
Actually i've implemented this code to show audit info:
Public Class viewAudit
    Inherits DevExpress.ExpressApp.ViewController
    Private showAuditInfoActionCore As SimpleAction

Public Sub New()
        showAuditInfoActionCore = New SimpleAction(Me, "ShowAuditInfo", DevExpress.Persistent.Base.PredefinedCategory.View)
        showAuditInfoActionCore.Caption = "Cronologia modifiche"
        showAuditInfoActionCore.ImageName = "Audit"
        AddHandler showAuditInfoActionCore.Execute, AddressOf showAuditInfoActionCore_Execute
        showAuditInfoActionCore.PaintStyle = ActionItemPaintStyle.Image
        showAuditInfoActionCore.TargetViewType = ViewType.Any
    End Sub

Public Function GetAuditInfo(ByVal session As Session, ByVal targetType As Type) As XPCollection(Of AuditDataItemPersistent)
        Dim bo1 As New BinaryOperator("TargetType", session.GetObjectType(session.GetClassInfo(targetType)))
        Dim bo2 As New BinaryOperator("TargetKey", XPWeakReference.KeyToString(ObjectSpace.GetKeyValue(Me.View.CurrentObject)))
        Dim auditObjectWeakReference As AuditedObjectWeakReference = session.FindObject(Of AuditedObjectWeakReference)(New GroupOperator(GroupOperatorType.And, bo1, bo2))
        If auditObjectWeakReference IsNot Nothing Then
            auditObjectWeakReference.AuditDataItems.BindingBehavior = CollectionBindingBehavior.AllowNone
            Return auditObjectWeakReference.AuditDataItems
        End If
        Return Nothing
End Function
    Protected Overridable Sub ShowAuditInfo(ByVal e As SimpleActionExecuteEventArgs)
        Dim auditInfo As XPCollection(Of AuditDataItemPersistent)
        Dim objSpace As XPObjectSpace = CType(View.ObjectSpace, XPObjectSpace)
        auditInfo = GetAuditInfo(CType(View.ObjectSpace, XPObjectSpace).Session, View.ObjectTypeInfo.Type)
        If auditInfo IsNot Nothing Then
            Dim cs As CollectionSourceBase = New CollectionSource(objSpace, GetType(AuditDataItemPersistent))
            e.ShowViewParameters.CreatedView = Application.CreateListView(Application.FindListViewId(GetType(AuditDataItemPersistent)), cs, False)
            e.ShowViewParameters.CreatedView.Caption = String.Format("{0} History", e.ShowViewParameters.CreatedView.ObjectTypeInfo.Name)
            cs.Criteria("AllAuditInfo") = New InOperator(objSpace.GetKeyPropertyName(GetType(AuditDataItemPersistent)), auditInfo)
            e.ShowViewParameters.Context = TemplateContext.View
            e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow
        Else
            XtraMessageBox.Show("Non ci sono dati nella cronologia.", Application.Title, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information)
        End If
    End Sub

Private Sub showAuditInfoActionCore_Execute(ByVal sender As Object, ByVal e As SimpleActionExecuteEventArgs)
        ShowAuditInfo(e)
    End Sub

Public ReadOnly Property ShowAuditInfoAction() As SimpleAction
        Get
            Return showAuditInfoActionCore
        End Get
    End Property
End Class
In the GetAuditInfo sub i'd like to return a complete collection of AuditDataItemPersistent referred to master object and childs too.
How can i get all types and all id's of object referred from the master object so i can create the criteria and return the complete collection?
Thanks,
Paolo

Comments (1)
DevExpress Support Team 12 years ago

    Please accept our apologies for the delay in responding. We couldn't find an immediate answer or resolution. Please bear with us. We will inform you as soon as an answer is found.

    Answers approved by DevExpress Support

    created 12 years ago (modified 12 years ago)

    The AuditTrail module is not designed to show audit information about a current object and each object from its collection property.
    However, you can implement this behavior manually. I have demonstrated how to do this in the following example: Audit - How to show audit entries for a current object and for each object from its collection property in one list.
    Generic implementation that shows audit entries for a current object and its related objects from all collection properties is a complicated task, so we cannot provide an immediate complete solution. In the meantime, check the How to: Access Business Class Metadata topic and the corresponding example How to: Access Business Class Metadata, where we described how to get information about properties of any persistent type.

      Comments (3)

        Why this code doesn't works??
            Public Function GetAuditInfo(ByVal session As Session, ByVal targetType As Type) As XPCollection(Of AuditDataItemPersistent)
                Dim g1 As New GroupOperator
                Dim retcoll As New XPCollection(Of AuditDataItemPersistent)(session)
                For Each mi As XPMemberInfo In session.GetClassInfo(targetType).CollectionProperties
                    If mi.IsAggregated AndAlso mi.IsCollection AndAlso mi.IsAssociation Then
                        Dim objs As ICollection = mi.GetValue(Me.View.CurrentObject)
                        For Each obj As IXPObject In objs
                            Dim b1 As New BinaryOperator("TargetType", session.GetObjectType(session.GetClassInfo(obj)))
                            Dim b2 As New BinaryOperator("TargetKey", XPWeakReference.KeyToString(ObjectSpace.GetKeyValue(obj)))
                            g1 = GroupOperator.Combine(GroupOperatorType.And, b1, b2)
                            Dim auditObjectWeakReference As AuditedObjectWeakReference = session.FindObject(Of AuditedObjectWeakReference)(g1)
                            If auditObjectWeakReference IsNot Nothing Then
                                auditObjectWeakReference.AuditDataItems.BindingBehavior = CollectionBindingBehavior.AllowNone
                                retcoll.AddRange(auditObjectWeakReference.AuditDataItems)
                            End If
                        Next obj
                    End If
                Next mi
                Return retcoll
            End Function
        Thanks,
        Paolo

        DevExpress Support Team 12 years ago

          I have integrated your code into the Audit - How to show audit entries for a current object and for each object from its collection property in one list example with only one change:

          Visual Basic
          'Dim retcoll As New XPCollection(Of AuditDataItemPersistent)(session) Dim retcoll As New List(Of AuditDataItemPersistent)()

          because the XPCollection class automatically loads its content from the database when its items are queried the first time and removes your manually added items.
          With this change, your code works as expected: all audit entries for each object in the aggregated 'Addresses' collection are loaded and shown. For more details, see the attached solution.
          Don't hesitate to write to me if I misunderstand your needs. In this case, please describe the current behavior of your code and the necessary behavior in greater detail.

            Thanks, it works!!
            Paolo

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.