XAF Data Import Functionality

by Administrator 2. May 2010 11:05

One of the biggest problems with migrating legacy applications to a new framework (such as XAF, netTiers, etc) is the process of importing existing data into the newly created application. I've always found this to be a challenging and boring step of the process, and usually it requires a fair bit of manual work or writing custom import functions or applications.

I think there are probably (generally) 3 common data import sources:

  • Flat File (CSV, TSV, etc)
  • XML File
  • Relational DBMS (Access, SQL, MySQL, etc)

As most of my projects these days are baed on XAF or XPO, I figured there must be a more generic way to do my data imports. XAF is an application framework built around eXtensible Persistent Objects (XPO) which is a proprietary ORM technology developed by Developer Express.

XPO Objects are defined in classes which derive from XPObect (or other) base classes with various Attributes to further refine persistent behaviour.

I have added a few of my own custom Attributes to decorate my XPO classes and properties in order to hint my data import library with any additional data required for the import process. I have a custom application XpoImport which uses reflection to enumerate all the Xpo classes and properties within a specified namespace. This application creates two connections to the source and destination databases and provides a small amount of in-memory caching for lookup data. Some examples will follow.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]

public class TableImportAttribute : Attribute

{

public readonly string SourceTable = string.Empty;

public readonly string KeyField = string.Empty;

...


[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]

public class FieldImportAttribute : Attribute

{

public readonly string SourceField = String.Empty;

public readonly FieldConversionType ConversionType = FieldConversionType.None;


public enum FieldConversionType

{

None,

IntegerToString,

StringToPhoneNumber,

Lookup,

Enum

}

...


The business objects must now be decorated with these properties as such: (this example demonstrates that the new "Area" XPO object data will be loaded from the "tblAreas" source SQL table using "AREAID" as the key. The Name property will be populated with data from the "SEARCHTEXT" field from the "tblAreas" source.)


   [DefaultClassOptions]

[DefaultProperty("Description")]

[TableImport("tblAreas", "AREAID")]

[TableImportIndex(1)]

public class Area : XPObject

{

private string _Name;

[Size(20)]

[Indexed(Unique = true)]

[FieldImport("SEARCHTEXT")]

public string Name

{

get

{

return _Name;

}

set

{

SetPropertyValue("Name", ref _Name, value);

}

}


Once the required fields have been created, I run a small WinForms application which loads the business object assembly and iterates through the various objects to load the data.


201005021603.jpg


Still a work in progress, but slowly getting there...


Tags:

Hardware Manufacturers

by Administrator 29. April 2010 10:03

I can see the merits in hardware vendors and software vendors being more or less the same thing.  Eg Apple Inc.  I mean - you know there's compatibility throughout the life of your product, and generally long into the future.  The companies that anger me to no end are the ones like Behringer.  I have bought several of their products over the years and quite frankly they are useless.  The products may be good quality and well priced for what they are - but their product support is crap.

My latest example - FCA202 - a log-cost firewire audio interface.  Supports windows XP and "maybe" vista, but certainly doesn't support any 64bit OS. 

Works fine under OS X though - so now I'm kind of being forced into getting a new sound board just for windows... just so I can listen to a couple of MP3's when I boot into bootcamp? 

Tags:

Thread-Safe DotNet UI Updates

by Administrator 17. April 2010 06:18

I can’t count the number of times I’ve had problems in Multi-Threaded C# / VB apps, nor can I count the number of times I’ve had to Google for the solution to this common problem.  This week I finally found a generic method to handle the situation where you want to update UI from another thread.

 

public static class ThreadSafeInvokeExtension
{
    public static void ThreadSafeInvoke<T>(this T @control, Action<T> toPerform) where T : ISynchronizeInvoke
    {
        if (@control.InvokeRequired)
            @control.Invoke(toPerform, new object[] { @control });
        else
            toPerform(@control);
    }
}

To use the extension method just do something like this:

textBox1.ThreadSafeInvoke(box => box.Text = value);

For more information on the Action<T> delegate used in this method check out the MSDN page here : http://msdn.microsoft.com/en-us/library/018hxwa8.aspx

Another good use for the Action<T> delegate is on Steve Smith’s blog here : http://stevesmithblog.com/blog/eliminate-repetition-with-action-lt-t-gt/

Tags:

Things To Research Further

by Administrator 14. April 2010 08:46

I've been listening to Scott Hanselman's podcasts (www.hanselman.com) in the car recently and have heard about a few interesting projects that I think would be worth further investigation.

Also a couple of libraries I've used before but I think I need to research a bit further.

As part of my project to port AirpCap I think the QuickGraph library could come in very handy as a simple way to graph AP - Client associations and display them graphically.

Tags:

Porting AirPCap to C#

by Administrator 9. April 2010 12:51

As part of my security work I often perform wireless audits of 802.11a/b/g/n networks and use a variety of tools to manage this. A couple of weeks ago I finally got myself a CACE Technologies Airpcap NX device. It's a small USB wireless adaptor with two external antenna connections. The NX model supports packet transmission or injection also.

I've written a few custom tools before using the SharpPcap library for DotNet and figured I would do a couple more to utilise the enhanced capabilities of the new hardware. Out of the box it works a treat, and is visible to SharpPcap (and any other winpcap applications I suspect), however the airpcap specific features are not exposed through these apps. The only applications which support the full functionality of the device are some custom versions of aircrack and kismet which use cygwin to run on windows.

So, this brings me to my first opensource project. I've decided I should extend the functionality of SharpPcap to support an additional device type and expose the full capabilities of the airpcap hardware.

More details to come...

Tags: