Απρίλιος 2013 - Δημοσιεύσεις

Dressing up an Entity Framework model with a rich app UI in 5 min
17 Απριλίου 13 04:36 πμ | tolisss | 0 σχόλια   

Imagine that we have already build a mobile app using DXTREME such as the DXSK8 demo and already have a ready-to-use Entity Framework data model. Now we are faced with a task to provide a rich administrative application that will be mainly used in Intranet from the desktop (Windows) or web browser. This application should have a typical CRUD UI for managing goods in an online shop, content on our main web site, etc. and of course have potential for future extensibility and customization by a customer request. Following the instructions of this post it should be easy to do it your self from scratch in less than five minutes! (Sample app at then end of this post).

1) Create a XAF Cross-platform application

Create a new XAF solution called DXSK8.Admin by using the DXperience v12.2 XAF Cross-Platform Application project template as shown below.

image

Below we see the created solution which contains two ready to run XAF applications (DXSK8.Admin.Win, DXSK8.Admin.Web) and three empty XAF modules where the DXSK8.Admin.Module is the platform agnostic one. We are going to work in the platform agnostic module because we want to minimize code duplication between our Win and Web XAF applications.

image

2) Adding Entity Framework model types to XAF

XAF auto generates rich CRUD UI for our data using our award-winning DevExpress visual components. However our Entity Framework model is located in an external library so in our platform agnostic module we need to reference the EF model container which is the DXSK8.Service assembly along with the System.Data.Entity and DevExpress.ExpressApp.EF assemblies.

image

Next its time to add the all the EF model entities in our application business model by using the following code in the constructor of this platform agnostic module.

image

public sealed partial class AdminModule : ModuleBase {

    public AdminModule() {

        InitializeComponent();

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Customer));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Address));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Brand));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Employee));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.ImageSource));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Login));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.NotificationChannel));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Order));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.OrderItem));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Person));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Product));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.ProductFlavor));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.ProductType));

        AdditionalExportedTypes.Add(typeof(DXSK8.Service.Store));

    }

As a result now the XAF Application Model contains all types from the EF model and we are ready to use it we are ready to modify the auto generated Views, define the navigation structure or empower our app with built-in or open source modules.

image image

For example in the sample app in the end of the post we used the Model Editor to modify the model of the platform agnostic module and create a Navigation menu for both platforms as shown:

image

Note: Creating Navigation Items is fully described in XAF docs (Add an Item to the Navigation Control). In addition you can find a detail tutorial and a big list of How To that can help you get the most out of XAF really fast!

3) Switch the Application to Using the Entity Framework

We continue to work in the platform agnostic DXSK8.Admin.Module. To use the EFObjectSpace instances to access data we need to provide an IObjectSpaceProvider implementation designed for EF and located in DevExpress.ExpressApp.EF assembly. For this we need to modify again our Module.cs codebehind class as shown.

Note that EFObjectSpaceProvider’s first parameter is Entity Framework’s ObjectContext implementation from DXSK8.Service project.

    public override void Setup(XafApplication application) {

        base.Setup(application);

        application.CreateCustomObjectSpaceProvider += ApplicationOnCreateCustomObjectSpaceProvider;

    }

 

    void ApplicationOnCreateCustomObjectSpaceProvider(object sender, CreateCustomObjectSpaceProviderEventArgs e) {

        var typesInfo = (TypesInfo)Application.TypesInfo;

        const string metadata = "res://*/SK8Data.csdl|res://*/SK8Data.ssdl|res://*/SK8Data.msl";

        const string provider = "System.Data.SqlClient";

        var objectContextType = typeof(DXSK8.Service.SK8DataContainer);

        e.ObjectSpaceProvider = new EFObjectSpaceProvider(objectContextType, typesInfo, null, e.ConnectionString, metadata, provider);

    }

Note: XAF will not modify the schema of your existing database!

Conclusion

Microsoft recommends when accessing data to use Entity Framework, which from v5 is open sourced and has an unlimited list of add-ons and really big audience. We used this amazing technology to create the DXSK8 data service and in this post we demoed how to use XAF with three simple steps to manage its content by creating rich CRUD UI views as below on the spot. Therefore it should be clear that we can deliver app prototypes for our EF models really fast and our end users can enjoy access to their data with modern UI look & feel from day one! Note that XAF has a lot of build-in and open sourced modules that can be install with a simple drag and drop and can save you months of work.

