Example #1
0
        private void SendNotificationDestination(NotificationDestination notification)
        {
            String          jsonConfig          = null;
            String          provaider           = null;
            String          title               = null;
            String          message             = null;
            String          typeNotification    = null;
            NotificationLog notificationLogSave = null;

            if (notification.NotificationMessageBase != null)
            {
                title   = ResolveParamsMessageDinamyc(notification.NotificationMessageBase.TitleMessage, notification.NotificationMessageBase.TitleParams, notification.ParamsTitleBase);
                message = ResolveParamsMessageDinamyc(notification.NotificationMessageBase.MessageBase, notification.NotificationMessageBase.MessageParams, notification.ParamsMessageBase);
            }

            typeNotification = notification.CatalogNotificationType.NotificationType;

            if (!String.IsNullOrEmpty(notification.TitleSpecifict))
            {
                title = notification.TitleSpecifict;
            }
            if (!String.IsNullOrEmpty(notification.MessageSpecifict))
            {
                message = notification.MessageSpecifict;
            }

            jsonConfig = notification.CatalogNotificationType.NotificationConfig.JsonConfig;
            provaider  = notification.CatalogNotificationType.NotificationConfig.ProvaiderNotification;
            if (notification.Notify)
            {
                notificationLogSave = NotificationLogs.SaveNotificationLogs(new NotificationLog()
                {
                    IdNotificationCondition = notification.NotificationConditions.IdNotificationCondition,
                    TaleName           = notification.TableName,
                    TableKeys          = notification.TableKeys,
                    IdTypeNotification = notification.IdNotificationType,
                    EventName          = notification.NotificationConditions.NotificationEvents.EventName,
                    TableEvent         = notification.NotificationConditions.NotificationEvents.TableName,
                    DateSend           = DateTime.Now,
                    TitleMessage       = title,
                    Message            = message,
                    WasSend            = false,
                    BaseSend           = notification.BaseSend
                });

                if (Enum.TryParse(typeNotification, out TypeNotification typeNotificationEnum) && Notify.Send(notification.BaseSend, title, message, jsonConfig, typeNotificationEnum, provaider, out String a))
                {
                    notificationLogSave.WasSend = true;
                    NotificationLogs.SaveNotificationLogs(notificationLogSave);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 推播器實體建立
        /// </summary>
        /// <param name="destination">通知目的地</param>
        /// <returns></returns>
        public static IPusher CreateInstance(NotificationDestination destination)
        {
            IPusher pusher;

            switch (destination)
            {
            case NotificationDestination.Mobile:
                pusher = new MobilePusher();
                break;

            case NotificationDestination.Desktop:
                pusher = new DesktopPusher();
                break;

            default:
                throw new Exception($"尚未實作 { destination } 推播器");
            }

            return(pusher);
        }