Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hey. I'm trying to send out web notifications whenever a new article is published for the frist time.
I've got it for the most part. The notifications are sending, but there's a few things im missing that i can't work out.
public class UmbracoEventInterceptor : ApplicationEventHandler { // Constructor method public UmbracoEventInterceptor() { //ContentService.Published += sendPushNotifications; ContentService.Publishing += sendPushNotifications; } private void sendPushNotifications(IPublishingStrategy sender, PublishEventArgs<IContent> args) { string sql = null; using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ConnectionString)) { sql = "SELECT [Endpoint],[Key],[AuthSecret] FROM [dbo].[PushNotificationSubscriptions]"; using (SqlCommand cmd = new SqlCommand(sql, cnn)) { cnn.Open(); DataSet dSet = new DataSet(); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); try { da.Fill(dSet); dt = dSet.Tables[0]; //loop through each endpoint foreach (DataRow a in dt.Rows) { //loop through each published article foreach (var entity in args.PublishedEntities) { //only send notification if not already published and is an article if (!entity.HasIdentity && !entity.HasPublishedVersion && entity.ContentType.Alias == "newsItem") { PushSubscription subscription = new PushSubscription(a["Endpoint"].ToString(), a["Key"].ToString().Replace(" ", "+"), a["AuthSecret"].ToString().Replace(" ", "+")); string payload = "{\"Title\": \"New Article!\", \"Description\": \"" + entity.Name + "\", \"Url\": \"https://www.WEBSITENAME.com\"}"; NotificationsController.createNotification(subscription, payload); } } } } catch (SqlException) { throw; } if (cnn.State == ConnectionState.Open) cnn.Close(); } } } }
Basically it just loops through a table in the database and sends out notifications to each endpoint.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
content service event intercepting
Hey. I'm trying to send out web notifications whenever a new article is published for the frist time.
I've got it for the most part. The notifications are sending, but there's a few things im missing that i can't work out.
Basically it just loops through a table in the database and sends out notifications to each endpoint.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.