In the next images we see two of the default auto generated XAF CRUD Views one for each platform (Win and Web).

image

image

For those of you that you have Entity Framework models and you want to try these instructions on them you may download an XAF trial from here.

Sample Download (Contains DXSK8.Service project as well).

In next post we will continue with a discussion over reusable EF models in XAF stay tuned!

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

Until next time,

Happy XAF’ing!

Subscribe to XAF feed
Subscribe to community feed

Δημοσίευση στην κατηγορία: ,
Migrating a legacy real world application
15 Απριλίου 13 02:56 πμ | tolisss | 0 σχόλια   

Recently we made the decision to clone our Winforms VideoRent real world application and create a new XAF application – the XVideoRental. Wearing my LEGO designer hat Smile I will go through all migration steps as if I were in your shoes.

XVideoRental uses only a small part of XAF tooling –>Native modules + Code Central examples + open sourced project and community resources. All the time invested was for gathering ready to use implementations and putting them in a reusable project agnostic library. In addition since all these ready to use implementations exist already in our community project (eXpand) we created a second open source version of XVideoRental where this project agnostic library does not exist so we consumed even less resources for building it!

As you can read in the overview post the XVideoRental contains almost zero designed time code and everything is described declaratively in XAF’s Application Model xafml file, allowing full customization after distribution.

Real world applications are really demanding. We spend huge times for first release and in most cases is very poor compared to the next ones. The reason is simple, we do not have enough time to prepare a domain-specific language (DSL) that will bridge business requirements with our existing technical tooling/knowledge. Therefore we try to re-invent the wheel in many areas whereas XAF exists as the most comprehensive tooling available. Using application model and the Security System, XAF fully describes and configures the behavior of platform agnostic applications. Both Application Model and Security System are the technology abstraction or in other words the DSL language we need to minimize the time to market cost of a real world application.

We recommend:

1.  Watch the BUILDING A PROJECT MANAGER APPPLICATION IN 5 MIN video where we used the same LEGO designer approach as in XVideoRental in a simpler application as our MainDemo.



2.  Go for a quick overview of XVideoRental by reading XVideoRental real world application (RWA) – The overview.
3.  Go through the next table where from these simple statistics it should be clear the tremendous gain we get when developing with the XAF way.

  Number of projects Classes Lines of code
Legacy VideoRent
Location:
Four non reusable projects  256 27965
XAF XVideoRental • 1 project agnostic library
• 1 non reusable module
• 1 front end application almost unmodified as  created from VS templates
-
77
5
-
806
126
Open Sourced XVideoRental • References open sourced libs (project agnostic lib not exist)
• 1 non reusable module
• 1 front end application almost unmodified as  created from VS templates
-
36
5
-
807
126

In short the legacy app is using 256 classes. The XVideoRental much less 77 and 90% or them are simply concrete implementations from the referenced project agnostic library. However in the 3rd row where this project agnostic library is replaced from a reference to our open source project that number of classes goes further down to only 36!

Legacy app location:               %Public%\Documents\DXperience 12.2 Demos\Common\DevExpress.VideoRent.Win\CS\
XAF app location:                   %Public%\Documents\DXperience 12.2 Demos\eXpressApp Framework\XVideoRental\CS\
Open source XAF app location:
http://www.expandframework.com/downloads/download.html –>Demos\XVideoRental\

4.  Finally go through the list bellow where we compare the legacy and XAF application side by side.

Legacy VideoRent

XAF XVideoRental

Data Access  

• Legacy app uses ORM technology and our XPO to describe the video rent business. However special skills needed and extra efforts to create a clear separation from  other layers, so many helper classes exists even for very common tasks such as database connectivity.

• XAF has built-in support for both XPO and MS Entity Framework. We can simply utilize the legacy domain model by simply copy- paste the classes. Helper classes are of no use because XAF can handle all common tasks transparently for us!

• A real world application requires an importing mechanism for initial data. The legacy app imports data from xml files with structure that fits exactly to the structure of the business objects. Therefore even for a small  change in the BO design we need to modify and retest this mechanism.

• XVideoRental plugs-in an abstract domain agnostic importing engine from Fast prototyping requires an initial data import mechanism, allowing us to modify the structure of BO in the minimum time possible. In addition how to Supply Initial Data is well documented sparing our time for making architectural decisions.

