I am using HTML Agility pack in Xamarin forms to scrape data from a website. When a condition returns true, I want to send a push notification to all users. However, this data is changing a lot and I think it would cost a lot of internet data and maybe battery, if the device with this app is constantly collecting the data in the background to check a certain condition.
This is a piece of the code to give you an idea:
var url = "https://www.goal.com/en-us/live-scores";
var httpClient = new HttpClient();
var html = await httpClient.GetStringAsync(url);
var htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(html);
var voetbalWedstrijdenHTML = htmlDocument.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("class", "")
.Equals("main-content")).ToList();
So I thought it might be a good idea to let only one device use this code and check if the condition is true and then only send the push notification to all users. I've made this image to give you a better idea about what I mean.
I thought it might be a good idea to use firebase messaging to send push notifications to all users, but how or what do I use to have only one device checking the C#? Should I use a website with the C# code that is running 24/7 (is this possible?), or something else? So... how do I run C# code 24/7?
EDIT:
I found out about 'Firebase functions'. Would this work for me? I'd have to change to javascript so I rather stick to C#.
java file to add Notification code. Modify layout XML file res/layout/activity_main. xml add any GUI component if required. Run the application and choose a running android device and install the application on it and verify the results.
Now to send Notifications to multiple devices of a user, you just need to send a notification to the user's Device Token group which, in turn, sends the push notification to all the devices in the group.
For sending notification in One Signal click on your app name on the top left corner in One Signal Console and then click on your app name you will get to see the Dashboard screen. Click on the New Push option to send a new notification.
For Cisco Unified Communications Manager and IM and Presence Service deployments, Push Notifications are used by the following clients: Table 1. Compatible Clients that Use Push Notifications (On-Premises Deployments) * For messaging, Cisco Webex clients register to the Cisco Webex cloud rather than the IM and Presence Service.
By using a wizard in Visual Studio, you can generate push notifications from a mobile service that was created with Azure Mobile Services. The Visual Studio wizard generates code to help you get started.
The IM and Presence Service uses Push Notifications ‘message’ channel to send the IM notification to Jabber. When the user clicks the notification, the client moves to foreground mode, resumes the session with the IM and Presence Service, and downloads the message. While the client is in background mode, the Presence status is Away .
Here's how i would have done it
Create an Azure web job that checks the condition. You can schedule it to run according to your requirements.
Create an Azure notification hub (ANH) and link it to Firebase and equivalent in IOS and other platforms as per requirements.
Create a web api that every app user will call. In this api call, register every device with Azure notification hub. The registrations can include tags to which you can send notifications to.
When the web job needs to trigger a notification, it will call the ANH directly or through the web api and send a broadcast notification. You can also narrow down the users to send notifications based on tags.
One advantage of using ANH is that you don't need to worry about sending to multiple platforms. You just send to tags it will go corresponding users of all platforms.
I believe that this document may help you. https://learn.microsoft.com/en-in/azure/notification-hubs/. Hope I have helped.
EDIT:
Would you be using 2 projects: Yes you would be using atleast 2 projects. One for web api and 1 for each platform that you want your app to be in.
Point in Using Azure Notifications: It comes with great deal of features that will make your life easier especially if your application runs on multiple platforms. However, you can use FCM directly. Actually ANH will also use FCM behind the doors.
Putting the code you want to run every some time in Startup.cs
: Thats a bad idea. You should ideally be using a web job for that. Startup code is executed only once in lifetime of application. You don't want your notification trigger code to be in Startup class. However if using webjob is not something you want, you can be using the cron scheduler.
EDIT 2:
You can use the timer in Startup.cs
however, i would not recommend that. One class should ideally have only one purpose and business logic is not for Startup. You should consider moving out the method to another class.
If you decide to use webjobs, you would create different projects for web job. These offerings like ANH, web job etc exist for one reason - to make your life easier. You can always do everything on your own if you are ready to work extra mile. PS web job is becoming obsolete and people are now moving to Azure functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With