using System.Collections.Generic;
using System.Threading.Tasks;
using Abp;
using Abp.Configuration;
using Abp.Extensions;
using Abp.Threading;
namespace IwbZero.Setting
{
///
/// Extension methods for .
///
public static class IwbSettingManagerExtensions
{
///
/// 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 IIwbSettingManager 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 IIwbSettingManager settingManager, string name)
where T : struct
{
return (await settingManager.GetSettingValueForApplicationAsync(name)).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 id
/// Current value of the setting for the user
public static async Task GetSettingValueForUserAsync(this IIwbSettingManager settingManager, string name, long userId)
where T : struct
{
return (await settingManager.GetSettingValueForUserAsync(name, 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 IIwbSettingManager 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 IIwbSettingManager 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 IIwbSettingManager settingManager, string name)
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForApplicationAsync(name));
}
///
/// 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 id
/// Current value of the setting for the user
public static string GetSettingValueForUser(this IIwbSettingManager settingManager, string name, long userId)
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForUserAsync(name, 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
/// User id
///
/// Current value of the setting for the user
public static string GetSettingValueForUser(this IIwbSettingManager settingManager, string name, long userId, bool fallbackToDefault)
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForUserAsync(name, 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 IIwbSettingManager 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 IIwbSettingManager settingManager, string name)
where T : struct
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForApplicationAsync(name));
}
///
/// 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 IIwbSettingManager settingManager, string name, int? tenantId, long userId)
where T : struct
{
return AsyncHelper.RunSync(() => settingManager.GetSettingValueForUserAsync(name, 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 IIwbSettingManager 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 IIwbSettingManager 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 IIwbSettingManager 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 IIwbSettingManager 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 IIwbSettingManager 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 IIwbSettingManager 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 IIwbSettingManager 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 IIwbSettingManager settingManager, UserIdentifier user, string name, string value)
{
AsyncHelper.RunSync(() => settingManager.ChangeSettingForUserAsync(user, name, value));
}
}
}