• In a real world application sequential number integration is essential. However special design and knowledge is needed to be able to build something reliable.

• XVideoRental operates under a business application framework therefore a rich click and run SDK provides solutions to such common problems E2829. So  the developer only needs to integrate and not to think about the technical difficulties or guess the showstoppers.

Architecture  

Legacy app has a design time modularization based on Forms/UserControls/(Bussiness Concept). However it is not possible to extended it without adding new Forms and recompiling the whole application inside VS. In addition because of the lack in documentation determining the best place to write code for a specific behavior can still cause big headaches.

Application life cycle is component centric and was invented on demand for the current application.

XVideoRental demo is using XAF’s well-documented and simple to use MVC architecture. Also, while the discussed application is a simple fat client app, demanding users looking for something more advanced may also find a ready to use client-server solutions in XAF.

• VS templates to fast create modules. which by design are reusable and independent from main application.
• Well documented Application life cycle guide us where we to write code (e.g. Setup, Login, View Activation etc.)
• Simple to follow tutorial on how to Extend Functionality.
• Detailed guide of all the main concepts for building business applications.

Data Validation  

A real world application without strong validation support is unstable and has huge support times.
Building a validation engine is not trivial at all and requires third party components which will raise the cost even further. 
Therefore the legacy application time frame and budget wouldn’t allow any investment here and there is no validation support.

Creating validation rules does not require you to be a developer, even end-users can create them because it is quite easy and intuitive, not more difficult than creating a filtering rule in your Outlook. We only need to install the build-in Validation module!

Data Representation  

The legacy application a large number of components. Therefore the developer requires A huge amount of mundane, repetitive work was invested to:

XAF has native support for a large number of DX components. Automatic UI generation (CRUD detail and list forms, navigation and menu systems - all based on data models).  This is a huge time saver because almost every typical business application contains a good percentage of list and detail forms, navigation and menu systems - all linked together without any effort from your side.

• Create a large number of data entry forms, drag & drop numerous controls on it, arrange their positions and configure data bindings
• Providing a consistent look and feel is not an easy job and requires deep knowledge of a large number of components as well as a special design
• Interact with the database through XPO, create CRUD operations and support transactions needs careful considerations and a lot of time, so it was done as basic as possible by simply pushing non mandatory tasks such as undo operations and transaction for the next application release Smile.
• In an agile real world the navigation menu system should be controlled as declaratively as possible. However legacy app does not conform this requirement resulting in huge update times for every customer request.
• Extend XtraReports for every Business object we want to create reports.
• Design reports inside VS making their support  impossible in real world.
• Design analysis views inside VS making their support impossible in real world.

• We plugged-in a mechanism that allows to control any component at runtime from Dressing up our classes – Date with a model tonight!.
• A business rule driven Pivot editor borrowed from How to rule the Pivot we showed how to marry business requirements with a complex component like Pivot.
• Legacy code was converted on the spot to declarative as in Tooltips to the max - expressive UI.
• From Visiting dashboards we add a ready to use extension that provides collaboration for our views.
• We went over expectations by simply installing a community module from Dashboards in the real world – A Scotland strike.

Application Configuration  

Although most of the components can persist their state there is no application level integration by default. In addition their serialization is not designed to be human friendly and its hard to edit and support. The legacy developer had to create an integration mechanism deep in application’s infrastructure. This costly. wrap-up was as basic as possible and target only a few major forms producing a non consistent feeling.

XVideoRental is a XAF application which by design is described declaratively in XAF’s Application Model. Using Model Editor at runtime an end user can modify any part of the app.

However we didn’t spend the 10 min required to plugin the ModelDifference community module and consume the application from a persistence storage such as a database cause we were  building a clone and not demo the endless features of XAF!

Zero migration resources for this one!

Application Security  

The legacy developer tried to create a basic security implementation. However he soon realized that the efforts needed for something useful and reliable will probably exist the efforts for building the whole application. So, unfortunately due to app budget there is no investment in implementing a security system.

Our time frame here was really loosed since we already have a mature plug n’ play Security module. This flexibility allows us to plugin more goodies such as User Friendly permissions and  metadata based permission policies

Reporting  

The major goal of business applications is to be able to create and print reports.

