Sunday, December 4, 2016

Xafari x011. Overview

Xafari x011 has a number of new features and performance enhancement for some solutions. I hope we published first build of Xafari x011 in January, 2017.

AppStarter

AppStarter is a special utility for starting a win-application deployed on the file server of the corporate network. The utility preliminarily downloads the application on the local computer and then starts the local copy of the application. The utility can also be used for .net optimization.

Combined usage of AppStarter utility and Xafari.Accelerator module reduces application start time by at least 3 times on the client computer.


 AppStarter utility allows managing several applications at a time. When the application is started, the utility checks the current available application version and downloads the up-to-date version. For simpler application usage, the utility allows creating a shortcut on the desktop for each used application.

AppStarter also has a number of opportunities simplifying its operation by the administrator when using the application.

DX NewStyle for Xafari MVC

Xafari MVC supports NewStyle analogue for Web Xaf-application. We saved complete usability of NewStyle for touch-screen devices, and all advantages of ASP.NET over WebForms are available.

Performance enhancement for Xafari.MVC

Xafari.MVC uses a new original concept for working with modal windows. The new approach significantly reduces response time for opening modal windows regardless of complexity of the displayed view. The new concept also helped to minimize memory leaks in the client application.

We have taken into account a number of improvements made in DX 16.1.8, which allowed reducing time leaks when implementing parallel AJAX-queries.

In general, applications developed using Xafari MVC have become more stable and reliable when working under “load”.

Simplifying of use eXtensions Framework (XF)

We have performed refactoring of the eXtensions Framework (XF) module, which allowed simplifying of the module as well as adding new features. Now it is easier and more convenient to use XF, and ERP applications have become more flexible and adjustable.

Persistent model

The model of generated persistent types has been changed – now it does not include inherited persistent classes. Therefore, there is no ObjectType column in persistent types table any more.

Entity registration

We have added an opportunity to register entities through attributes above types.

[RegisterEntity] // so uses to register any domain component
public interface DC1 : IXFEntity {}

[RegisterExtension(typeof(DC1))]
public interface Ext1 : IXFEntityExtension {}

Therefore, there is no need to add necessary code in the module class. Xafari allows using this approach with all DomainComponents, not only XF entities.

Model designer in VS

Now the model designer works with XF modules a lot quicker. Previously, code compilation was necessary for XF. Now, due to improvements made in Xafari x011, it is no longer required.

Working with extensions

Now the extensions are more visible in the general list of entity attributes. Previously all extensions formed the single list of attributes, now there is a separate attribute for each extension.


To access extension attributes (Ext1, Ext2) for entity (Entity1) you can use Entity1.__Ext1.Property1 or Entity1.__Ext2.Property2 (prev. Entity1.Exts.Property1 и Entity1.Exts.Property2). If you see attribute with two underscores (‘__’) at the beginning you can be sure that XF extensions are used.

New concept of Xafari ERP applications

Starting with Xafari x011, we are offering a new view on an ERP application.

From the point of view of Xafari, an ERP application is data and the data management functions, i.e. all platform-independent modules. ERP application can be used in various scenarios. Win, Web and other platform applications are hosts (or containers) for the ERP application. Platform-dependent modules are connected only to the container application.

The picture demonstrates how one application (AppModule) can be started in different hosts.

To implement such approach, Xafari introduces the concepts of AppModule and ApplicationHost. In order to simplify using this approach, we have included new Xafari ERP Solution Master in Xafari x011.

AppModule is a special XAF module, which describes all attributes of a XAF application (security, database provider etc.). We have developed a special VS designer for AppModule in Xafari, which allows conducting all operations to set up a XAF application, the same ones the standard designer from DX does. All modules connected to the application have to be listed in the AppModule.


ApplicationHost is a class equivalent to a platform host for XAF application. This class is a factory for XafApplication, and starts platform environment for the application. It also loads platform-dependent modules listed in the AppModule. The picture below demonstrates connection of Win modules to a Win application (Galaktika is an EPR application).

Using this Xafari approach allows using and maintaining the ERP application successfully in various scenarios.

EasyTests support for Xafari Win components

Xafari x011 supports EasyTest for the first set of Win components. If you use EasyTests in your work, you can now conduct tests for Xafari components.

Xafari Component wizards in VS

New Xafari ERP Solution wizard for VS

In order to simplify using Xafari ERP application concept, we have included a mew master for creating Xafari ERP Solution in Xafari x011. We want Xafari to be an extension to XAF, so we designed the master similar to XAF Solution master. Screen shots

New wizard for creating Xafari ERP application’s elements

A new master for creating Xafari ERP application’s elements has been included in Xafari x011. The master’s operating principle is similar to the relevant DX XAF master. This will help users to learn all its features quicker. Screen shots

Performance enhancement for UI DynamicProperties

The mechanism of dynamic properties is actively used by our users directly as well as by other Xafari components (AppSettings, Docflow, BulkEdit etc.). In Xafari x011, we have sufficiently improved performance of this solution, which had a positive impact on the overall usability of Xafari applications.


