示例#1
0
        internal RestChannel(AblyRest ablyRest, string name, ChannelOptions options, IMobileDevice mobileDevice = null)
        {
            Name      = name;
            _ablyRest = ablyRest;
            _options  = options;
            _basePath = $"/channels/{name.EncodeUriPart()}";

            if (mobileDevice != null)
            {
                _pushChannel = new PushChannel(name, ablyRest);
            }
        }
示例#2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="appKey"></param>
 /// <param name="appSecret"></param>
 /// <param name="channel">推送通道,</param>
 /// <param name="platform">默认iOS+Android</param>
 public PushModel(string appKey, string appSecret, PushChannel channel = PushChannel.JPush, int platform = 3)
 {
     this.AppKey            = appKey;
     this.AppSecret         = appSecret;
     this.APNSIsProduction  = Push.Config.APNSIsProduction;
     this.Channel           = channel;
     this.Platform          = platform;
     this.LoggerName        = Common.DefaultLoggerName;
     this.LoggerSource      = Common.DefaultLoggerSource;
     this.Audience.Category = PushAudienceCategory.Alias;
     this.NotificationWay   = NotificationWay.APNs;
     this.LowerExtraKey     = true;
 }
        public void WhenBalancerIsShutdown()
        {
            var channelEvents = new ChannelEvents();
            this.eventsProxy = new ChannelEvents();

            var channelFactory = Substitute.For<ChannelFactory>();
            this.theChannel = Substitute.For<PushChannel>();
            this.theChannel.Events.Returns(channelEvents);
            channelFactory.Create().Returns(this.theChannel);

            this.balancer = new QueueLengthLoadBalancer(channelFactory, this.eventsProxy, PlatformType.None);

            this.balancer.AddChannels(1);
            this.balancer.ShutdownAll(true);
        }
示例#4
0
        public ActionResult SaveChannel(Subscription subscription)
        {
            using (var db = new LiteDatabase(databasePath))
            {
                PushChannel channel = new PushChannel
                {
                    ChannelUri = subscription.DeviceSubscription.Endpoint.ToString(),
                    P256Dh     = subscription.DeviceSubscription.Keys.P256Dh,
                    Auth       = subscription.DeviceSubscription.Keys.Auth
                };

                var channels = db.GetCollection <PushChannel>();
                channels.Insert(channel);

                return(new OkResult());
            }
        }
        public async Task <ActionResult> SendNotification(PushChannel channel)
        {
            WebPushClient    client       = new WebPushClient();
            VapidDetails     vapiDetails  = new VapidDetails("https://aka.ms/appconsultblog", publicKey, privateKey);
            PushSubscription subscription = new PushSubscription(channel.ChannelUri, channel.P256Dh, channel.Auth);

            Notification message = new Notification
            {
                Title   = "Test notification",
                Message = "Hey, you have a notification!"
            };

            string json = JsonConvert.SerializeObject(message);

            await client.SendNotificationAsync(subscription, json, vapiDetails);

            return(new OkResult());
        }
示例#6
0
        /*
         * private async System.Threading.Tasks.Task Authenticate()
         * {
         *  MobileServiceUser user = await authenticationService.LoginEasyAsync();
         *  CurrentUser = new User();
         *  CurrentUser.UserId = user.UserId;
         *  CurrentUser.Name = "Dummy";
         * }
         */

        async void FriendsViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == CurrentUserPropertyName)
            {
                // We haven't seen this user before
                if (CurrentUser.Id == 0)
                {
                    CurrentUser.MpnsChannel = PushChannel.ToString();
                    await chatService.CreateUserAsync(CurrentUser);
                }
                ReadFriends();
            }
            else if (e.PropertyName == PushChannelPropertyName)
            {
                RaisePropertyChanged(ContactsPropertyName);
                notificationService.RegisterNotificationHubs(PushChannel.ToString());
            }
        }
