XAF already provides strong and flexible validation for any object that fits specified Rules with build-in the Validation Module. In this post you can find a sample XAF application which extends the Validation to provide support for Warning/Information messages.
The implementation uses any Validation Business Rule that exists in XAF’s Application Model. Below we see the default ones but its applicable to custom business rules as well.
The sample code extends the Application Model of IModelRuleBase and by using one more property like RuleType marks the rule as warning or information as shown:
When the Validation occurs this implementation will not raise exceptions for Warning and Information Rules and will change their notification icon accordingly.
Windows
Web
By default, it is also possible to create business rules that evaluated when an object is changed by using the ObjectSpaceObjectChanged custom context (see also Contextual Validation Concepts).
To use this RuleType functionality discussed today in your XAF Applications you need to download the sample from RuleType.zip. The functionality is described by just one controller in RuleTypeController.cs which is spanned across the platform agnostic and platform depended projects.
Note: I “borrow” the code for RuleType support from our community project expandframework and for one more time we clearly see how flexible is XAF and how powerful to provide reusable solutions!
P.S.: The original eXpand implementation has code support using a RuleTypeAttribute as well as ListView support and can be found in Xpand.ExpressApp.Validation, Xpand.ExpressApp.Validation.Win and Xpand.ExpressApp.Validation.Web assemblies (See also this discussion in eXpand’s forums).
Thursday, May 2, 2013
UI Annotation using Business Rules
Wednesday, April 17, 2013
Dressing up an Entity Framework model with a rich app UI in 5 min
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.
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.
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.
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.
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.
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:
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.
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).
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!
Monday, April 15, 2013
Migrating a legacy real world application
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
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. | 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. |
| Data Validation | |
| A real world application without strong validation support is unstable and has huge support times. | 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 | • We plugged-in a mechanism that allows to control any component at runtime from Dressing up our classes – Date with a model tonight!. |
| 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. |
| 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. | XVideoRental uses the built-in Reports Module which natively integrates our award winning XtraReports suite and provides a runtime designer. |
| 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! |
| 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. |
| 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!
Thursday, March 7, 2013
Socialized XAF
XAF community is really active, there are many places where you can participate in XAF related conversations, ask for dedicated help from other devs etc. Depending on your choice, to follow anything new comes along you can subscribe to your favorite RSS or site for the following list.
| XAF official RSS | Posts from our blog. |
| XAF Facebook page | Official XAF Facebook page (includes blog posts). |
| XAF Facebook group | Join other XAF users there and discuss anything XAF related with them. |
| XAF LinkedIn group | A XAF dedicated group on Linked. |
| XAF twitter | Tweets new posts. releases etc. (Follow us to get notified). |
| Other XAF bloggers RSS | A list of several personal XAF related posts. (Apostolis Bekiaris, Dennis Garavsky, Manuel Grundner, Mike Calvert:, Nathanial Wools, Robert Anderson, Martynas Dauciunas and more. Let me know at apostolisb@devexpress.com if you want to ride this feed as well. |
| eXpand Twitter or Tweeterfeed | Tweets everything in this list plus new eXpand releases plus new Git commits. |
| eXpand’s main RSS | The most complete XAF info source currently available. Contains everything is XAF/eXpand related from official XAF and community sites. |
| Samples’s forum | A forum dedicated to community samples/ideas. Feel free to post anything interesting there. We will review it and add it to eXpand’s code base. |
In addition if you or your company are doing XAF consultancy or trainings, feel free to contact us to get you listed in our XAF consultancy page.
Friday, February 22, 2013
Dashboards in the real world – A Scotland strike!
The DevExpress Universal Subscription now includes an interactive data visualization Dashboard for Windows, the Web and Mobile devices. DevExpress Dashboard helps you deliver solutions that allow any enterprise to visually explore business trends using stunning and easily understood performance indicators.
If you are an XAF user, you already know that a framework such as XAF provides reusable building blocks to quickly build feature-rich business applications for Windows or the Web. In this post, I’ll discuss how Stephen Manderson, an XAF user from Scotland merged the capabilities of XAF and DevExpress Dashboard to create a new reusable XAF Dashboard module.
To best demo this Dashboard integration, we’ll use our XVideoRental RWA demo. The sample is available for your review at the bottom of this post.
XAF users already know that dashboard support is part of the shipping product. A few days ago I posted Visiting Dashboards where I discussed possible use case scenarios and extensions of the native implementation in order to deliver dashboard solutions to address real problems without writing any code!
Stephen Manderson was recently asked by a customer if it was possible for end users to create dashboards without going through IT to request changes and modifications to their system. The solution as you can imagine was the migration of the Dashboard Suite to his XAF application.
Stephen’s goals were simple.
- Create dashboards like any other BO at runtime.
- Pass any number of Target Persistent Object as data sources.
- Restrict access to dashboards based on Roles.
The DashboardDesigner
This step is really easy, we only need to drag this DashboardDesigner component into a simple empty windows form:
Displaying custom forms in XAF requires no special skills and is well documented: How do I show a custom window?
Create dashboards like any other BO at runtime
Working with XAF is straight forward. We have a DX component (DashboardDesigner) and we want to integrate it. Almost all our components are serializable and the DashboardDesigner is no exception. This means that we need a Persistent object to host the Xml for the layout and a collection of XAF BO Types that will be assigned as data sources.
To start we can use the following interface:
public interface IDashboardDefinition {
int Index { get; set; }
string Name { get; set; }
Image Icon { get; set; }
bool Active { get; set; }
string Xml { get; set; }
IList<ITypeWrapper> DashboardTypes { get; }
}
For the sake of simplicity I wont post the full implementation however you can grab it and follow its history in eXpand’s github repo or in the sample at the end of this post.
The Xml property along with the Designer’s LoadFromXml method can be used to load the Designer’s layout. So we need:
- To create a SimpleAction in a ViewController. We choose a ViewController instead of any other Controller simply because targeting a certain view and not the whole app.
- Then we configure the controller a bit further, to activate it only for BO that implements IDashboardDefinition.
- Finally we subscribe to SimpleAction’s Execute event, and we load the Windows form with the Dashboard designer component.
public class DashboardDesignerController : ViewController {
readonly SimpleAction _dashboardEdit;
public DashboardDesignerController() {
_dashboardEdit = new SimpleAction(this, "DashboardEdit", PredefinedCategory.Edit);
TargetObjectType = typeof(IDashboardDefinition);
_dashboardEdit.Execute += dashboardEdit_Execute;
}
public SimpleAction DashboardEditAction {
get { return _dashboardEdit; }
}
void dashboardEdit_Execute(object sender, SimpleActionExecuteEventArgs e) {
using (var form = new DashboardDesignerForm()) {
new XPObjectSpaceAwareControlInitializer(form, Application);
form.LoadTemplate(View.CurrentObject as IDashboardDefinition);
form.ShowDialog();
}
}
In the above snippet we chose to implement the LoadTemplate method in the DashboardDesignerForm because the Dashboard’s XML loading is not of XAF concern. This form is simply another separate windows based layer.
Visualizing our business data in the designer
The dashboard designer allows for us to see our XAF data and shape our dashboards in real time as shown:
This designer is similar to our Reports designer but does not offer support for dynamic members aliases. However we covered them in depth in Dynamic member aliases from Application Model.
Dashboards in action
To visualize our dashboards we have to:
- Dynamically populate the navigation menu items
We want to extend XAF’s functionality therefore we need to find the responsible built-in controller. This leads to ShowNavigationItemController where we can subscribe to its events and populate the navigation items from DashboardDefinition persistent objects. A possible implementation can be found in sample in WinDashboardNavigationController.cs or you can follow its history online.
- Modify XAF’s security system to restrict access to dashboards based on Roles.
Since we really care about making it easy for the business user, the sample is using a possible implementation as discussed in depth in User friendly way to add permissions.
- Display the dashboard’s using built-in DashboardViewer control.
Here we easily can follow an SDK sample: How to show custom forms and controls in XAF (Example). In short we need to create and return a new DashboardViewer control by overriding the CreateControlCore method of a PropertyEditor. In case we want to access extra system info we may use a different class than a PropertyEditor as discussed in Implement Custom Property Editors.
Our active dashboards are linked in the “Dashboards” navigation group; this can be renamed and reordered so all changes are reflected within this group. The end result in post’s sample looks like:
What’s next?
Stephen is already working in a State Machine designer plus an integration with XAF’s KPI module which gives dashboard its full power according to his words! Forgot to mention that a web version of Dashboards is coming soon!
Big thanks to Stephen Manderson for sharing this cool XAF implementation with us, I am sure this post/contribution will boost his spirit/cv/carrier a bit
, We welcome any of you that wants to share it’s cool XAF stuff with the rest of us. Feel free to use our Support Center for this or our community project.
Please do not forget your feedback about what we discussed today.
Unit next time Happy XAF’ing as always!
Download XVideoRental sample here. The sample contains the following modification
- User friendly way to add permission migrated in Common.Win.General namespace.
- XVideorental references DynamicMemberAliases.Module from Domain Components+ Calculated properties + Application Model.
- XVideorental references ProvidedAssociation.Module from Modifying Business Objects using Attributes.
- XVideorental references eXpand’s/Stephen's Dashboard module.




