- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试让 PushSharp(2.0.4.0?)作为 Windows 服务运行。每次服务运行并执行push.QueueNotification() 时,小程序都会挂起对stopAPNS(push) 的调用。当我运行类似的代码作为控制台应用程序时,它每次都运行良好(即我正在收到推送通知)。控制台应用程序基于 PushSharp.Sample 项目。
有趣的是,如果我启动/停止我的小程序而不执行任何push.QueueNotification()调用,我的服务将正确退出。在其他情况下,OnStop() 中对 stopAPNS(push) 的调用不会挂起。我想这是有道理的......队列是空的
我在.NET 4.0和4.5下编译了PushSharp项目。在每种情况下,我都会得到相同的行为。
我在下面提供了代码的清理版本。
对于为什么当作为 Windows 服务运行时,push.StopAllServices(true) 调用会挂起有什么想法吗?
谢谢。
public class PushNoteService : System.ServiceProcess.ServiceBase
{
// Initialize global instance of PushBroker service
private PushBroker push = new PushBroker();
#region Constructor
public PushNoteService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
#endregion
#region Component Designer generated code
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new PushNoteService(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new PushNoteService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
#endregion
#region OnStart
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
YYLog.Log.Instance.Info("Starting service.");
timer2.Enabled = true;
YYLog.Log.Instance.Info("Starting APNS.");
startAPNS(push);
}
#endregion
#region OnStop
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
YYLog.Log.Instance.Info("Stopping service.");
// Add code here to perform any tear-down necessary to stop your service.
timer2.Enabled = false;
YYLog.Log.Instance.Info("Stopping APNS.");
stopAPNS(push);
// some clean up.
push = null;
YYLog.Log.Instance.Info("Service stopped.");
}
#endregion
#region Acess Methods
/// <summary>
/// On Timer_Elasped events, websites are accessed to check status.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">E.</param>
private void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
int count = checkForPushRequest();
YYLog.Log.Instance.Info(" Count: " + count.ToString());
if (count > 0)
{
stopAPNS(push);
}
}
private int checkForPushRequest()
{
YYLog.Log.Instance.Info("Processing push notifications...");
int count = 0;
// Get the ConnectionStrings collection.
ConnectionStringSettings connections = ConfigurationManager.ConnectionStrings["MyDB"];
using (SqlConnection conn = new SqlConnection(connections.ConnectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand("MySP", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
while (dr.Read())
{
// increment counter
count++;
int badgeNumber = 0;
string deviceToken = Convert.ToString(dr[dr.GetOrdinal("DeviceToken")]);
string alertMessage = Convert.ToString(dr[dr.GetOrdinal("AlertMessage")]);
if (!dr.IsDBNull(dr.GetOrdinal("BadgeNumber")))
{
badgeNumber = Convert.ToInt16(dr[dr.GetOrdinal("BadgeNumber")]);
}
string soundFile = Convert.ToString(dr[dr.GetOrdinal("SoundFile")]);
// Send out the notification to APNS
YYLog.Log.Instance.Trace(" Sending notification to " + deviceToken);
sendPush(deviceToken, alertMessage, badgeNumber, soundFile);
}
dr.Close();
}
return count;
}
private void sendPush(string DeviceToken, string AlertMessage, int BadgeNumber, string SoundFile)
{
push.QueueNotification(new AppleNotification()
.ForDeviceToken(DeviceToken)
.WithAlert(AlertMessage)
.WithBadge(BadgeNumber)
.WithSound(SoundFile));
}
private void startAPNS(PushBroker push)
{
//Wire up the events for all the services that the broker registers
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;
string appleCertFileName = System.Configuration.ConfigurationManager.AppSettings["APNS_Certificate"];
var appleCert = File.ReadAllBytes(appleCertFileName);
string appleCertPassword = System.Configuration.ConfigurationManager.AppSettings["APNS_Certificate_Password"];
bool productionMode = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["APNS_Production_Mode"]);
push.RegisterAppleService(new ApplePushChannelSettings(productionMode, appleCert, appleCertPassword)); //Extension method
}
private void stopAPNS(PushBroker push)
{
YYLog.Log.Instance.Info("Waiting for Queue to Finish...");
//Stop and wait for the queues to drains
push.StopAllServices(true);
YYLog.Log.Instance.Info("Queue Finished");
}
#region Events
private void DeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
{
//Currently this event will only ever happen for Android GCM
YYLog.Log.Instance.Info("Device Registration Changed: Old-> " + oldSubscriptionId + " New-> " + newSubscriptionId + " -> " + notification);
}
private void NotificationSent(object sender, INotification notification)
{
YYLog.Log.Instance.Info("Sent: " + sender + " -> " + notification);
}
private void NotificationFailed(object sender, INotification notification, Exception notificationFailureException)
{
YYLog.Log.Instance.Error("Failure: " + sender + " -> " + notificationFailureException.Message + " -> " + notification);
}
private void ChannelException(object sender, IPushChannel channel, Exception exception)
{
YYLog.Log.Instance.Error("Channel Exception: " + sender + " -> " + exception);
}
private void ServiceException(object sender, Exception exception)
{
YYLog.Log.Instance.Error("Channel Exception: " + sender + " -> " + exception);
}
private void DeviceSubscriptionExpired(object sender, string expiredDeviceSubscriptionId, DateTime timestamp, INotification notification)
{
YYLog.Log.Instance.Info("Device Subscription Expired: " + sender + " -> " + expiredDeviceSubscriptionId);
}
private void ChannelDestroyed(object sender)
{
YYLog.Log.Instance.Info("Channel Destroyed for: " + sender);
}
private void ChannelCreated(object sender, IPushChannel pushChannel)
{
YYLog.Log.Instance.Info("Channel Created for: " + sender);
}
#endregion
#endregion
}
最佳答案
我们有一个 Web 应用程序,但我认为解决方案可以是相同的。我们花了一整天的时间来猜测这个问题!最后是Newtonsoft.Json版本错误我们的解决方案中的一些项目依赖于该库的旧版本,因此我们运气不好,在 Web 项目的/bin 文件夹中获得了错误的版本。
关于push-notification - PushSharp 的 StopAllServices() 作为 Windows 服务挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16713546/
我的团队正在使用 gerrit 代码审查,本质上这意味着默认的推送行为会绕过标准工作流程,因此我们需要使用 git push origin HEAD:refs/for/feature 来正确推送我们的
我是 assembly 新手,我正在使用 MASM。我看到这些代码行,想知道这之间有什么区别 a) push myVar b) push [myVar] c) push OFFSET myVar 我怎
美好的一天! 将镜像推送到docker hub时遇到一些问题。我的第一个软件版本: vagrant@debian-8-docker:~$ docker version Client version:
我有三个 Controller 一二三 .首先是navigationController的rootViewController。 在 SecondViewController ,我有一个名为 的协议(
我在这个 Google 教程的帮助下实现了一个 Web Push API: https://developers.google.com/web/fundamentals/getting-started
我有两个模式: var optionsSchema = new Schema({ locationname: String, locationnumber : String
我是 git 的新手并对其进行了测试。我已经能够克隆 friend 存储库进行小的本地更改并提交。 我现在想测试将我的本地更改推送到远程存储库,但不幸的是当我尝试进行推送时 $ git push <
我们正在公司讨论 git rebase 之后该做什么。在rebase之后,您需要将更改推送到远程origin,但是当git不允许时我们应该怎么做呢?实际上,我们正在讨论当分支已经被推送时我们最常用的两
我正在使用具有嵌入式 github 支持的新 IDE。在命令行本地,我可以成功地使用 git push orgin master 并更新 github。但是我的 IDE 使用带有 -v 标志的命令,这
我仍在阅读有关 RoR 的一些指南,我被困在 Deploying The Demo App 上 我遵循了说明: With the completion of the Microposts resour
我正在尝试创建一个可以将我的 git 存储库镜像到另一个存储库的脚本。一切正常,但它一直在说 [remote rejected] refs/pull/xx/head -> refs/pull/xx/h
我想了解使用 Tortoise SVN 构建过程的一些过程。主要是 我想知道你是否插入: 主线中继 QA 后的一个分支将其抓取到本地的工作副本中并测试该分支,然后一些构建推送该分支 我遇到的问题是我在
在谈论将消息推送到移动应用程序以触发 WAP 内容的下载时,似乎都使用了 WAP 推送和 SMS 推送这两个术语。 这些术语是指相同的机制还是具有不同的含义? 最佳答案 SMS Push 是告诉终端发
我只是想知道是否有人使用这种技术: 由于推送通知仅随 OS 3.0 一起提供,因此我一直在考虑使用电子邮件推送(Exchange、mobile.me)作为解决方法: 您可以注册一个 URL,例如。 m
我正在 build WP website using DIVI theme .应该被插入 dataLayer 的标签被默认的“未设置”值卡在某个地方。 为了推送我使用脚本的值: functi
我最近删除了xcode 6 beta 3并安装了xcode 6 beta 6 当我在终端输入gitpush时,这发生了 xcrun:错误: Activity 的开发人员路径(“/Application
我即将实现ionic-native Push Notifications .这可以在浏览器中运行吗?还是我需要安装 iOS/Android 模拟器? 最佳答案 除非您使用 Phonegap 推送服务器
Safari 12.1 是否支持服务 worker PWA 推送通知?我试过这个 demo在 iOS 上,但它仍然不适合我。 有机会得到它们吗?谢谢。 最佳答案 目前没有关于此功能的通信...Appl
目前我有很多 chrome 浏览器的推送订阅都是这样的方法, swr.pushManager.subscribe({userVisibleOnly: true}) .then(function
我需要 4 个过渡效果,但我只知道 2 个过渡效果,还有 2 个我不知道。我知道的 2 个过渡动画是: 过渡时下推: 并向下推过渡: 但
我是一名优秀的程序员,十分优秀!