Azure mobile services scheduled job - Are there alternatives to using javascript? - c#

Background -
I am working on a Windows Phone RSS reader app (using C#). In addition to just reading RSS content, the app does some scraping on the articles linked by the feeds to get additional info. This is turning out to be too resource/bandwidth intensive to be done on the client and I am thinking of moving the RSS aggregation and scraping logic to the cloud.
I want to use Azure mobile services. In my simple design, I want to have-
(1) an Azure DB, which stores all the RSS data including the scraped content.
(2) Front end service which clients can call to get this data
(3) A scheduled task in the cloud that keeps the DB up to date with the latest RSS content. The processing here will be heavy weight since it will scrape thousands of webpages, process them to get additional information, and then update the DB.
* Actual question *
My question is regarding (3). I already have C# code that does this on the client and I want to be able to reuse it in developing the scheduled task in the service. I read the Azure mobile services documentation. What they seem to have is a scheduled job which runs javascript. I don't want to use java script and would prefer to reuse my C# code. What is a recommended (and non-hacky) way for me to do that?

You can use Windows Azure WebJobs:
http://www.windowsazure.com/en-us/documentation/articles/web-sites-create-web-jobs/
Just create a new (empty) website in Windows Azure, go to the "WEB JOBS" tab and add a new WebJob.
There you can upload your .NET console application which has all your logic (zipped), set a schedule according to your needs and you can use the web sites connection string setting (under the "CONFIGURE" tab) to set your connection string.

As of today, there isn't any option to run anything but javascript from your Mobile Service. HOWEVER, if you already have the C# code to perform #3, I would recommend wrapping that in a very light weight Web Service (Web API, etc). You can host this from Windows Azure Websites. You can then use the Windows Azure Scheduler to schedule a ping of that service which will kick off your job. You could use the Mobile Services scheduler to ping it as well but using the WA Scheduler would be even easier.

Related

How to structure an Email and SMS sending web app that runs in the background

I need to develop a web application in asp.net and C# that sends emails and SMS. I already have a console version of this app that i created a few years back but it relies on a windows scheduled task, and is outdated.
What is the proper or best way to do this using asp.net, considering that i'll have other applications that will feed a database with the information to send. How can i setup a background service that will monitor this database and send the messages even if there are no pages open?
Thanks.
We use Topshelf to run as a windows service and Quarts to schedule/manage the recurring job/function calls. Hangfire was another solution that looked interesting.
Hangfire
An easy way to perform background processing in .NET and .NET Core applications. No Windows Service or separate process required.
https://www.hangfire.io/

Windows service / ASP site / something other?

I need to write something for listen data for devices like gps and other device that can send every X seconds me data
And I will can to add device to my database from web site / (via wcf service)
Now I want after I added new device to database I want to start get from device data.
I dont want to do it in wcf service - so I want top write a little program only for get data.
What is better way for get data in background ?
Also I will need sent "push notification" from WCF to this program - for add new device to list
So what is better way ? windows service / console/wpf programm / asp.net ??
Sorry for English grammar
You can use either windows service or console application. I will suggest you to develop console application and configure it as schedule task. Schedule task is allow you to define task job to execute the console application.
Some advantages using console application over windows service:
Easy to debug/truobleshoot.
Easy to develop and configure.
No need to learn how to write Windows service.
Don't require extra permissions.

Best practices for cron job style tasks on the ASP.NET MVC / Azure platform?

Every day, I want to email all my users who have signed up, but not completed a specific task.
What is the best framework for approaching this problem on the .NET MVC / Windows Azure platform?
Coming from OS/Linux world I would write a program and schedule it to run daily via crontab.
At least for the scheduling part, you could look into Windows Azure Scheduler Service announced not too long ago. Using this service, you would be able to invoke a HTTP/HTTPS web endpoint of write a message to a queue on a scheduled interval.
For sending emails, you would still need to write a program. You could host this program as a cloud service running as a worker role or you could write that logic in a web application and host it as a Windows Azure Website.
Azure just added the ability to schedule jobs. Currently in "Preview"
You can find more information about the scheduler jobs in here.
http://gauravmantri.com/2013/11/10/windows-azure-scheduler-service-part-i-introduction/
http://gauravmantri.com/2013/11/10/windows-azure-scheduler-service-part-ii-managing-cloud-services/
You could leverage the scheduled task component of Azure Mobile Services to achieve this outcome and write the code to achieve it using node.js (see: http://www.windowsazure.com/en-us/develop/mobile/tutorials/schedule-backend-tasks/) It's possible to add other npm packages so you are limited to what's already deployed to Azure so you could hopefully find a library to do the mail sending for you. The only thing you'd need to think about is reliable mail delivery which on Azure typically means using SendGrid to avoid spam blackists.

Windows 8 And Windows Phone Push Notifications Using Azure

I've looked into Azure Mobile Services and found its great but does not give me the flexibility I want (Node.js also leaves a bad taste in my mouth coming from C#).
I was using periodic update notifications in Windows 8 and already have an ASP.NET Web API project supplying tile images and tile xml content. I was hoping to use an Azure Worker Role with Azure storage tables for Push Notifications for Windows 8 and Windows Phone.
I found this example but it seems to be for VS2012 Release Preview. I can't find an updated version or any other samples to work with. In particular I want my service to support both Windows 8 and Windows Phone.
http://watwindows8.codeplex.com/wikipage?title=Push%20Notification%20Worker%20Sample
If anyone can outline the references/nuget packages I need. It would be a great help.
EDIT:
Jim O'Neil's blog is a good starting point. I need to use a Azure Worker Role because I want to send my notifications periodically.
I also found the WnsRecipe NuGet package for sending push notifications from the server. Jim O'Neil solution is just as good.
Finally, to save a bit of time, I was hoping to avoid writing data acess code for registering apps channel ID's to a table on the server. The Azure Mobile Services MobileServiceClient class is a great solution to this as it lets you do all of this with a couple of lines of code. The table is available through REST services. However, questions remain:
Can I continue using the Mobile Services Table Storage MobileServiceClient with my app and Azure Worker Role or do I have to use Azure Table Storage?
If I can use MobileServiceClient, how do I access the table from my Azure Worker Role?
If I have to use Azure Table Storage which also provides a REST service for free, how can I access the table from my Windows 8 app?
Windows Azure Service Bus just released a new feature that allows to push Windows 8 (and iOS) notifications from C# back-ends (and soon from Mobile Services too), with no need top handle ChannelURIs at all.
Take a look at: http://channel9.msdn.com/Shows/Cloud+Cover/Episode-100-Introduction-to-the-Windows-Azure-Service-Bus-Notification-Hubs
Windows 8 code walkthrough: http://channel9.msdn.com/Blogs/Subscribe/Service-Bus-Notification-Hubs-Code-Walkthrough-Windows-8-Edition
If you try it, let me know what you think!
Strictly speaking, no NuGet packages are needed, they are just wrappers for functionality (it's all REST/OAuth under the covers) to make your life easier. As you observed, the Windows Azure Toolkit for Windows 8 and Windows Phone has been somewhat supplanted by Windows Azure Mobile Services.
If you want to do it all yourself, you can check out a three part blog series I did on using Azure Web Sites for Push Notifications. It's Web Sites, not Web Roles, but that part is fairly interchangeable; although, I'd say that Web Sites are going to be a far more economical option here unless you already have a service implemented that you are using.
I don't have Windows Phone incorporated into that series, and Windows Phone does use a slightly different notification mechanism from Windows 8, but that's on my to-do list, and hopefully what is there will get you going in the right direction.
When you use the MobileServiceClient to store data in Mobile Services, you are actually storing your data in a SQL Azure database. You have a number of options when it comes to accessing this data from your worker role.
Connect directly using a SQL client. This could be Entity Framework, a different ORM, or even raw ADO.NET. You can get the connection string for your database by selecting it in the Azure portal. On the dashboard tab there is an option to show connection strings.
Use a client library to access the data via Mobile Services. Unfortunately we do not have an official SDK that can be used from a worker role yet but the good news is that there is an unofficial package on NuGet
Access the data directly via the HTTP endpoint that Mobile Services provides by making HTTP requests. The API is documented here.

How to run a program in WCF?

I am new to WCF and i am designing a project in which i want to run a crawler program (coded in c#) which crawlers some websites and it stores the crawled data in the tables of database (sql server db). I want that crawler runs repeatedly after 30 minutes and updated the database.
I want to then use the service on my hosted platform so that i can use the data from tables in web form (i.e. .aspx page)
Is it okay to use WCF for this purpose ?
Please suggest me how to move on ?
Thanks
Windows Communication Foundation (WCF) is responsible for communication between 2 points with different channel technology. you will use WCF if you want to send/receive some data between two point regardless channel technology (TCP/UDP/NetPipe/MSMQ , ...)
But you first need to design you crawler application which is configured to fetch data from your target web sites, then you need to design a schedular application using
http://quartznet.sourceforge.net/
to run your crawlers.
after running and storing your web pages you can use WCF if you need to do replication or synchronization with center server but it is optional
You could use a WCF service to do this but I would go for another setup:
I'd build a Windows application that is scheduled to run every 30 minutes by the Windows Task Scheduler. A simple console application might be fine.
I'd use a Web application (possibly ASP MVC) to query the database.
As you can see there is no need to use WCF at all.
An exception can/must be made when the server is not yours but you are using a hosting provider who doesn't allow you to schedule a Windows task. In that case you might want to run the crawling process by hand through the web application and have it repeat itself after 30 minutes.
Some hosting providers do allow the scheduling of tasks but in a different way so it might be worth to investigate.

Categories