public static async Task HandleServiceNotification(this IAppConfigurationService configurationService, bool retrieveCached = false, Action failureHandler = null,
string serviceNotificationTitleKey = Constants.AppConfigurationServiceNotificationTitleKey,
string serviceNotificationBodyKey = Constants.AppConfigurationServiceNotificationBodyKey,
string serviceNotificationShowKey = Constants.AppConfigurationServiceNotificationDisplayingKey)
{
if (configurationService == null) return;
configurationService.Mapper.EnsurePresence(serviceNotificationTitleKey);
configurationService.Mapper.EnsurePresence(serviceNotificationBodyKey);
configurationService.Mapper.EnsurePresence(serviceNotificationShowKey);
var appConfig = await configurationService.LoadAppConfig(retrieveCached);
if (appConfig == null) return;
var showServiceNotification = appConfig.GetValueForKey<bool>(serviceNotificationShowKey);
if (showServiceNotification)
{
//Alert users
var serviceNotificationTitle = appConfig.GetValueForKey<string>(serviceNotificationTitleKey);
var serviceNotificationBody = appConfig.GetValueForKey<string>(serviceNotificationBodyKey);
if (!string.IsNullOrEmpty(serviceNotificationTitle) &&
!string.IsNullOrEmpty(serviceNotificationBody))
{
if (failureHandler != null)
{
//developer might have the custom action rather than displaying out alert
failureHandler.Invoke();
}
else
{
await configurationService.BlockAppFromRunning(serviceNotificationBody, serviceNotificationTitle);
}
}
}
}