コード例 #1
0
        public ApplePushService(IPushChannelFactory pushChannelFactory, ApplePushChannelSettings channelSettings, IPushServiceSettings serviceSettings)
            : base(pushChannelFactory ?? new ApplePushChannelFactory(), channelSettings, serviceSettings)
        {
            var appleChannelSettings = channelSettings;

            cancelTokenSource = new CancellationTokenSource();

            //allow control over feedback call interval, if set to zero, don't make feedback calls automatically
            if (appleChannelSettings.FeedbackIntervalMinutes > 0)
            {
                feedbackService = new FeedbackService();
                feedbackService.OnFeedbackReceived  += feedbackService_OnFeedbackReceived;
                feedbackService.OnFeedbackException += (Exception ex) => this.RaiseServiceException(ex);

                if (timerFeedback == null)
                {
                    timerFeedback = new Timer(new TimerCallback((state) =>
                    {
                        try { feedbackService.Run(channelSettings as ApplePushChannelSettings, this.cancelTokenSource.Token); }
                        catch (Exception ex) { base.RaiseServiceException(ex); }

                        //Timer will run first after 10 seconds, then every 10 minutes to get feedback!
                    }), null, TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(appleChannelSettings.FeedbackIntervalMinutes));
                }
            }

            //Apple has documented that they only want us to use 20 connections to them
            base.ServiceSettings.MaxAutoScaleChannels = 20;
        }
コード例 #2
0
ファイル: ApplePushService.cs プロジェクト: greg84/PushSharp
		public ApplePushService(IPushChannelFactory pushChannelFactory, ApplePushChannelSettings channelSettings, IPushServiceSettings serviceSettings)
			: base(pushChannelFactory ?? new ApplePushChannelFactory(), channelSettings, serviceSettings)
		{
			var appleChannelSettings = channelSettings;
			cancelTokenSource = new CancellationTokenSource();

			//allow control over feedback call interval, if set to zero, don't make feedback calls automatically
			if (appleChannelSettings.FeedbackIntervalMinutes > 0)
			{
				feedbackService = new FeedbackService();
				feedbackService.OnFeedbackReceived += feedbackService_OnFeedbackReceived;
				feedbackService.OnFeedbackException += (Exception ex) => this.RaiseServiceException (ex);

				if (timerFeedback == null)
				{
					timerFeedback = new Timer(new TimerCallback((state) =>
					{
						try { feedbackService.Run(channelSettings as ApplePushChannelSettings, this.cancelTokenSource.Token); }
						catch (Exception ex) { base.RaiseServiceException(ex); }

						//Timer will run first after 10 seconds, then every 10 minutes to get feedback!
					}), null, TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(appleChannelSettings.FeedbackIntervalMinutes));
				}
			}

			//Apple has documented that they only want us to use 20 connections to them
			base.ServiceSettings.MaxAutoScaleChannels = 20;
		}
コード例 #3
0
        public ApplePushService(IPushChannelFactory pushChannelFactory, ApplePushChannelSettings channelSettings, IPushServiceSettings serviceSettings)
            : base(pushChannelFactory ?? (IPushChannelFactory) new ApplePushChannelFactory(), (IPushChannelSettings)channelSettings, serviceSettings)
        {
            ApplePushService         applePushService    = this;
            ApplePushChannelSettings pushChannelSettings = channelSettings;

            this.cancelTokenSource = new CancellationTokenSource();
            if (pushChannelSettings.FeedbackIntervalMinutes > 0)
            {
                this.feedbackService = new FeedbackService();
                this.feedbackService.OnFeedbackReceived  += new FeedbackService.FeedbackReceivedDelegate(this.feedbackService_OnFeedbackReceived);
                this.feedbackService.OnFeedbackException += (FeedbackService.FeedbackExceptionDelegate)(ex => applePushService.RaiseServiceException(ex));
                if (this.timerFeedback == null)
                {
                    this.timerFeedback = new Timer((TimerCallback)(state =>
                    {
                        try
                        {
                            applePushService.feedbackService.Run(channelSettings, applePushService.cancelTokenSource.Token);
                        }
                        catch (Exception ex)
                        {
                            applePushService.RaiseServiceException(ex);
                        }
                    }), (object)null, TimeSpan.FromSeconds(10.0), TimeSpan.FromMinutes((double)pushChannelSettings.FeedbackIntervalMinutes));
                }
            }
            this.ServiceSettings.MaxAutoScaleChannels = 20;
        }