Therefore the legacy app has a dedicated project for reporting. In which the developer had to use Visual Studio for report design. As a result he loosed any chance to update them on demand after project distribution which is a really common case.

At the same time the reports were extended and bound to VideoRent business objects making the whole implementation not reusable from any other project.

XVideoRental uses the built-in Reports Module which natively integrates our award winning XtraReports suite and provides a runtime designer.

The module saves the reports in the database so our job was to copy paste the Reports layout from the legacy app and distribute them as discussed in Distribute the Created Reports with the Application.

Moreover we provided collaboration/filtering with other views using as usual a no code approach as discussed in Visiting dashboards.

Data Printing and Export  

The legacy developer had to write special code for each control on your forms that he wished to print or export. Although this functionality is very useful in real world again the time frame wouldn’t allow such an investment.

XVideoRental can export data from the grid, pivot, chart, tree view, layout and others to a wide number of formats (PDF, RTF, TXT, CSV, HTML, MNT, XLS, XJSX, PNG, GIF, JPG, BMP, TIFF, WMF, EMF) without spending not even 1 minute to install or configure the system!

You probably can guess why eh? As usual XAF has a built-in generic mechanism for all controls out of the box!

Data Analysis  

Legacy app has a whole structure to support only a few data analysis views for the 4 major BO which are Customer, Movie, Receipt and Rent. Huge amount of code is located in dedicated forms for each analysis views making the solution not able to survive in real world. The reason of course is  that for each new customer request the developer has to change the code inside VS recompile and redistribute the app. A common example is a calculated value where it needs a UI to define these members, special algorithms to create them

XVideoRental uses the build-in Pivot Chart Module which as usual shifts development to the runtime allowing business users to modify the analysis display at any time. Uses the extended Pivot from How to rule the Pivot. Empowering the app with the dashboard suite as in Dashboards in the real world – A Scotland strike! was as simple as drag & drop the module from VS toolbox!. Essential for data analysis runtime calculated members as in Domain Components+ Calculated properties + Application Model was in the menu as well.

Localization  

There are technics for localizing .NET application via satellite assemblies however they do not localize application specific data and they are very time consuming, so the legacy app does not support any kind of localization

XAF supports all standard localization approaches and also addresses the problems that occur with them. With XAF, it is always possible to localize any part of your application at runtime (e.g., correct certain values from satellite assemblies). A convenient wizard provides the capability to use online translation services from MS, Google, etc. So, it is possible to leave the localization job to non-programmers who can easily import/export data without leaving the application.

Customizing Controls Appearance  

Even for the simplest operation like making bold a grid column or hiding a control from a view developer time is needed as long as recompilation and redistribution of the application

XVideoRental addresses this declaratively using the Conditional appearance module and the technic described in Dressing up our classes – Date with a model tonight! where any component can be serialized and controlled declaratively from XAF’s application model using the runtime Model editor.

This is control-agnostic and we spared our time digging into the specifics of each control – XAF did everything for us!

Implementing Custom Business Requirements  

Lets talk a concrete example here. The legacy app uses tooltips to create a more expressive UI. However even if the developer wrote a decoupled class at the end he has to attach it to various controls and forms. This makes the whole design not flexible since changes require developer presence.

XVideoRental can use the same decoupled class from the legacy application. However it simply attaches the behavior to application model instead of attaching it to controls and forms. This solution is project agnostic and allows later changes from a non programmer at runtime! This process is discussed in details in Tooltips to the max - expressive UI.

Getting Help and Support  

Application and developer are simply married. If for any reason they divorced then everything becomes very unstable and tricky. It is really hard to find another developer to continue support a legacy app. Even if we manage to do so the cost will be extremely high since there are no docs, support etc.

XVideoRental uses bricks/samples from XAF’s code central and community project. Thus by design there is a large number of developers that can support its code base. Not to forget the unmatched documentation and support we can get from the XAF team.

   

Conclusion

Even thought XAF does not contain solutions to each and every business problem in the world,  the framework is very strong in providing its own extensibility ( "preventing the lock-in effect").  It is fast and easy to plugin solutions to common business problems, at the end XAF is a Domain Specific Language that  that can bridge business requirements with our existing technical tooling/knowledge!

Until next time,

Happy XAF’ing!

Subscribe to XAF feed
Subscribe to community feed

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

Search

Go

Το Ιστολόγιο

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

Συνδρομές