Παρουσίαση με Ετικέτες

Fast prototyping requires an initial data import mechanism
06 Νοεμβρίου 12 04:02 πμ | tolisss | 0 σχόλια   

To improve development time and achieve better results we need to use frameworks like XAF. Moreover with XAF it’s really easy to create applications that are maintainable at runtime! After designing a domain model in VS we are almost ready to go. At this point, however we need a smart and flexible importing mechanism for feeding our domain models with initial data. Customers are impressed when they see real world data! So lets build together this mechanism proving once more the XAF power.

Requirements

  1. Domain model agnostic.

    This really means that our importing algorithms should depend only on object types. Therefore we can implement this as an attribute and decorate our domain objects. 
     
  2. Database agnostic

    XPO that supports all common database engines with its rich metadata API is our answer here.
     
  3. Flexible mapping configuration

    For this we are going to create the an XPO dictionary on the fly. Querying our domain object attributes we can map this dictionary correctly.
     
  4. Inheritance mapping configuration

    Take as example an Artist, Customer both inheriting a Person object. The attribute should allow to map different the properties of Person when Artist and when Customer.

Examples

  1. The following example imports all members that belong to MovieArtist from a table with same name columns (AllOwnMembers=true). In addition it maps the oid column in the table of the importing data store to the Oid property of VideoRentalBaseObject (BaseNMembers=”oid|Oid”). Finally it does lookup data in a data store in a table named vMovieArtist (Name=”vMovieArtist”).

    [InitialData(BaseMembers = "oid|Oid", AllOwnMembers = true,Name = "vMovieArtist")]

    public class MovieArtist : VideoRentalBaseObject {

        Artist artist;

        Movie movie;

  2. The next one imports from a table named CompanyType only the column named Name (AllOwnMembers=false, BaseMembers=null, only Name property is decorated)

    [InitialData()]

    public class CompanyType : VideoRentalBaseObject {

        [InitialData]

        public string Name {

            get { return _name; }

            set { SetPropertyValue("Name", ref _name, value); }

        }


  3. By default all object relations are auto imported unless the related object is not included in the configuration. Then only the key value is imported. It is also possible to control the mapping in many to many relations as

    public class Movie : VideoRentalBaseObject {

     

        [InitialData(DataProviderTableName = "CountryMovies", DataProviderQueryColumnName = "Movies", DataProviderResultColumnName = "Countries")]

        [Association("Movies-Countries")]

        public XPCollection<Country> Countries {

            get { return GetCollection<Country>("Countries"); }

        }

The algorithm

  1. This is an initial data import mechanism. For such operations XAF provides the ModuleUpdater. We need the XafApplication’s IObjectSpace and one UnitOfWork that connects to an external data source so we can simply design an extension method like,

    public static void Import(this IObjectSpace objectSpace, UnitOfWork unitOfWork) {

    }

    and invoke it inside UpdateDatabaseAfterUpdateSchema as,

     

    public class Updater : ModuleUpdater {

        public Updater(IObjectSpace objectSpace, Version currentDBVersion) : base(objectSpace, currentDBVersion) { }

        public override void UpdateDatabaseAfterUpdateSchema() {

            base.UpdateDatabaseAfterUpdateSchema();

            var connectionString = ConfigurationManager.ConnectionStrings["initialdata"].ConnectionString;

            ObjectSpace.Import(new UnitOfWork{ConnectionString = connectionString});

     

  2. Using XAF’s rich reflection API we can enumerate all our domain objects, search for the InitialData attribute and create an XPO dictionary on the fly! This is rather easy as XPO follows a similar to .NET structure, so we have to create XPClassInfo for Classses and XPMemberInfo for members. A great sample exists in our code central so we can get a fast start with this API (E269). Following are the 2 main methods that implement the import mapping.

    public static void ImportCore(this IObjectSpace objectSpace, UnitOfWork unitOfWork) {

        var builder = new InitDataDictionaryBuilder(objectSpace);

        builder.InitDictionary(unitOfWork);

        foreach (var persistentTypeInfo in builder.GetPersistentTypes()) {

            Import(objectSpace, builder, unitOfWork, persistentTypeInfo);

        }

        unitOfWork.CommitChanges();

    }


    internal class InitDataDictionaryBuilder {

        public void InitDictionary(UnitOfWork unitOfWork) {

            var persistentTypes = GetPersistentTypes();

            CreateMemberInfos(unitOfWork.Dictionary, persistentTypes);

        }

     
    A complete and up to date version can be found in expandframework’s github repository.


In this post we improved the already rapid XAF development, by creating the import mechanism from almost any type of data into our domain model. In the next one we will visit another great tool offered by XAF the dashboard views.

We would appreciate your feedback on this post. Has it been useful to you? Feel free to contact us with any further questions.

Happing XAFing as always!


Δημοσίευση στην κατηγορία: ,
New ImportWizard on eXpand v11
08 Ιουνίου 11 08:23 πμ | tolisss | 0 σχόλια   

I am very happy to announce the release of eXpandFramwework v11. Our team has already tested the framework in production. However any feedback or discussions the new version are most welcome. Please you our forums for better collaboration.

In addition we most welcome Martynas Dauciunas as the newest eXpandframework member. Martys joined our team along with his ImportWizard module. The module can map and import Excel files!

You can read more about it and see the demo video in our blog

As always eXpandFramework is available for download here


Δημοσίευση στην κατηγορία:
Model Distribution with IO Engine
22 Σεπτεμβρίου 10 02:28 μμ | tolisss | 0 σχόλια   
ModelDifference module is one of the powerfull modules of eXpand . It really helps in managing your application models. Scenario Your application has been already distributed to your client and you no longer have access to the production database. Your client admin is responsible for that. But since development never stops as you know, you client asked for some model modification and some new application models (lets say 10) have been developed by your team and you want to sent them to the admin to update the application. eXpand IO module is the right one for the job Step1—Create a serialization graph to configure which objects/values you are going to export In order to create a serialization graph for an object type you have 1st to create a Serialization Configuration

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία: ,
Developing data analysis objects with the help of IO module
08 Φεβρουαρίου 10 10:12 πμ | tolisss | 0 σχόλια   
After creating PivotingChart Module I was able to really control the fluent DevExpress Pivot grid options at runtime and design more complex analysis pivoting UI writing no code and save all that “configuration” at the same database record as the analysis object. But I was still developing inside my VS and since my model was not stable yet I continuous drop the database using the DxCore addin to drop database at design time which by the way have been updated to support multiple datastores and damn I lose the designed analysis UI cause it was stored in the database Time for some IO module use I could export my analysis objects and use the following code to load the configured objects at application start up from an embedded resource public class Updater : ModuleUpdater

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία: , ,
Collaborating with Xaf and IO module
18 Ιανουαρίου 10 01:02 μμ | tolisss | 0 σχόλια   
.NET provides a lot of ways to collaborate between systems. All of them are based on data serialization. XPO is missing that, and have a client project that could not live without some generic type of serialization. So I create a simple but powerful IO engine It can serialize any object that inherits DevExpress.Xpo.XPBaseObject. It will also serialize any object that is related to the root object of serialization. To control the export engine A serialization graph can be provided . Object's properties can be serialized according to Serialization Strategy enumeration      public enum SerializationStrategy     {         SerializeAsValue = 0,         SerializeAsObject,

Διαβάστε περισσότερα »

Δημοσίευση στην κατηγορία: , ,

Search

Go

Το Ιστολόγιο

Ιστορικό Δημοσιεύσεων

Συνδρομές