Category Archives: XPO

A DevExpress designed entity model called Xtra Persistent Objects.

.NET Applications on Linux

Well, what a touchy subject this might be to some people.  I have always seen the battle go back and forth between Windows, Macintosh and Linux.  Windows being a middle-tier price range which excellent performance, Macintosh being the high end simply from marketing and Linux being the low end cost point which the most potential.  The problem I have always seen is that Microsoft holds the middle share which is always the most used share.   I have been a Microsoft developer for my entire career and I love it to death, but the power behind a Linux machine is starting to become hard to ignore.  Recently I ran into a project that was faced with spending 100 hours developing a communication platform for a piece of software or somehow getting .NET hooked into a Linux server.

Of course we went both routes as with any project whichever option is the best is the choice, but something has to work.  I came across this plugin for Apache and Linux called Mono.  Mono is a plugin/server application that lets you run ASP.NET applications on your Linux server native.  You do not have to get pushed to another server or lose your performance, you simply install the package and configure it in Apache and you are up and running.  To start, here is the mono website for you to check out and hopefully spread out through all of your Linux servers: http://www.mono-project.com/Main_Page

Hopefully you all install it and configure it so when I come through I can install my applications on your server and be just fine and dandy, if you don’t I will no doubt make you do it :)  There is a set of install instructions for each server type including Mac servers as well as CentOS, Ubuntu, Debian, etc.  Mostly it seems to just be a package installation through w-get or whatever your package flavor is.  After configuration you can use this site to configure virtual directories: http://go-mono.com/config-mod-mono/Default.aspx

The nice thing about this configuration generator is that you can create a separate config file for each virtual directory and include them in your base httpd config file under each virtual host settings section.  It is almost exactly like creating virtual applications in IIS and the performance is for the most part the same.  From what I have seen this far, .NET 4.0 is supported as well as AJAX, and I am hoping to see some more stuff go into the project to make it a viable option for hosting .NET applications.  Cheers!

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))

HOW TO: Delete data in SQL Using VB.NET And XPO

There are many ways to delete data in SQL, but the problem is that none of them are a silver bullet type answer. The bottom line is to delete a table you want to execute a truncate table against the table to get the fastest speed. Unfortunately if you have any foreign keys related to this table you cannot do that. The next best thing is to execute a delete from statement against the table, but that can be somewhat costly.

In XPO, there are two methods which you can use to delete objects from within a database. The first is calling a delete against an object, and the second is calling the Session.Delete method and pass in an object or collection of objects. Both of these statements use deferred deletion which can speed up your delete process if you are targeting specific records. If this it not a good option (which usually it isn’t) than the next best thing is to generate paged SQL calls. This is what a paged SQL delete might look like using XPO:

Dim strSql As String = "DELETE FROM [Order] WHERE Oid In ("
            Dim sshSession As New Session
            Dim xpcOrders As New XPCollection(Of Order)(sshSession)
            For intLoop As Integer = 0 To xpcOrders.Count - 1
                strSql &= String.Format("'{0}',", xpcOrders(intLoop).Oid.ToString)
                If intLoop Mod 100 = 0 OrElse intLoop = xpcOrders.Count - 1 Then
                    strSql = String.Format("{0})", _
                                         strSql.Substring(0, strSql.Length - 1))
                    sshSession.ExecuteNonQuery(strSql)
                    strSql = "DELETE FROM [Order] WHERE Oid In ("
                End If
            Next