示例#1
0
        private static void LogPushResultToDatabase(PushContext context, string message, Exception ex)
        {
            var log = new LogInfo();

            log.ChannelId = context.Subscription.ChannelId;
            log.UserUid   = context.Subscription.UserUid;
            log.Message   = message;
            if (ex == null)
            {
                log.Title = "推送成功";
                log.Level = LogInfo.LEVEL_INFO;
            }
            else
            {
                log.Title      = "推送失败";
                log.Level      = LogInfo.LEVEL_WARN;
                log.StackTrace = ex.StackTrace;
            }
            log.LogTime = DateTime.Now;
            try
            {
                PushBo.Instance.Log(log);
            }
            catch (Exception e)
            {
                Logger.Log.Error(e);
            }
        }
示例#2
0
        public void Push(DeviceSubscription subscription, Payload payload)
        {
            var context = new PushContext {
                Subscription = subscription, Payload = payload
            };

            if (OperationContext.Current != null)
            {
                context.Callback = OperationContext.Current.GetCallbackChannel <IPushCallback>();
            }

            if (subscription.Channel.PlatformType == PlatformType.Apple)
            {
                var notification = new AppleNotification(subscription.SubscriptionId)
                {
                    Tag = context
                };
                if (payload != null)
                {
                    var p = new AppleNotificationPayload();
                    p.Alert = new AppleNotificationAlert {
                        Body = payload.Alert
                    };
                    p.Badge              = payload.Badge;
                    p.Sound              = payload.Sound;
                    p.CustomJson         = payload.Custom; //https://github.com/caniusq/PushSharp
                    notification.Payload = p;
                }

                PushBrokerManager.Broker.QueueNotification(notification, subscription.Channel.ApplicationId);
            }
            else if (subscription.Channel.PlatformType == PlatformType.Beyondbit)
            {
                var notification = new BeyondBit.PushClientLib.BeyondBitNotification {
                    DeviceToken = subscription.SubscriptionId, Tag = context
                };
                if (payload != null)
                {
                    var bnp = new BeyondBit.PushClientLib.BeyondbitNotificationPayload();
                    bnp.Alert            = payload.Alert;
                    bnp.Badge            = payload.Badge;
                    bnp.Sound            = payload.Sound;
                    bnp.CustomJson       = payload.Custom;
                    notification.Payload = bnp;
                }

                PushBrokerManager.Broker.QueueNotification(notification, subscription.Channel.ApplicationId);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
 private static void LogPushResultToDatabase(PushContext context, string message, Exception ex)
 {
     var log = new LogInfo();
     log.ChannelId = context.Subscription.ChannelId;
     log.UserUid = context.Subscription.UserUid;
     log.Message = message;
     if (ex == null)
     {
         log.Title = "推送成功";
         log.Level = LogInfo.LEVEL_INFO;
     }
     else
     {
         log.Title = "推送失败";
         log.Level = LogInfo.LEVEL_WARN;
         log.StackTrace = ex.StackTrace;
     }
     log.LogTime = DateTime.Now;
     try
     {
         PushBo.Instance.Log(log);
     }
     catch (Exception e)
     {
         Logger.Log.Error(e);
     }
 }