Useful safety check for the property and content type subset functionality

In the articles Different subsets of properties in different EPiServer multi sites using same content type model and Different subsets of content types in different EPiServer multi sites with all types in one assembly you can read about adding subsets of properties and content types to different EPiServer installations that run on the same code.

Here is a quick safety check that will save debugging and potential headache down the line.

Exception showing available values that you may add to your MultiSiteId setting.

The Exception message will be based on what available flags you have put in your MultiSiteId flag enum.

ScannerInitializer.cs

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ScannerInitializer : IInitializableModule
{
  public void Initialize(InitializationEngine context)
  {
    var currentId = (MultiSiteId) Properties.Settings.Default.MultiSiteId;
    if (currentId == MultiSiteId.None)
    {
      throw new Exception(Message);
    }
  }

  private static string Message
  {
    get
    {
      var values = (MultiSiteId[]) Enum.GetValues(typeof(MultiSiteId));
      var options = values.Where(v => v != MultiSiteId.None).Select(v => $"{(int)v} ({Enum.GetName(typeof(MultiSiteId), v)})");
      var message = $"You need to set a MultiSiteId value != 0 (None) in web.config section Platform.Core.Properties.Settings. Available values are: {string.Join(", ", options)}";
      return message;
    }
  }

  public void Uninitialize(InitializationEngine context) { }
}