using System.Collections.Generic;
using System.Threading.Tasks;
using Abp.Extensions;
using Abp.Threading;
namespace Abp.Configuration
{
///
/// Extension methods for .
///
public static class SettingManagerExtensions
{
///
/// Gets value of a setting in given type ().
///
/// Type of the setting to get
/// Setting manager
/// Unique name of the setting
/// Value of the setting
public static async Task GetSettingValueAsync(this ISettingManager settingManager, string name)
where T : struct
{
return (await settingManager.GetSettingValueAsync(name)).To();
}
///
/// Gets current value of a setting for the application level.
///
/// Setting manager
/// Unique name of the setting
/// Current value of the setting for the application
public static async Task GetSettingValueForApplicationAsync(this ISettingManager settingManager, string name)
where T : struct
{
return (await settingManager.GetSettingValueForApplicationAsync(name)).To();
}
///
/// Gets current value of a setting for a tenant level.
/// It gets the setting value, overwritten by given tenant.
///
/// Setting manager
/// Unique name of the setting
/// Tenant id
/// Current value of the setting
public static async Task GetSettingValueForTenantAsync(this ISettingManager settingManager, string name, int tenantId)
where T : struct
{
return (await settingManager.GetSettingValueForTenantAsync(name, tenantId)).To();
}
///
/// Gets current value of a setting for a user level.
/// It gets the setting value, overwritten by given tenant and user.
///
/// Setting manager
/// Unique name of the setting
/// Tenant id
/// User id
/// Current value of the setting for the user
public static async Task GetSettingValueForUserAsync(this ISettingManager settingManager, string name, int? tenantId, long userId)
where T : struct
{
return (await settingManager.GetSettingValueForUserAsync(name, tenantId, userId)).To();
}
///
/// Gets current value of a setting for a user level.
/// It gets the setting value, overwritten by given tenant and user.
///
/// Setting manager
/// Unique name of the setting
/// User
/// Current value of the setting for the user
public static async Task GetSettingValueForUserAsync(this ISettingManager settingManager, string name, UserIdentifier user)
where T : struct
{
return (await settingManager.GetSettingValueForUserAsync(name, user)).To();
}
///
/// Gets current value of a setting.
/// It gets the setting value, overwritten by application and the current user if exists.
///
/// Setting manager
/// Unique name of the setting
/// Current value of the setting
public static string GetSettingValue(this ISettingManager settingManager, string name)
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueAsync(name));
}
///
/// Gets current value of a setting for the application level.
///
/// Setting manager
/// Unique name of the setting
/// Current value of the setting for the application
public static string GetSettingValueForApplication(this ISettingManager settingManager, string name)
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForApplicationAsync(name));
}
///
/// Gets current value of a setting for a tenant level.
/// It gets the setting value, overwritten by given tenant.
///
/// Setting manager
/// Unique name of the setting
/// Tenant id
/// Current value of the setting
public static string GetSettingValueForTenant(this ISettingManager settingManager, string name, int tenantId)
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForTenantAsync(name, tenantId));
}
///
/// Gets current value of a setting for a user level.
/// It gets the setting value, overwritten by given tenant and user.
///
/// Setting manager
/// Unique name of the setting
/// Tenant id
/// User id
/// Current value of the setting for the user
public static string GetSettingValueForUser(this ISettingManager settingManager, string name, int? tenantId, long userId)
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForUserAsync(name, tenantId, userId));
}
///
/// Gets current value of a setting for a user level.
/// It gets the setting value, overwritten by given tenant and user.
///
/// Setting manager
/// Unique name of the setting
/// Tenant id
/// User id
///
/// Current value of the setting for the user
public static string GetSettingValueForUser(this ISettingManager settingManager, string name, int? tenantId, long userId, bool fallbackToDefault)
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForUserAsync(name, tenantId, userId, fallbackToDefault));
}
///
/// Gets value of a setting.
///
/// Type of the setting to get
/// Setting manager
/// Unique name of the setting
/// Value of the setting
public static T GetSettingValue(this ISettingManager settingManager, string name)
where T : struct
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueAsync(name));
}
///
/// Gets current value of a setting for the application level.
///
/// Type of the setting to get
/// Setting manager
/// Unique name of the setting
/// Current value of the setting for the application
public static T GetSettingValueForApplication(this ISettingManager settingManager, string name)
where T : struct
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForApplicationAsync(name));
}
///
/// Gets current value of a setting for a tenant level.
/// It gets the setting value, overwritten by given tenant.
///
/// Type of the setting to get
/// Setting manager
/// Unique name of the setting
/// Tenant id
/// Current value of the setting
public static T GetSettingValueForTenant(this ISettingManager settingManager, string name, int tenantId)
where T : struct
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForTenantAsync(name, tenantId));
}
///
/// Gets current value of a setting for a user level.
/// It gets the setting value, overwritten by given tenant and user.
///
/// Type of the setting to get
/// Setting manager
/// Unique name of the setting
/// Tenant id
/// User id
/// Current value of the setting for the user
public static T GetSettingValueForUser(this ISettingManager settingManager, string name, int? tenantId, long userId)
where T : struct
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForUserAsync(name, tenantId, userId));
}
///
/// Gets current value of a setting for a user level.
/// It gets the setting value, overwritten by given tenant and user.
///
/// Type of the setting to get
/// Setting manager
/// Unique name of the setting
/// User
/// Current value of the setting for the user
public static T GetSettingValueForUser(this ISettingManager settingManager, string name, UserIdentifier user)
where T : struct
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForUserAsync(name, user));
}
///
/// Gets current values of all settings.
/// It gets all setting values, overwritten by application and the current user if exists.
///
/// Setting manager
/// List of setting values
public static IReadOnlyList GetAllSettingValues(this ISettingManager settingManager)
{
return AsyncHelper.RunSync(settingManager.GetAllSettingValuesAsync);
}
///
/// Gets a list of all setting values specified for the application.
/// It returns only settings those are explicitly set for the application.
/// If a setting's default value is used, it's not included the result list.
/// If you want to get current values of all settings, use method.
///
/// Setting manager
/// List of setting values
public static IReadOnlyList GetAllSettingValuesForApplication(this ISettingManager settingManager)
{
return AsyncHelper.RunSync(settingManager.GetAllSettingValuesForApplicationAsync);
}
///
/// Gets a list of all setting values specified for a tenant.
/// It returns only settings those are explicitly set for the tenant.
/// If a setting's default value is used, it's not included the result list.
/// If you want to get current values of all settings, use method.
///
/// Setting manager
/// Tenant to get settings
/// List of setting values
public static IReadOnlyList GetAllSettingValuesForTenant(this ISettingManager settingManager, int tenantId)
{
return AsyncHelper.RunSync(() => settingManager.GetAllSettingValuesForTenantAsync(tenantId));
}
///
/// Gets a list of all setting values specified for a user.
/// It returns only settings those are explicitly set for the user.
/// If a setting's value is not set for the user (for example if user uses the default value), it's not included the result list.
/// If you want to get current values of all settings, use method.
///
/// Setting manager
/// User to get settings
/// All settings of the user
public static IReadOnlyList GetAllSettingValuesForUser(this ISettingManager settingManager, UserIdentifier user)
{
return AsyncHelper.RunSync(() => settingManager.GetAllSettingValuesForUserAsync(user));
}
///
/// Changes setting for the application level.
///
/// Setting manager
/// Unique name of the setting
/// Value of the setting
public static void ChangeSettingForApplication(this ISettingManager settingManager, string name, string value)
{
AsyncHelper.RunSync(() => settingManager.ChangeSettingForApplicationAsync(name, value));
}
///
/// Changes setting for a Tenant.
///
/// Setting manager
/// TenantId
/// Unique name of the setting
/// Value of the setting
public static void ChangeSettingForTenant(this ISettingManager settingManager, int tenantId, string name, string value)
{
AsyncHelper.RunSync(() => settingManager.ChangeSettingForTenantAsync(tenantId, name, value));
}
///
/// Changes setting for a user.
///
/// Setting manager
/// User
/// Unique name of the setting
/// Value of the setting
public static void ChangeSettingForUser(this ISettingManager settingManager, UserIdentifier user, string name, string value)
{
AsyncHelper.RunSync(() => settingManager.ChangeSettingForUserAsync(user, name, value));
}
}
}