Now the mechanism of dynamic properties works via a special manager that creates and works with a separate application model. The manager launches the model asynchronously and does not affect the start time of the application. The manager also thoroughly uses data cashing, which results in a significant reduction of time required to create an object with dynamic properties.

Tuesday, May 24, 2016

How to accelerate XAF Application. Part 2 Logic Controllers

This article describes how to reduce number of ViewControllers and to accelerate the XAF application.

Why to use Xafari LogicControllers

WindowController and ViewController are using to implement the behavior in the Views of XAF application. And XAF application is arranged so that all controllers are collected in a single list, and for each new Frame creates a complete copy of this list. At the same time for each controller runs its entire life cycle, from creation to deletion.

This pattern of behavior is simple and clear, but it leads to a marked slowdown in creating View, when a large number of controllers implemented in the application.

Among the set of application ViewControllers can be identified separately, which do not contain their own actions and are designed to customize the behavior of View.

Xafari Framework contains a component LogicController that is designed to replace the ViewController without actions and thus greatly reduce the number of controllers in the XAF application.

According to the possibilities of using Logic Controller fully coincides with the ViewController. Also Logic Controller can only be activated for a particular case: Target View, TargetObjectType, TargetViewId.

How it's work

To manage the life cycle of LogicController there is a special LogicControllerViewController. When this controller is activated it searches LogicControllers for a suitable environment. After that the LogicController objects are activated.
When you deactivate / delete LogicControllerViewController object also deactivated / deleted all found LogicController objects.
Detail description see in article Documentation Logic Controllers.

How to start to use LogicController

You can download trial version of Xafari Framework for latest Devexpress XAF version.

LogicController is implemented in assembly Xafari.BC.
  1. Add module Xafari.BC to your module or application.
  2. Switch on Diagnostic info like described in article Determine Why an Action, Controller or Editor is Inactive.
  3. Start application and get a small report to find all ViewControllers wich can be implemented like LogicController


    This is a sample of report:

  4. In this report you can see that you can create two LogicControllers - MainDemo.Module.Win.Controllers.WinNullTextEditorController and MainDemo.Module.Win.Controllers.WinTooltipController

How to create LogicController

1. Use Visual Studio template create new LogicController

2. Modify source code as you wish

// filter LogicController activation by TargetObjectType=Contact, TargetView=DetailView
public class WinNullTextEditorLogicController : LogicControllerBase<Contact, Detailview> 
{
 private void InitNullText(PropertyEditor propertyEditor)
 {
   ((BaseEdit)propertyEditor.Control).Properties.NullText = CaptionHelper.NullValueText;
 }

 protected override void OnActivated()
 {
   // Processing logic placed in this method when OnActivated() executing.
   // Sample logic for business object
   PropertyEditor propertyEditor = ((DetailView)View).FindItem("Anniversary") as PropertyEditor;
   if (propertyEditor != null)
   {
    if (propertyEditor.Control != null)
    {
      InitNullText(propertyEditor);
    }
    else
    {
     propertyEditor.ControlCreated += new propertyEditor_ControlCreated;
    }
  }
 }
 private void propertyEditor_ControlCreated(object sender, EventArgs e)
 {
  InitNullText((PropertyEditor)sender);
  }
}
3. Add code to module class to register created LogicController

public class MainDemoWinModule : ModuleBase 
{
 public override void Setup(XafApplication application)
 {
  base.Setup(application);
  application.SetupComplete += application_SetupComplete;
 }
 private void application_SetupComplete(object sender, EventArgs e)
 {
   LogicControllerService.Instance.Register(new WinNullTextEditorLogicController());
 }
}

Alternatively, use XafariModuleBase as parent class for your module. XafariModuleBase implements method to automatic discover all LogicControllers in current assembly.

public class MainDemoWinModule : XafariModuleBase 
{
}

4. If you replace existed ViewController do not remember to remove old code from compile process.
5. Start application to see how created LogicController works.


Thursday, April 28, 2016

How to accelerate XAF application

Overview

XAF applications use the Application Model a lot. When the quantity of modules in the app grows, the Application Model becomes more complicated (because of the increasing number of layers in the Application Model). It slows the Application Model performance down and leads to notable time lags in the application itself. The growing amount of time needed for the app to start is the most obvious sign of such changes.

To solve the issue mentioned above, use the Xafari.Accelerator module designed precisely to fix the problems with the Application Model performance.

Effects of Usage

Being used in demo applications, Xafari.Accelerator showed twice as less starting time compared to the same apps without this module. The actual result for a particular project depends on the complexity of the application and the quantity of business objects in use.
The results of demo application profiling proved that the usage of Xafari.Accelerator allows excluding all operations with the Application Model from the profiling reports. When Xafari.Accelerator is not used, the operations with the Application Model are critical according to the application profiling reports.

Profiling EAM application

I profile application Galaktika.EAM and colect results of usage Xafari.Accelerator. I marked the time that has passed since the beginning of the start of the application:

StagesStandard start, сAccelerator using, сAcceleration, times
Splash screen450.8
Logon40142.85
Startup View63331.9

How to Start

