Exemplo n.º 1
0
        private Task SendApplicationPushNotification(PushNotification message, string deviceType, string pushUrl)
        {
            var pushNotificationPayload = new PushNotificationPayload
            {
                Content = message.Content,
                Target  = new PushNotificationTarget
                {
                    DevicePushTokens = message.DevicePushTokens
                                       .Where(x => x.DeviceType == deviceType)
                                       .Select(x => x.Token)
                                       .ToList()
                }
            };

            if (!pushNotificationPayload.Target.DevicePushTokens.Any())
            {
                return(Task.CompletedTask);
            }

            var jsonMessage = this.SerializeNotification(pushNotificationPayload);

            this.logger.Debug($"Serialized {deviceType} notification message: {jsonMessage}");

            return(this.SendPushNotificationRequest(pushUrl, jsonMessage));
        }
Exemplo n.º 2
0
        private string SerializeNotification(PushNotificationPayload message)
        {
            var serializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            return(JsonConvert.SerializeObject(message, serializerSettings));
        }