I'm working on a C# MVC 4 application and I want to make a notification system much like facebook.
I thought about adding a notification in a table for each event, and then make AJAX calls to the database each 1 minute to retrieve notifications for the current user.
But I'm afraid it's too heavy.
Your best bet would be to go with SignalR. Its designed for the purpose of real time notification
introduction-to-signalr
Related
I'm writing an Xamarin iOS app, which will display a mobile graphical dashboard.
I'm planning on handling data delivery and synchronization (as well as offline scenario) by using Azure Mobile Services to sync my local Sqlite data on a regular intervals (let's say every 10 minutes). Is there a way to react to the sync finishing by refreshing the UI?
I think the key here is to implement IMobileServicesSyncHandler. This lets you override these events and respond to them, to refresh the UI, etc. This is the same place you can handle conflict resolution, etc.
I think this guy shows some good examples.
I have a functionality where I need to remind the customers about their appointments before the time interval set while creating the appointment.
Example:
A customer is logged into the system today at 4:00PM.
If a customer has an appointment set today at 5:00PM , and the reminder minutes as 10.
This invokes a popup with beepsound that has to appear today at 4:50PM(i.e 10 minutes before the actual appointment start time).
I have all appointments with start time, end time , (along with the dates) stored in backend table for number of customers.
Please guide me to achive the following in realtime :
(1) to invoke this popup at 4.50PM
(2) play the soundfile stored in the database
From my search,there is a way to do this using signalr concept in mvc. I went through the sample for chat application in this lnk.
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
This invokes the hub when a event occurs. but in my application it has to work as a reminder to show the popup if the start time matched the current time. how to get this in real time. Any idea can help me.
This could be a good situation to use WebSockets. (Take a look at Socket.IO, and it's .NET version SocketIO4Net)
The idea would be to have a business logic server side to manage what customer has an appointment to be reminded. Then it uses the WebSocket to send the reminder signal. If the customer is logged in, the js client side would catch the signal and you decide how you want to show it.
To play the sound stored in the database, you could do an action server side that returns the sound file or something, and then use an HTML 5 tag to play the sound.
Hope this helps.
Everything can be done but as ChristianDev says SignalR does not work like this out of the box... I think you can do this with SignalR anyway but you have a few challenges...
You have to maintain state on the server for the clients appointment
This state have to be persistent between connection, when a client navigates between pages
When an event fires you have to send the message to the correct client
If that client is between pages (offline) at the moment that message have to be stored until the client gets back online and then be sent to him/her.
EDIT: It seemed like a fun thing to write so a wrote a simple notification application. You can probably port it to SignalR pretty easy. Realtime Notification Sample
You could change the approach, and use a windows service, emailing/sms'ing the user to remind them of the appointment, this means that the user doesn't need to be logged into the web application to receive a reminder.
If you wanted to use technology such as SignalR, you would need to keep a record of connected users (and their username) and then when an appointment is due, you would need to trigger an event to send to the user in question, based on the unique connectionId.
SignalR, out of the box, doesn't work like this - but, take a look at my question here for some help : Update UI with SignalR and Knockout when manually updating DB
Edit: To add to this, if you're looking for a very nice notification plugin, then take a look at John Papa's ToastR, it's a small JS/Css plugin which notifies via a 'timed, outlook style notification'.
I have a web service that takes user location periodically.
I want to create a desktop application that takes those values and shows the real time position of user on a map automatically.
What is the best method I can follow to get real time updates?
Can I use Ajax? Does it support auto refresh?
Is there a better method which supports auto refresh and also display real time data?
Thank you..!
Check out the SignalR library. There is a server-part and a clients part (Javascript, rich client) etc.).
You could trigger the update in the client if the WebService was called. So the client is notified and could update his data accordingly.
How many clients are connected? Maybe some other message bus like library would be more appropriate?
I have a question that is perhaps slightly towards architecture and design rather than syntax problem....
I have a c# winforms app on my desktop which I have built which is similar to a CRM. I make updates to customers records as they submit orders/invoices etc and what I would like to do is to build (or buy) a module that will update a remote database that sits behind a website onto hich registered clients log in. I want the clients to be able to see the status of their invoice/purchase etc as I have updated it on the winforms app.
I can think of a couple of options of the top of my head but would like to know more if you have done something similar
Things I am considering are;
>Replication - I think this is overkill as the updates are not
huge, are one way only, and not
critical they are in real time, and
also I am running SQL express on the
winforms app. This can be changed
but rather not
>create a text/xml file that gets created and uploaded to the web
server to a location that is
monitored every 5 minutes and then
updates the web database. - I am not
hosting the website myself so I do
not have complete control over what
I can install but I suspect I can
install a .NET 'filewatcher'
Anyway, I would appreciate your thought on my 'problem'
thanks
I think your best bet is to create a web service of some kind (I like using ServiceStack.net to create simple REST ones, much cleaner imo than WCF). This will sit on the server and be responsible for the server-side sync piece.
On the client, you could either have the winforms app fire off the call to the web service based on some threshold of activity, or you could have a windows service that you install with the winforms app which does it in a scheduled job or on a timer.
You'll want to be sure that you're doing all your calls over SSL of course, and make sure you're authenticating the clients, but that's the basic architectural approach I'd take.
I'm using c# to communicate with twitter and i need to code a schedule system to send twitter messages at a user defined date.
The messages to be sent are in a database with the date and time of deliver.
Which is the best method to check the db for scheduled messages and send it when the time arrives?
How accurate do you need the timing to be? Could you get away with polling the database every 5 minutes, saying "Tell me all the messages which need to be delivered before current time + 5 minutes" and then sending them all? (And marking them as sent in the database, of course.) Does it matter if they're a bit early or late?
You can do the scheduling on the C# side to make it more accurate, but unless you really need to I'd stick with a very simple solution.
(Depending on your database there may be clever ways of getting callbacks triggered etc... but again, I'd stick with the simplest solution which works.)
In addition to the windows service option (or background thread), you could just set up a scheduled task to run an app that polls the DB and sends the tweets once every defined interval.
Windows schedules can be setup using C# if needed and are really easy to set up manually.
There are several ways to do this, but I guess the best way is to set up a Windows Service that will periodically poll (frequency is up to you) the DB for any scheduled tweets that hasn't been sent.
Needless to say you'll need to handle scenarios such as the Internet connection or DB being down, etc.
In fact the solution consists in using a windows service but it can't communicate directly with the ASP.NET MVC app. I've added a Web Service that handles the task and a System.Threading.Timer in Windows Service to periodically call the Web Service.