Module Xafari.Accelerator is included to Xafari x08 and above.

Module Adding

To start using the module, add the overloaded methods to the descendant class as shown in two code samples below.

For WinApplication:

using System.Collections.Generic;
using Xafari;
using Xafari.Win;

public class NorthwindWindowsFormsApplication : WinApplication
{
 protected override ApplicationModelManager CreateModelManager(IEnumerable<Type> boModelTypes)
 {
  return this.Xafari().Win().CreateModelManager(boModelTypes, base.CreateModelManager);
 }

 protected override void OnSetupStarted()
 {
  this.Xafari().OnSetupStarted(base.OnSetupStarted);
 }
}

For WebApplication:

using System.Collections.Generic;
using Xafari;
using Xafari.Web;

public class NorthwindAspNetApplication : WebApplication
{
 protected override ApplicationModelManager CreateModelManager(IEnumerable<Type> boModelTypes)
 {
  return this.Xafari().Web().CreateModelManager(boModelTypes, base.CreateModelManager);
 }

 protected override void OnSetupStarted()
 {
  this.Xafari().OnSetupStarted(base.OnSetupStarted);
 }
}
Note
These methods add the necessary extension points that are further used by the accelerator. If Xafari.Accelerator is disabled or not used, the behavior of such methods remains the same. Such approach protects the application from any negative effects that newly implemented methods can cause.
Now the Xafari.Accelerator module can be added to the application in VS through the Application Model designer. It is also possible to add it other ways, e.g. via the .config file of the application.
Important
Xafari.Application requires the application to run in .NET 4.5.1+ mode.

Module Usage

Accelerator Start

By default, Xafari.Accelerator is available but not used. To start it, the administrator of the application should use the Start Accelerator option in the Tools tab.


If the operation was successful, the following popup window is shown:

Xafari.Accelerator will be in use as soon as the application is launched the next time.

Accelerator Stoppage

The administrator of the application can use the Stop Accelerator option in the Tools tab to disable Xafari.Accelerator.

If the operation was successful, the following popup window is shown:

The Accelerator will be disabled during the next launch of the application.
Note
The alternative way to disable the accelerator is to remove its files ApplicationName.Accelerator.xafml (ApplicationName.Accelerator_locale.xafml) from the same folder that stores the ModelAssembly.dll file (by default, it should be the application folder).

Temporary Accelerator Stoppage

When it is needed to turn the accelerator off for a particular period only, use the following key in the configuration file:

<configuration>
 <appSettings>
  <add key="Xafari.Accelerator" value="False" />
 </appSettings>
<configuration>
Alternatively, the accelerator can be temporarily disabled in the code as shown below:

XafariAcceleratorModule.Enabled = false

How It Works

Xafari.Accelerator core principle is the usage of a separate XML file to store the whole Application Model unchangeable part for the current combination of modules and their versions. The same idea works for localization files if there are any.
Note.
The accelerator files ApplicationName.Accelerator.xafml (ApplicationName.Accelerator_locale.xafml) are stored in the same folder that has the ModelAssembly.dll file. By default, it is the application folder.
The Accelerator then modifies the Application Model so that its unchangeable part builds upon this only file.
As a result, there are only two layers left in the Application Model: the accelerator and the user.
The Xafari.Accelerator module also extends the Application Model with extra interfaces to avoid performance issues that may happen when adding CustomMembers.

Required assemblies

  • Xafari.Utils.dll
  • Xafari.dll
  • Xafari.Win.dll (Xafari.Web.dll)
  • Xafari.Web.dll
  • Xafari.Web.Utils.dll)

Tuesday, April 12, 2016

How to quick find memory leaks on using IObjectSpace

In my practice, memory leaks in XAF application in 90% of cases occur by using undisposed IObjectSpace.


As is known in the XAF application all data operations are made through the session and IObjectSpace.
If you do not call the Dispose() method a large amount of memory will not be released. And after some time of using such a code your application grabs a huge amount of memory and this will adversely affect the performance and reliability of application.
Search for memory leaks is time consuming and requires highly skilled developer.

There is a standard approach to deal with such memory leaks by C# using keywords.


using (var objectSpace = Application.CreateObjectSpace())
{
}


But in some cases the use of the using keyword is impossible. And fix memory leaks becomes very complex task.

To simplify this task Xafari Framework provides to developers a standard solution.

Xafari implements special Controller and Action to inspect all created and not released instances of UnitOfWorks and IObjectSpace. See picture below how to run report of active instances.

Show Memory Leaks report

All active instances of UnitOfWork and IObjectSpace collected into 2 lists (see on picture). You can see information about Owner, Age and Time of creation.

IObjectSpace Memory Leaks report

Detail information additionally contains the stack trace and serves to quick find source code line to fix memory leaks.

Detail info for IObjectSpace



I hope this article is usefull for you.


Hello all XAF developers

Hi everyone
My name is Sergey Zaitsev. I am a leading developer of Xafari Framework.
This blog will discuss a variety of questions about the use DevExpress XAF and Xafari Framework.
We show some examples of how to use Xafari and XAF components, and answer your questions.