Tag Archive for 'xLim'

Matrix algorithm for rendering XtraLayout designs into Web UI

In the past post on using XtraLayout component by DevExpress as a simple but powerful run-time designer I’ve mentioned rendering designs into Web UI. Here’s simple recipe for the matrix algorithm that is actually used to render XtraLayout-generated form designs in web UI of xLim 2 implementation.

Matrix algorithm for rendering XtraLayout designs into Web UI

This implementation does not require creating groups for every logical section like it has been done in XAF Web UI (and defining some custom orientation direction there) - all group contents sit within one table. Additionally this makes the designs reusable for WPF, Windows.Forms and Silverlight UI rendering (xLim 2 compatible renderer prototypes already exist for the first two).

Basically the UI rendering process happens in two steps. First, we check out every single control in the group and register its coordinates. We are only interested in unique X and Y values at this step.

Then, we count number of unique non-zero X values (that’s the number of columns in our table) and number of unique non-zero Y values (that’s the number of rows in our table). After that we calculate the sizes of these columns and rows (derive them from actual X, Y values). Widths will get sizes in percentages, since normally we want our forms to resize with the browser window.

In second pass we simply render all the controls into cells of the HTML table, while assigning appropriate RowSpan and ColSpan to these cells.

What about extending xLim2 with DSL implementations?

As you can see from the overview article, the minimal development cost of implementing first Domain Specific Language in your solution is:

Cost(generic_DSL_framework) + Cost(specific_DSL_implementation)

where initial cost of generic DSL framework could be close to zero, if you reuse Boo compiler and Rhino.DSL. And the cost of specific DSL implementation normally revolves around writing the appropriate base class with all the syntax specifications.

Now, when you have all this in place, development cost of adding another DSL implementation to your solution (in the optimistic scenario) would just depend on creating yet another base class.

So, if it looks so easy for us to add different Domain Specific Languages to our information management solution, what could we do?

  • DSL for workflow definitions (WWF is just too heavy)
  • DSL for the complex security rules
  • Business rules DSL
  • DSL for specifying Smart Client UI composition for different user roles (composite web UI could reuse this, too)
  • Message routing rules

And remember, that you can compile these DSL implementations to .NET at build-time (this results in easier development) or at run-time (also adds flexibility of run-time configuration of the system).

Given all this efficient flexibility at low development cost (and possibly low maintenance costs), it is no wonder that Boo-based DSLs are being considered for the introduction into the architecture concept of building lightweight extensible information management systems.

Obviously, pros and cons of this step are yet to be researched, but I already could think of some big chunks of code, that could be thrown out of the existing xLim 2 implementations.

XPO hosted on a web site (remoting with binary encoding + http channel)

Below you will find an extremely simple prototype that uses XPO hosted within web application (http channel) with the binary encoding. You will need to have DevExpress components installed and Visual Studio 2008.

Now, before you continue, here is an important caveat - don’t use XPO in any complex project. It will just become bottle-neck there.

In my case complex project means:

  • 41 Visual Studio projects (74k LOC and 35k statements)
  • 3 integration projects on CC.NET
  • 417 revisions over 6 months
  • 2Gb+ FileStore in production system
  • All the features of the xLim 2 approach (and some more)

Here’s the Kiviat metrics graph:

xLim 2-2 Kiviat Graph

And these are some of the problems with the XPO:

  • Linq2XPO implementation is horrible (I’m not even talking about decent documentation)
  • Flexibility is extremely low (most of all I miss custom mapping routines and ability to specify custom queries)
  • Generated SQL is quite inefficient in complex requests
  • Remote communication is too chatty by default

As you can see, these problems of mine mostly come from the Lego scenario.

If I were able to start the project from scratch, then I’d probably (would have to do some prototyping first) use NHibernate. Half a year ago there was no chance of using it, since DX controls would not be able to work with NHibernate in server mode.

Ok, you have been warned. Now you finally can download sample of XPO hosted on a web site (remoting with binary encoding + http channel).

From Web Services to IIS-hosted remoting: XPO performance improvement.

Switching from “XPO over Web Service” to “XPO over IIS hosted remoting” made select operations 20% faster for the average usage scenario in xLim. Adding Forms Authentication on top of the remoting didn’t have any significant impact.

Note, that in this test scenario the remote server was located on the ASP.NET Intermediate shared hosting plan in CrystalTech data center. Desktop Smart Client was located on the opposite side of the Earth. If we remove the distance factor (ping between these two points is 245ms on the average), then the speed improvement for this scenario is 26%.

No optimization to the HttpChannel code has been done. Although, probably bringing over the compression logics from WCF would yield better performance results (at the cost of CPU load).

Update: sample can be downloaded here.

One more usage of the XtraLayoutControl - cross-platform UI designer

DevExperience has a nice control called XtraLayoutControl. Basically it allows you to have your own form designer at run-time.

XtraLayoutControl in action

