Click or drag to resize

Configuration of tenants

The provided API enables additional, advanced configuration of tenants.

Operations on different sets of rules are permitted according to users' attributes defined in Active Directory. This way, delegated users can work directly on a particular set of rules (e.g. rules associated with a specific group of employees only), without access to other rules. Furthermore, if you want to use any existing tenants defined in the program or to create new tenants in your custom app, you should download AdvancedSettings (these settings contain information on tenants and message splitting) from the Settings Storage WCF Service using DownloadAdvancedSettings:

C#
//Download advanced settings and check tenants
var settingsStorage = new ER.SDK.SettingsStorageClient("SettingsStorageHttpEndpoint");
var advancedSettings = settingsStorage.DownloadAdvancedSettings();
var tenants = advancedSettings.Tenants;

By default, CodeTwo Exchange Rules Pro doesn't recognize tenants, therefore the methods defined in the Settings Storage WCF Service have the name of the parameter associated with tenants set to null. To create a tenant, you need to generate a tenant object and set the values of its properties. Next, download advanced settings from the Settings Storage WCF Service, add the created tenant to the collection of advanced settings and upload the settings back to the Settings Storage WCF Service in the way shown below. This way the newly created tenant will be recognized by the Exchange Rules Service and automatically propagated to all instances of the Exchange Rules Service in your environment.

Code entity reference: Tenants

C#
//Create a tenant object and set the values of properties
var tenant = new Settings.Advanced.Tenant();
tenant.Name = "Company1";
tenant.LdapPropertyName = "extensionAttribute15";
tenant.ComparisonType = C2Common.AD.EnumComparsionType.typeEquals;
tenant.PropertyValue = "Sample value";

//Download advanced settings
var settingsStorage = new ER.SDK.SettingsStorageClient("SettingsStorageHttpEndpoint");
var advancedSettings = settingsStorage.DownloadAdvancedSettings();

if (advancedSettings.Tenants == null)
{
    advancedSettings.Tenants = new Settings.Advanced.TenantsCollection();
}

//Add the tenant to a collection
advancedSettings.Tenants.Add(tenant);

//Upload the settings to SettingsStorage
settingsStorage.UploadAdvancedSettings(advancedSettings);

The example below shows how to create a rule applicable to one particular tenant only:

C#
//Create a new rule
var rule = new Settings.RuleDesc();
rule.ID = Guid.NewGuid().ToString();
rule.Name = "Sample rule";

//Activate the rule
rule.Active = true;

//Create a Block message action and add it to the created rule
var actionBlockMessage = new Settings.Actions.ActionBlockMessage();
rule.Actions.Add(actionBlockMessage);

//Create a snapshot and add the rule to this snapshot
var snapshot = new Settings.ItemsSnapshotT<Settings.RuleDesc>();
snapshot.NewItems = new Settings.RuleDesc[] { rule };
snapshot.AllItemsIds = snapshot.NewItems.Select(r => r.ID).ToArray();

//Upload the snapshot to SettingsStorage for Company1 tenant
var client = new ER.SDK.SettingsStorageClient("SettingsStorageHttpEndpoint");
client.UploadChanges("Company1", snapshot);
See also

Message splitting - how to implement a message splitting configuration into a custom app via the provided API.