Xafari Server. AppModule Implementation

In the described application to create a separate AppModule is not necessarily. In this example, the AppModule functionality is implemented in a platform-independent application module. Execute the following steps:

  • Add DevExpress.ExpressApp.Security.vXX.Y, Xafari и Xafari.MQ assemblies to the module References.
  • Add DevExpress.ExpressApp.Security.SecurityModule, Xafari.XafariModule and Xafari.MQ.XafariMQModule using DevExpress designer.
  • Configure application in DemoAppModule class as follows
  • c#
  • VB

public sealed partial class DemoAppModule : ModuleBase
{
  private readonly SecurityStrategyComplex _securityStrategy;
  public DemoAppModule()
  {
  var authentication = new AuthenticationActiveDirectory();
  authentication.CreateUserAutomatically = true;
  authentication.LogonParametersType = null;
  _securityStrategy = new SecurityStrategyComplex();
  _securityStrategy.Authentication = authentication;
  _securityStrategy.RoleType = typeof(SecuritySystemRole);
  _securityStrategy.UserType = typeof(SecuritySystemUser);
}
public override void Setup(XafApplication application)
{
  base.Setup(application);
  Application.ApplicationName = "DemoApp";
  Application.Security = _securityStrategy;
  Application.CustomizeLanguagesList += Application_CustomizeLanguagesList;
  Application.CreateCustomObjectSpaceProvider += Application_CreateCustomObjectSpaceProvider;
  Application.DatabaseVersionMismatch += DemoAppWindowsFormsApplication_DatabaseVersionMismatch;
}
private void DemoAppWindowsFormsApplication_DatabaseVersionMismatch(object sender, DatabaseVersionMismatchEventArgs e)
{
  e.Updater.Update();
  e.Handled = true;
}
private void Application_CreateCustomObjectSpaceProvider(object sender, CreateCustomObjectSpaceProviderEventArgs e)
{
  if (e.ObjectSpaceProvider == null)
  {
    var app = (XafApplication)sender;
    var security = (SecurityStrategy)app.Security;
    e.ObjectSpaceProvider = new SecuredObjectSpaceProvider(security, e.ConnectionString, e.Connection);
  }
}
private void Application_CustomizeLanguagesList(object sender, CustomizeLanguagesListEventArgs e)
{
  string userLanguageName = Thread.CurrentThread.CurrentUICulture.Name;
  if (userLanguageName != "en-US" && e.Languages.IndexOf(userLanguageName) == -1)
  {
    e.Languages.Add(userLanguageName);
  }
}
}

Public Partial NotInheritable Class DemoAppModule
  Inherits ModuleBase
  Private ReadOnly __securityStrategy As SecurityStrategyComplex
  Public Sub New()
    Dim authentication = New AuthenticationActiveDirectory()
    authentication.CreateUserAutomatically = True
    authentication.LogonParametersType = Nothing
    __securityStrategy = New SecurityStrategyComplex()
    __securityStrategy.Authentication = authentication
    __securityStrategy.RoleType = GetType(SecuritySystemRole)
    __securityStrategy.UserType = GetType(SecuritySystemUser)
  End Sub
  Public Overrides Sub Setup(ByVal application As XafApplication)
    MyBase.Setup(application)
    Application.ApplicationName = "DemoApp"
    Application.Security = __securityStrategy
    Application.CustomizeLanguagesList += Application_CustomizeLanguagesList
    Application.CreateCustomObjectSpaceProvider += Application_CreateCustomObjectSpaceProvider
    Application.DatabaseVersionMismatch += DemoAppWindowsFormsApplication_DatabaseVersionMismatch
  End Sub
  Private Sub DemoAppWindowsFormsApplication_DatabaseVersionMismatch(ByVal sender As Object, ByVal e As DatabaseVersionMismatchEventArgs)
    e.Updater.Update()
    e.Handled = True
  End Sub
  Private Sub Application_CreateCustomObjectSpaceProvider(ByVal sender As Object, ByVal e As CreateCustomObjectSpaceProviderEventArgs)
    If e.ObjectSpaceProvider Is Nothing Then
      Dim app = CType(sender, XafApplication)
      Dim security = CType(app.Security, SecurityStrategy)
      e.ObjectSpaceProvider = New SecuredObjectSpaceProvider(security, e.ConnectionString, e.Connection)
    End If
  End Sub
  Private Sub Application_CustomizeLanguagesList(ByVal sender As Object, ByVal e As CustomizeLanguagesListEventArgs)
    Dim userLanguageName As String = Thread.CurrentThread.CurrentUICulture.Name
    If userLanguageName <> "en-US" AndAlso e.Languages.IndexOf(userLanguageName) = -1 Then
      e.Languages.Add(userLanguageName)
    End If
  End Sub
End Class

As you can see in the code above, Security configuration is implemented in constructor.

To use Xafari Server, application must satisfy the following requirements:

  • Security Strategy is DevExpress.ExpressApp.Security.SecurityStrategyComplex
  • Object Space Provider is DevExpress.ExpressApp.Security.ClientServer.SecuredObjectSpaceProvider, set it in Application_CreateCustomObjectSpaceProvider event handler.
  • Initialize application name (it's important to work RunCmd.exe) and customize LanguageList in Setup method.

All the code that duplicate these functions in the DemoApp.Win.WinApplication class, should be removed from DemoApp.Win.WinApplication class.