Tag Archives: XPO

HOW TO: Create an XtraReport from a ReportData Object

DevExpress has a nice module for their eXpressApp Framework called the Report Module.  The purpose of this module is to provide a reporting engine for your objects and allow you to generate reports through actions and in the UI.  So far, the biggest problem I have encountered with this is how to generate these reports outside of the Framework once they are designed a ready.  A typical scenario involves having a designed application and then needing to develop some sort of service process that fetches and sends reports on a daily basis.

As a work around, I’ve found out how to generate these reports as a simple XtraReport instead of a XafReport object.  The XtraReport class can be loaded from a stream which contains the layout in a byte array.  I simply read the layout from the persistent ReportData object into a byte array and load the XtraReport from it.  Here are some code examples:

VB.NET

Dim uowUnitOfWork As New  UnitOfWork(XpoDefault.DataLayer)
Dim obsObjectSpace As New ObjectSpace(uowUnitOfWork, XafTypesInfo.Instance)
Dim rptReportData As Reports.ReportData
Dim xfrReport As Reports.XafReport

rptReportData = obsObjectSpace.FindObject(Of Reports.ReportData)(Nothing)
xfrReport = rptReportData.LoadXtraReport(obsObjectSpace)

C#

using( UnitOfWork uow = new UnitOfWork( XpoDefault.DataLayer ) ) {
        ObjectSpace objectSpace = new ObjectSpace( uow , new XpoTypesInfoAdapter(
uow.DataLayer.Dictionary ) );
        uow.Connect();
        ReportData reportData = objectSpace.FindObject<ReportData>( new BinaryOperator( "Name",
"ContactsGroupedByPosition" ) );
        if( reportData != null ) {
            XafReport report = reportData.LoadXtraReport( objectSpace );
            report.ObjectSpace = objectSpace;
            report.ShowPreview();
        }
    }

HOW TO: Set Properties Dynamically Using XAF/XPO

XPO provides some very powerful features which are wrapped up again in a nice library for XAF. One such feature is the System.Reflection metadata that is wrapped into a nice library that allows you to find attributes easier etc. I recently came across a situation which required me to set an unknown property with an unknown value and show any errors if the typing didn’t work or the property wasn’t found. To do this, I used the XafTypes Instance of XAF to find the type and member info. The code looked something like this:

Dim dtiTypeInfo As TypeInfo
dtiTypeInfo = XafTypesInfo.Instance.FindTypeInfo(GetType(ObjectType))
If dtiTypeInfo Is Nothing Then
    Return Nothing
End If
Return dtiTypeInfo.FindMember(MyFieldName)

The next challenge I ran into was deserializing the values of the object, which again XAF and XPO provide a nice wrapper to forget about all of the noise. I simply used the deserialize method of the member info that I just returned and passed in the string value that I wanted to set. This automatically converted everything to what I need and also allows you to serialize down properties into databases if you wanted to and set properties based on their deserialized value. This was a one liner that looks like this:

MyMemberInfo.SetValue(vrtVariant,MyMemberInfo.DeserializeValue(Value.ToString))