Using Xafari Services in Updater

To modify the services settings use SafeUpdateDatabaseAfterUpdateSchema() method of the XafariModuleUpdater class. After modifying and saving the settings, make sure that the ServiceManager.Instance.LoadServicesModel() method is called. This method is needed to load the changes.

The code below demonstrates how to copy Branches settings from a persistent object to the Services Model.

  • c#
  • VB

public class Updater : XafariModuleUpdater
{
  public Updater(IObjectSpace objectSpace, Version currentDBVersion)
    : base(objectSpace, currentDBVersion)
  {
  }
  public override void SafeUpdateDatabaseAfterUpdateSchema()
  {
    base.SafeUpdateDatabaseAfterUpdateSchema();
    this.CreateBranchesSettingsObject();
    this.ObjectSpace.CommitChanges();
    ServicesModelService.Instance.Reset();
  }
  internal void CreateBranchesSettingsObject()
  {
    var settingsObject = GetSettingsObject();
    var objectSpace = this.Xafari().ObjectSpace;
    var branchesSettings = objectSpace.Xafari().ServicesModel().Edit.Branches();
    branchesSettings.Enabled = settingsObject.BranchSwitchOn;
    branchesSettings.EnabledTypes = settingsObject.BranchEnabledTypes;
    branchesSettings.ReadMode = settingsObject.ReadMode;
  }
}

Public Class Updater
  Inherits XafariModuleUpdater
  Public Sub New(ByVal objectSpace As IObjectSpace, ByVal currentDBVersion As Version)
    MyBase.New(objectSpace, currentDBVersion)
  End Sub
  Public Overrides Sub SafeUpdateDatabaseAfterUpdateSchema()
    MyBase.SafeUpdateDatabaseAfterUpdateSchema()
    Me.CreateBranchesSettingsObject()
    Me.ObjectSpace.CommitChanges()
    ServicesModelService.Instance.Reset()
  End Sub
  Friend Sub CreateBranchesSettingsObject()
    Dim settingsObject = GetSettingsObject()
    Dim objectSpace = Me.Xafari().ObjectSpace
    Dim branchesSettings = objectSpace.Xafari().ServicesModel().Edit.Branches()
    branchesSettings.Enabled = settingsObject.BranchSwitchOn
    branchesSettings.EnabledTypes = settingsObject.BranchEnabledTypes
    branchesSettings.ReadMode = settingsObject.ReadMode
  End Sub
End Class