But it can easily do more than just reshuffling of existing items for the Desktop UI. You can design forms that will be rendered on Desktop and Web alike.

eXpressAppFramework team has started using its capabilities of the design management, but I believe they can go even further if they:

  • Forget about pseudo-groups with custom orientation flags and keep positioning and size information of the design elements.
  • Add a couple of simple layout elements that are stored in the layout only (i.e. LayoutLabel, LayoutImage).
  • Use full design information for rendering detail views on the Web.
  • Forget about the model and persist the design in the DB.
  • Actually it is quite easy to go even further on this read and push all view schemas, data schemas and even form storage schema (if they implement Forms) to the database (thus allowing to change all that on-the-fly).

All the above items are quite easy to implement. I know that for sure since they constitute logically separate module in xLim 2 - “Record and Form Management” (Flexible Grids + Details + Forms) and that has already been done more than once.

There’s even more of that. I believe that the information generated by the XtraLayoutControl is enough to create similar interfaces not only for Web and Desktop, but for WPF and GTK# also (would not you want to have the perspective of reusing your nicely crafted forms on Linux platforms?)

Desktop UI Form produced by XtraLayout designer

Web UI Form produced by Xtra Layout designer

xLim 2 Engine concept or simple continuous integration for businesses

xLim 2 Engine is an extremely simple concept and continues the idea from post on “How to simplify complex maintenance tasks of your information management solution?“.

So, if you have architecture like this, you can just:

  • take multiple maintenance and automation tools of yours
  • throw out all the repetitive code (connection, logging, security, etc) and wrap everything that remains with some common interface (ICommand or Action<IContainer> are equally fit here)
  • Create some simple host (Win Service, Mono daemon, Console Application) that establishes an IoC environment by loading the shared assemblies (by just asking the shared module to register), then resolves every command in a dedicated scope and runs it.

Since the commands are just ordinary IoC components, you can configure them in some XML file and provide the parameters. The resulting config file will resemble NAnt build file quite a bit. The only difference is that you are playing with business objects, workflows and services instead of some low-level development entities.

And since the engine talks to the main server via the common gateway interface (and uses some access account for this), you can be sure that

  • all possible harm will be limited by the permissions defined by the account
  • logging and audits will be applied

We recently had to implement similar automation engine for the current xLim 2 implementation. That was extremely easy with this concept, since all we had to write was the engine host (200LOC for the console implementation) and the actual command logic. Shared modules lent us all the other required functionality (and even a couple of ICommand implementations were reusable)

Now, you’ve just got your simple business integration engine. Adding new tasks is trivial here, since you have to worry only about the actual code (the engine and IoC will DI all the required interfaces from the shared modules). Given that, you can easily:

  • Send warning if some system goes short on DB or HD space
  • Save sales numbers every 1 hour to capture the statistics for future analysis
  • Fire alarms if some KPIs go out of range
  • Send message to admin if that document processor service is not responding again
  • Alert developers if there are any exceptions in the server log

It is an interesting coincidence that Ayende had written about the continuous validation concept in his web log. That fits quite close in this picture, although I believe he mixes two different concepts that logically should be separated: Environment Validation Framework and the Automation Engine.

Basically, the validation framework is just some IValidationReporter interface that is supported by some singleton components living in the root scopes of the application being validated. And then there is some component that generates composite validation report per request and sends it to the external monitoring system.

Now, why do we want to separate environment validation from the engine? These are the reasons:

  • System might not have the components/interfaces for running regularl environment validation checks and then taking some actions based on complex logic (do you want to add that extra code in there just for that?)
  • Configurations of different systems might have different ways of going invalid (i.e.: some systems could have recommended HD limit of 40Mbs while others could be limited to 40GBs, some could require access to dedicated workflow server and some could just live without that). You would not to spread that info with every config.
  • Some failures could be detected only after being aggregated (i.e. work cluster could be considered to be in invalid state if all nodes are consistently overloaded)
  • Some failures could be linked to external systems (i.e. HD space allocation for the user depends on type of the account of his company)

So it seems to be more efficient to have dedicated automation engines (you could have as many of them as you want) to handle all the meta-system logic, while leaving only report generation to the actual system being monitored.

Running xLim with latest Mono: XPO, autofac and binary compatibility

This is the update to the previous R&D post on running xLim (XPO+Autofac) under Mono 1.2.6.

Short summary:

  • Latest autofac code passes all tests with the latest mono sources
  • The dictionary issue (the one that required patching XPO sources) is fixed in the latest mono code
  • Binary remoting does not work for XPO purposes.

The reason for the last problem is simple: Mono and .NET implementations of the DateTime object are completely different. Serialized Mono DateTime uses more bytes than .NET implementation. The first one does not implement ISerializable, while the last one - does. That could make some difference.

Miguel de Icaza has pointed to the topic in Mono FAQ on the subject of binary compatibility between .NET and Mono. It turns out that the DateTime is not one of these compatible types. I wonder if there are other incompatible primitives or widely-used classes.