コード例 #4
0
        public ApplePushService(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
            : base(new ApplePushChannelFactory(channelSettings), serviceSettings)
        {
            var appleChannelSettings = channelSettings;
            cancelTokenSource = new CancellationTokenSource();
            feedbackService = new FeedbackService();
            feedbackService.OnFeedbackReceived +=
                this.feedbackService_OnFeedbackReceived;

            // allow control over feedback call interval, if set to zero, don't make feedback calls automatically
            if (appleChannelSettings.FeedbackIntervalMinutes > 0)
            {
                timerFeedback = new Timer(
                    state =>
                        {
                            try
                            {
                                this.feedbackService.Run(
                                    channelSettings, this.cancelTokenSource.Token);
                            }
                            catch (Exception ex)
                            {
                                this.Events.RaiseChannelException(ex, PlatformType.Apple);
                            }

                            // Timer will run first after 10 seconds, then every 10 minutes to get feedback!
                        },
                    null,
                    TimeSpan.FromSeconds(10),
                    TimeSpan.FromMinutes(appleChannelSettings.FeedbackIntervalMinutes));

            }
        }
コード例 #5
0
        public ApplePushService(PushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
            : base(channelSettings, serviceSettings)
        {
            cancelTokenSource = new CancellationTokenSource();
            feedbackService = new FeedbackService();
            feedbackService.OnFeedbackReceived += new FeedbackService.FeedbackReceivedDelegate(feedbackService_OnFeedbackReceived);
            timerFeedback = new Timer(new TimerCallback((state) =>
            {
                feedbackService.Run(channelSettings as ApplePushChannelSettings, this.cancelTokenSource.Token);

                //Timer will run first after 10 seconds, then every 10 minutes to get feedback!
            }),null, TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(10));
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: lbosman/PushSharp
        private static void ReceiveFeedback()
        {
            FeedbackService fs = new FeedbackService();
            fs.OnFeedbackReceived += Fs_OnFeedbackReceived;

            //			var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../Resources/PushSharp.Apns.Sandbox.p12"));
            //			ApplePushChannelSettings appleSettings = new ApplePushChannelSettings (false, appleCert, "Lize4Rune");

            var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../Resources/OLBPhoneSandboxCertificate.p12"));
            ApplePushChannelSettings appleSettings = new ApplePushChannelSettings(false, appleCert, "0lbSandb0x");

            fs.Run(appleSettings);
        }
コード例 #7
0
ファイル: ApnsRealTest.cs プロジェクト: Donnie888/LxServer
 public void APNS_Feedback_Service ()
 {
     var config = new ApnsConfiguration (
         ApnsConfiguration.ApnsServerEnvironment.Sandbox, 
         Settings.Instance.ApnsCertificateFile, 
         Settings.Instance.ApnsCertificatePassword);
     
     var fbs = new FeedbackService (config);
     fbs.FeedbackReceived += (string deviceToken, DateTime timestamp) => {
         // Remove the deviceToken from your database
         // timestamp is the time the token was reported as expired
     };
     fbs.Check ();
 }
コード例 #8
0
        public ApplePushService(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings)
            : base(channelSettings, serviceSettings)
        {
            var appleChannelSettings = channelSettings as ApplePushChannelSettings;

            //cancelTokenSource = new CancellationTokenSource();
            feedbackService = new FeedbackService();
            feedbackService.OnFeedbackReceived += new FeedbackService.FeedbackReceivedDelegate(feedbackService_OnFeedbackReceived);

            //allow control over feedback call interval, if set to zero, don't make feedback calls automatically
            if (appleChannelSettings.FeedbackIntervalMinutes > 0)
            {
                timerFeedback = new Timer(new TimerCallback((state) =>
                {
                    try { feedbackService.Run(channelSettings as ApplePushChannelSettings /*, this.cancelTokenSource.Token*/); }
                    catch (Exception ex) { this.Events.RaiseChannelException(ex); }

                    //Timer will run first after 10 seconds, then every 10 minutes to get feedback!
                }), null, TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(appleChannelSettings.FeedbackIntervalMinutes));
            }
        }
コード例 #9
0
        private void InitApnsBroker(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
        {
            if(string.IsNullOrWhiteSpace(globalSettings.Push.ApnsCertificatePassword)
                || string.IsNullOrWhiteSpace(globalSettings.Push.ApnsCertificateThumbprint))
            {
                return;
            }

            var apnsCertificate = GetCertificate(globalSettings.Push.ApnsCertificateThumbprint);
            if(apnsCertificate == null)
            {
                return;
            }

            var apnsConfig = new ApnsConfiguration(hostingEnvironment.IsProduction() ?
                ApnsConfiguration.ApnsServerEnvironment.Production : ApnsConfiguration.ApnsServerEnvironment.Sandbox,
                apnsCertificate.RawData, globalSettings.Push.ApnsCertificatePassword);

            _apnsBroker = new ApnsServiceBroker(apnsConfig);
            _apnsBroker.OnNotificationFailed += ApnsBroker_OnNotificationFailed;
            _apnsBroker.OnNotificationSucceeded += (notification) =>
            {
                Debug.WriteLine("Apple Notification Sent!");
            };
            _apnsBroker.Start();

            var feedbackService = new FeedbackService(apnsConfig);
            feedbackService.FeedbackReceived += FeedbackService_FeedbackReceived;
            feedbackService.Check();
        }
コード例 #10
0
 private void CheckAndRemoveExpiredToken()
 {
     try
     {
         var fbs = new FeedbackService(config);
         fbs.FeedbackReceived += (string deviceToken, DateTime timestamp) =>
         {
             notificationService.Unsubscribe(deviceToken, userId);
         };
         fbs.Check();
     }
     catch (Exception e)
     {
         logger.ErrorFormat("Unable to usubscibed token" + e.Message);
     }
 }