示例#7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="appKeys"></param>
 /// <param name="accessKeyId"></param>
 /// <param name="accessKeySecret"></param>
 /// <param name="channel">推送通道,</param>
 /// <param name="platform">默认iOS+Android</param>
 public PushModel(List <long> appKeys, string accessKeyId, string accessKeySecret, PushChannel channel = PushChannel.AliyunPush, int platform = 3)
 {
     this.AppKeys           = appKeys;
     this.AccessKeyId       = accessKeyId;
     this.AccessKeySecret   = accessKeySecret;
     this.APNSIsProduction  = Push.Config.APNSIsProduction;
     this.Channel           = channel;
     this.Platform          = platform;
     this.LoggerName        = Common.DefaultLoggerName;
     this.LoggerSource      = Common.DefaultLoggerSource;
     this.Audience.Category = PushAudienceCategory.Alias;
     this.NotificationWay   = NotificationWay.APNs;
     this.LowerExtraKey     = true;
 }
示例#8
0
        void bw_DoWork1(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                try
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "审批订单-查询数据库"
                    });
                    MessageDAO        mdao       = new MessageDAO(new BasicUserInfo());
                    OrdersCheckingDAO dao        = new OrdersCheckingDAO(new BasicUserInfo());
                    ClientUserDAO     userDao    = new ClientUserDAO(new BasicUserInfo());
                    MessageChannelDAO channelDao = new MessageChannelDAO(new BasicUserInfo());
                    var entitys = dao.GetValidOrdersChecking();
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "审批订单-找到" + entitys.Count() + "条数据"
                    });
                    foreach (var item in entitys)
                    {
                        Dictionary <ClientUserEntity, string> messages;
                        var userEntitys = userDao.GetValidUserByStatus0(item, out messages);
                        foreach (var it in userEntitys)
                        {
                            if (!string.IsNullOrEmpty(it.PushChannel))
                            {
                                PushChannel   info     = it.PushChannel.DeserializeJSONTo <PushChannel>();
                                var           pRequest = PushMsgRequestBuilder.CreateUnicastNotificationRequest(info.BaiduUserID, info.BaiduChannelID, "订单审批通知", messages[it]);
                                MessageEntity mEntity  = new MessageEntity();
                                mEntity.MessageID = Guid.NewGuid();
                                mEntity.ChannelID = 1;
                                mEntity.ClientID  = it.ClientID.Value.ToString();
                                mEntity.UserID    = it.ClientUserID.Value.ToString();
                                var request     = pRequest;
                                var messagetype = request.InnerDictionary["message_type"].ToString();
                                //判断消息类型0-消息,1-通知
                                switch (messagetype)
                                {
                                case "0":
                                    mEntity.MessageContent = request.InnerDictionary["messages"].ToString();
                                    break;

                                case "1":
                                    mEntity.MessageContent = request.InnerDictionary["messages"].ToJSON().DeserializeJSONTo <BaiduPushNotification>().Description;
                                    break;
                                }
                                mEntity.MessageParameters = pRequest.InnerDictionary.ToJSON();
                                mEntity.SendCount         = 0;
                                mEntity.Status            = 0;
                                mdao.Create(mEntity);
                                Loggers.Debug(new DebugLogInfo()
                                {
                                    Message = "【保存数据库成功】:" + mEntity.MessageParameters
                                });
                                item.SendStatus = 1;
                                dao.Update(item);
                            }
                            else
                            {
                                Loggers.Debug(new DebugLogInfo()
                                {
                                    Message = string.Format("用户{0}-{1}的PushChanel为空", it.ClientUserID, it.Username)
                                });
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Loggers.Exception(new ExceptionLogInfo(ex));
                }
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("审批订单-轮循结束,等待{0}秒", Interval)
                });
                Thread.Sleep(TimeSpan.FromSeconds(Interval));
            }
        }
 private void GivenAnEmptyChannel()
 {
     this.theEmptyChannel = this.AChannel(0);
 }
 private void GivenABusyChannel()
 {
     this.theBusyChannel = this.AChannel(2);
 }