Accelerator. Getting Started
Getting Started
To use Xafari.Accelerator module, it is required to inherit from the WinApplication class (or WebApplication, respectively) and override ApplicationModelManager and OnSetupStarted methods, code snippets below demonstrate this.
WinApplication:
- c#
- VB
public partial 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);
}
}
Public Partial Class NorthwindWindowsFormsApplication
Inherits WinApplication
Protected Overrides Function CreateModelManager(ByVal boModelTypes As IEnumerable(Of Type)) As ApplicationModelManager
Return Me.Xafari().Win().CreateModelManager(boModelTypes, MyBase.CreateModelManager)
End Function
Protected Overrides Sub OnSetupStarted()
Me.Xafari().OnSetupStarted(MyBase.OnSetupStarted)
End Sub
End Class
WebApplication:
- c#
- VB
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);
}
}
Public Class NorthwindAspNetApplication
Inherits WebApplication
Protected Overrides Function CreateModelManager(ByVal boModelTypes As IEnumerable(Of Type)) As ApplicationModelManager
Return Me.Xafari().Web().CreateModelManager(boModelTypes, MyBase.CreateModelManager)
End Function
Protected Overrides Sub OnSetupStarted()
Me.Xafari().OnSetupStarted(MyBase.OnSetupStarted)
End Sub
End Class
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 unchanged. Such approach protects the application from any negative effects that newly implemented methods can cause.
After these modifications, you can add the Xafari.Accelerator module to the application via the Application Designer or in config-file. Xafari.Utils.dll and Xafari.dll assemblies are required too.
Important.
Xafari.Accelerator requires the application to run in .NET 4.5.1+ mode.
Run application without debug, select Tools|Start Accelerator Action and click it, this Action is available for the Administrator Role only. The success message will appear:
Exit from application, Xafari.Accelerator will be in use as soon as the application is started the next time. The administrator of the application can use the Stop Accelerator Action in the Tools tab to disable Xafari.Accelerator. The appropriate message will appear:
The Accelerator will be disabled during the next start 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).
When it is needed to turn the Accelerator off for a particular period only, use the Xafari.Accelerator key in the configuration file:
- xml
<configuration>
<appSettings>
<add key="Xafari.Accelerator" value="False" />
</appSettings>
<configuration>
Alternatively, the Accelerator can be temporarily disabled in the code as shown below:
Start Accelerator from Code
In general, it is not recommended to start the Accelerator from code. The fact that you will have to restart the app anyway to begin using the cache. However, the Accelerator API provides methods to start and stop, they are listed below:
- Application.Xafari().Accelerator().CreateFullAcceleratorModel();
- Application.Xafari().Accelerator().DeleteFullModelCache();
For instance, you can call these methods in window controller.
Where you can store Accellerator's files
The Accelerator's 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. It is possible to save Accellerator.xafml file to anther directory by use standart DevExpress methods.