Example #1
0
        public static async void SendNotification(string message, List <NotificationType> types)
        {
            NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(Setting.HUB_Path, Setting.HUB_Name);

            foreach (var t in types)
            {
                var notification =
                    NotificationMessage.SetNotification(t, message);

                switch (t)
                {
                case NotificationType.FCM:
                    await hub.SendFcmNativeNotificationAsync(notification);

                    break;

                case NotificationType.WND:
                    await hub.SendWindowsNativeNotificationAsync(notification);

                    break;

                default:
                    await hub.SendFcmNativeNotificationAsync(notification);

                    break;
                }
            }
        }
Example #2
0
        public List <NotificationResponse> SendNotification(NotificationRequest request)
        {
            List <NotificationResponse> response = new List <NotificationResponse>();

            if (request.Types != null)
            {
                foreach (var type in request.Types)
                {
                    NotificationOutcome send = new NotificationOutcome();

                    string notification =
                        NotificationMessage.SetNotification(type, request.Message, request.WindowsNotificationId);

                    Exception e = null;

                    try
                    {
                        switch (type)
                        {
                        case NotificationType.FCM:
                            send = _hub.SendFcmNativeNotificationAsync(notification).Result;
                            break;

                        case NotificationType.WND:
                            send = _hub.SendWindowsNativeNotificationAsync(notification).Result;
                            break;

                        default:
                            send = _hub.SendFcmNativeNotificationAsync(notification).Result;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        e = ex;

                        continue;
                    }
                    finally
                    {
                        response.Add(new NotificationResponse
                        {
                            Type    = type,
                            Success = (e == null),
                            Error   = e?.Message
                        });
                    }
                }
            }


            return(response);
        }