Пример #1
0
        public async Task PublishNotificationMessage(BL_PushNotificationMessageTypeEnum pushNoticationType, string userprofileId, string entitityId)
        {
            try
            {
                var blsettings = await GetBusinessLogicSettings();

                var deviceDetails = await _repo.FindAppCenterDeviceDetail_ByUserIdAsync(userprofileId);


                if (deviceDetails.Count == 0)
                {
                    LCLog.Information($"PushNotifications - for UserId:{userprofileId} - Unable to publish PushNotification of type '{pushNoticationType}' since no deviceId(s) found.");
                }
                else
                {
                    var firstName = await GetCachedFirstname_byUserIdAsync(userprofileId);

                    foreach (var item in blsettings.AppCenterPushNotificationApiUrls)
                    {
                        var endpoint = item.Value;
                        var os       = map.From(item.Key);

                        var deviceIds = deviceDetails.Where(e => e.TypeOfDeviceOs == os).Select(e1 => e1.DeviceId).ToList();
                        if (deviceIds != null && deviceIds.Count > 0)
                        {
                            var notificationDetails = blsettings.AppCenterPushNotificationMessageTypes.SingleOrDefault(e => e.Key == pushNoticationType).Value;

                            if (notificationDetails != null)
                            {
                                var languageLocaleKey = "";
                                if (notificationDetails.TemplatePerLanguageLocale.TryGetValue(languageLocaleKey, out var messageTemplate))
                                {
                                    await _appCenterService.PublishPushNotificationDtoAsync(
                                        endpoint
                                        , deviceIds
                                        , pushNoticationType.ToString()
                                        , messageTemplate.TitleTemplate
                                        , messageTemplate.BodyTemplate
                                        , new Dictionary <string, string> {
                                        { "Page", notificationDetails.CustomData_Page },
                                        { "UserData", BL_Settings.ParsePushNotificationCustomData_UserData(notificationDetails.CustomData_UserData, firstName) },
                                        { "EntityId", entitityId ?? "" }     //For some reason App Center does not allow null here and responds with a 400
                                    }
                                        );

                                    LCLog.Information($"PushNotifications - for UserId:{userprofileId} - Succeeded to publish PushNotification of type '{pushNoticationType}' to '{endpoint}' for OS '{os}' for {deviceIds.Count} deviceid(s):{string.Join(" | ", deviceIds)}");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LCLog.Fatal(ex, $"PushNotifications - for UserId:{userprofileId} - Failed to fail publish PushNotification of type '{pushNoticationType}'");
            }
        }
Пример #2
0
        internal PushNotificationMessageTypeEnum From(BL_PushNotificationMessageTypeEnum key)
        {
            switch (key)
            {
            case BL_PushNotificationMessageTypeEnum.Type_EBA_Points_Sent:
                return(PushNotificationMessageTypeEnum.Type_EBA_Points_Sent);

            case BL_PushNotificationMessageTypeEnum.Unknown:
                throw new BusinessLogicException(ValidationErrorCode.NotFound, "", $"Unable to map enum of type {nameof(BL_PushNotificationMessageTypeEnum)} with with value '{key}' to value of type {nameof(PushNotificationMessageTypeEnum)}");

            default:
                throw new BusinessLogicException(ValidationErrorCode.NotFound, "", $"Unable to map enum of type {nameof(BL_PushNotificationMessageTypeEnum)} with with value '{key}' to value of type {nameof(PushNotificationMessageTypeEnum)}");
            }
        }