Persisting SignalR chat app to database - signalr

I have a simple SignalR chat application up and running.
However, I can't find anything about how you can persist the messages users send to a database, bizarrely - even though it would seem like an obvious requirement.
This is because we need a record of what people are saying, and want users who join to see the last few messages.
I have two SignalR books - neither cover this topic (Apress Pro ASP.net SignalR, and the Microsoft Press book SignalR programming).
Google searches return nothing about persisting messages to a database and I've found no samples that do this.
Am I missing something? How can I do this?
Thanks.

Related

SignalR just for checking if user is online or not

I would like to ask, if it is a good idea to use SinglR just for knowing if the current user now online or not?
For example I have an small website with log in system, and some where on the side i would like to show the logged in members.
Is this a good idea to use signalr for that?
And if it the case should I then on each page start the connection with hub? (In this case when user navigates on the pages, will be the ReConnected method called on hub, or OnDisconnected and OnConnected)?
I'm just starting with signalr, so curious what ppl think.
You could use SignalR though there might be better methods to do this. So when a user logs in, logs out or becomes inactive - you would have some sort of message being sent from the client to the server that indicates the change in status. You can store that information in a temporary database and whenever a value in the database changes you can use SignalR to relay that information to all the connected clients.
Signalr will get reconnected when the user moves from one page to another page. Whenever a user logs into a website the user security details will be persisted in a cookie assuming you are using Cookiebase authentication. So till the user logs out or session timesout the cookie will be active. So there is no real need for Signalr here.
I have been investigating the same thing. From my research, I would say that you COULD do this, but I'm on the fence of whether it's the best way to go about it. I would expect a LOT of disconnecting, connecting and reconnecting. If you're persisting this data in a database, you should anticipate a lot of database traffic. if you're only on a single server though, you could just persist this in memory.
Something to also note is that the ConnectionId changes with each page refresh. At first, I thought that was dumb because I wanted the connection id to be consistent so i could keep a handle on a user with it. However, if you open a link in a new tab and then close one of them, you have to still keep the other connection in storage. If the id was the same you would remove it on disconnect even though the other tab was open, so your user would incorrectly be marked as offline.
However, the other issue that i'm thinking about is that if you're just browsing around the site in a single tab, you will disconnect for a split second between each page load. So you might run into connection consistency issues with that.
I'd say online presence with signalr is more common to be used for a chat room or game lobby. So I'd say this is possible, but whether it's a good solution -- i'm unsure.

asp.net + private message system notification

I am trying to build a private message inbox system in my asp.net app, using SQL Server to store the messages between users but one thing I am not sure how to achieve is this, for e.g facebook immediately notifies a user when he/she recieves a new message or notification through the action of another user as a red icon on its top navigation bar. I have read through some of the tutorials and guides and most of them requires some sort of polling to the database every few seconds. Can anyone shed some light on what is a good way to go about this?
Thanks.
I have used SignalR to do something similar to this in the past. It can be installed via NuGet by Install-Package SignalR
Scott Hanselman has a great write up: http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx
Also, jabbr.net is a fully functional example of what, I think, is pretty close to what you want to do.

Implement User Activity Tracking

I am working on an ASP.NET website with sql server 2008 R2.
i need to implement a tracking system to track user activity as which pages the user browsed which item liked and so on
i have a lot of options and tried couple of them
i tried to send an insert with every page the user browses but it
turned out a huge load on the sql server and after two days i
removed it
I had a solution is to buffer the users history in xml and flush them every 500 records in the database. it is working fine but it would be bad when users number increase
I had found there is message queues like MSMQ and SQL Service Broker but i didnt go any further in this
In the end i would like to hear your suggestions and recommendations as well as your comments for the MSMQ and SQL Service broker and if i should go for them and to which one of both and why
You can try using a logging framework like log4net or nLog which gives you the flexibility to log to various targets and also use buffering / asynchronous logging to reduce the load.
I would use something like Google analytics. It's easy, you just put the boilerplate code into your pages, and google does the rest.

Integrating an issue, feature request and bug tracking system into an existing ASP.NET Web App

I have an existing asp.net application that is currently in production for more than 3 years now. That application was developped based on internal and user requirements. That application is also using Google Analytics to detect different usage metrics to understand more what users are doing and which part of the system is most requested. But... we understand now that we are not so well connected to client's need's and more importantly, we don't receive a lot of feedback from them and when we receive feedback, that feedback is sent to many different people so most of the time they are lost or missing some valuable informations. Here is my question: is there some free (or paid) products that can be incorporated into an existing asp.net application that can provide the following functionnalities:
For my users:
Send feedbacks
Log bugs
Submit feature request
Ask questions
Be able to follow an issue, bug or feature and subscribe to it
Be able to rate answers
Be able to include attachments
Be able to vote for issues to prioritize them
Etc.
For me:
Respond to all of these issues and be able, in some way, to see and analyze all of this data to properly populate our product backlog with what user needs
My real need will be to have something like Telerik has implemented. Is there something that can be incorporated into an existing application?
Thanks in advance
What about User Voice? It's a great system to collect user feedback. Not sure if you'd get the integration you're looking for. For the rest of your requirements it seems it would work really well.

Best architecture for an emergency alert system

I'm developing a software system which receives information (which is saved to a database) and when any information is received (new insert in a specific table) an alert should be seen in the screen in the information center, so proper action can be taken.
I'm writing an application with ASPNET MVC, SQL Server 2008 Express, SQL Agent free for that version of SQL Server, Entity Framework 4, Visual Studio 2010, etc.
Right now, I've set the database and a SQL job that monitors the table each minute, if there is a new records an email is sent to same addresses. My problem is...What then? Which would be the best architecture to follow?
A couple of option I thought about are:
1) In the job connect to a web service and that web service an the web service can open a popup
2) The web page could be pooling the database table to know if there are new records
Is there any way to make push to the web page instead of the page pooling the database server?
I know maybe windows application would fit better here, but right now I must stick with ASPNET MVC as I already started and don't want to create another application.
Thanks! Daniel
Is there any way to make push to the web page instead of the page pooling the database server?
HTML5 WebSockets. Draft, pretty new, specification is still subject to change, to all browsers implement it. You will need a WebSocket Server. If you go that route make sure you read this guy's blog. He is behind Laharsub which is a must try server.
I'm pretty sure you are able to use Silverlight to push data down to the client. Here is a pretty good overview that I read a while back. HTML5 might be a better way to go. But with such limited support it's almost not worth it at this point. Granted the Silverlight application might be out of reach to, but it's still a possibility.
I would suggest that you look into (complex) event processing, or stream processing -- at least to get the feeling for architecture of these systems.
The idea is to capture a stream of events before they reach database, route them (process) within the event processor and put them in the DB from there -- treating the DB as only one of event destinations (subscribers).
Take a look at Streambase, ruleCore, and many others.
These were all developed for the type of scenario you described.
Try to see the problem from the other angle. Develop a web client that reads the database every minute and compare to last pull ...

Resources