How to build a real-time streaming data silverlight application - silverlight

I'm curious to get some feedback and ideas on how one could go about building a realtime data streaming application. We can keep the source data generic for this exercise ... throughput info, stock trade pricing, etc. Just something that is constantly changing, and the information is stored in a database.
I am interested in building a silverlight application that the user can pull up and see real-time (or at least, seemingly realtime if polling is the only option) information in a chart or grid as it changes.
As you may imagine, the technology menu for this project is silverlight, asp.net, wcf, and sql server.
What is the right pattern (duplex wcf, polling) for this kind of application?
One example (and please remember, don't limit yourselves to thinking about the financial markets domain) is this "Strategydesk" product from TD ameritrade. You can see how it is constantly updating in real time:
http://www.tdameritrade.com/demo/strategydesk/1497_ameritrade_strategydesk.html

Silverlight has TwoWay DataBinding available to refresh UI seamlessly using ObservableCollections.
On the backend i'll prefer legacy methods "polling" using WCF. Duplex WCP isn;t the right option i think because only one machine can be requester either client or server.
Watch this screen cast:
http://blog.lab49.com/archives/2650
Jason Dolinger has presented a sample SL app for real time Stock updates.. its just a proof of concept.. hope it will help you.
Regards.

You might want to look into using sockets in Silverlight. That will probably be the fastest/most responsive way to send/receive real-time data.

Related

Advise to What is the best synchronization way?

I am encharged to build a web/desktop/mobile app for reservations, so obviously everything should be synchronized whenever a reservation is made either by the desktop, the mobile or the web app, I am thinking on using WPF and SILVERLIGHT for the dev, my question is I'm just seeking for advices before I start this up, are there protocols or ways to do the synchronization in WPF? Or would it be better using another language?
Excuse me if my question sounds dumb, the thing is I have never done something with synchronization and I'm seeking for guidenss.
Thanks in advance.
are there protocols or ways to do the synchronization in WPF?
You can use a Client-Server architecture to handle syncronization between all your clients.
The way this can work is you'll have a central server that handles the back-end logic of your buisness (Manages reservations in your example) and the clients act as the front-end applications that show the user data received from the server, let's him manipluate it through a UI, and send it back to the server for further proccessing such as saving the data in the database.
If you choose DotNet platforms as your development enviornment, You can use Windows Communication Foundation as your communication framework between your clients and your server.
would it be better using another language?
Your syncronization shouldn't rely on the UI framework you choose to develop your apps on, wether it's WPF, Silverlight or any other framework. It should be a seperate layer (like WCF) that keeps the coupling between your UI and DAL loose.
Hope this helps
Consider Sync Framework. Its like... in the name.
Okay, just got home, so can expand this answer.
Microsoft has an example where by it uses Sync Framework, SQL Server and SQL Server Express on the client, syncing using WCF to transfer ADO.Net DataTables and DataSets.
The important thing to realise about why you WANT to use Sync Framework is that it will handle all of the delta/diff/federation stuff for you. It is possible to have Sync Framework to two way sync your data, whilst only sending the delta across the wire.
Remember, don't reinvent the wheel.

Best strategy for connecting from my client to my database

Im looking into developing a new version of a client/server application for a client. The current solution is a website in asp.net mvc.
The purpose of the application is to build a digital signage solution, this means that on the client the user will be creating playlists, from viedos and images and scheduling them to be shown on a screen. The items to be displayed are WPF user controls, one with logic for image and one for logic about video.
The current application is web based and accesses the central database directly. When all the clients (the ones that present the information) request data it is done through a webservice. The customer is very happy to use the web based client, although they request more "rich" behavior. This includes a principal requirement og having a preview of both a single "slide" and of a collection of slides.
I started developing this as a WPF application (discarding silverlight because of the preview of a wpf user control). Now im faced with the problem/challenge of defining how to access the database. The customers probably want the same usage pattern as they have now, where they move around with their labtops and thus not being on the same network as the database all the time.
My question is this: How do I design the database connectivity layer, should i go for pure web service based so everybody always use this, or should i make some kind of disconnected mode, where they can work at home, then connect and synchronize their data? Should i require them to be on the same network as the databse, so i can connect directly using a database layer and a connectionstring?
Will a webservice based approach be fast enough for working with images, videos (thinking about only loading thumbnails of these, else data would kill the performance ~several Gb og data). Im planning on using thumbnails on the clients and when on the home network they connect and get all the big videos and images...
When designing your app it's worthwhile to remember the KISS and YAGNI principles, and to be wary of overkill solutions and premature optimizations.
If I understand correctly, you have a working web-app, in which the only further feature which is required is a slideshow of sorts.
you can find lots of jQuery (or any other web-client framework) solutions for that.
If, nevertheless, you decide to develop a new client- you already have a webservice which is working well! I would suggest using it.
About the idea of storing the data on the client side- that's a classic candidate for YAGNI; Test your application's performance, and then see if you need anything more sophisticated like caching on the client side etc.
A side note- having the client application access the DB directly is not a recommended approach; it effectively cancels the 'server' part of 'client-server', and causes a high coupling between your presentation and business logic / data access.
It would be better to have a WCF application on the server which is responsible for fetching the requested files.

Silverlight Multi-User application with synchronization

I am wondering if it's possible to create a graphical application in Silverlight which supports synchronisation between the different clients.
To be a bit more precise, I am drawing concepts of developing a Silverlight Game. Visitors would log-in, and see live, synchronised what the other vistors are doing.
If it is possible to have this implemented, I would like to know what is needed to create a fully synched Silverlight environment between multiple peers. Anything from links, code snippets, ideas and / or alternatives are more than appreciated !
Please do not suggest Flash, as I do not own a valid Flash building license, I prefer to have this created within Visual Studio 2010.
Edit:
I want it to be as lightweight for the clients as possible, I don't care much for the server, and also low bandwidth consuming. I don't know whether a broadcasting principal is the only option to have all the events taken place at the same time?
You may want to take a look at the Polling Duplex protocol of WCF. This is the subscription and publish concept. Support in SL has been about since version 2 so there's plenty of articles out there. An article I referenced for a message broadcast system we put in place at work can be found here...
http://tomasz.janczuk.org/2009/07/pubsub-sample-using-http-polling-duplex.html
which also mentions an interesting project on codeplex (I've not used)...
http://laharsub.codeplex.com/
A simple and working (but rather inefficient) solution would be for all clients to ask a WCF/Ria service on the server for status updates in regular intervals, perhaps once every X seconds or so, letting the server keep track of changes relevant to the calling clients.

Silverlight pages binding to dataset(design question)

I have a legacy dot net application (now migrated to .net 2.0).
We need to convert this application to silverlight.
Problem here is the datalayer. All the methods from the datalayer return datasets.
The entire web application is using datasets for databinding.
Now the questions are:
Can I use the same datasets for silverlight pages also?
Or do I have to create a wrapper around the datalayer?
Or do I have to change the entire datalayer architecture (like returning collections etc)?
Please suggest the best possible way.
Thanks,
SNA
Unfortunately, DataSets aren't supported in Silverlight 2 (and afaik aren't coming in Silverlight 3).
I'm going to assume that your current data layer has methods like GetTopCustomers that return DataSets, then the client application can modify that data and re-submit it to a data layer function like UpdateCustomers that takes a DataSet as a parameter and then submits changes to a database. If this is the case I think you'll have a tough time writing a wrapper because you'll be on your own for enforcing referential integrity and tracking changes on the client side. It's certainly possible but I think it'll be more pain than its worth. So imo creating a wrapper around your data layer would be equivalent to changing the entire data layer architecture to return collections, etc.
You best bet for a data layer is .NET RIA Services, which ships sometime in the Silverlight 3 timeframe. It's a huge leap over the current technology, ADO.NET Data Services, in that it adds change tracking and a DataSet-like "context" for the client. It also allows direct sharing of code between ASP.NET (or any part of the full .NET Framework) and Silverlight so your business rules can be run on both the client side and server side. Rewriting your data layer may not sound appealing, but I think it'll spare you much pain and you'll get a huge return if you choose .NET RIA Services. If that choice doesn't fit the other option is to use ADO.NET Data Services to ship the data back and forth (combined with a wrapper for your current data layer) or to write your own custom WCF services to provide CRUD operations (again with a wrapper on your current data layer).
Good luck!
If the goal of your conversion is to create a Silverlight version of your application with the least amount of change to your business logic layer, then a wrapper is your answer.
This is a lot of work in Silverlight V2, as you probably know. If you'd like some detail, here's a blog post. You will end up rolling your own serialize/deserialize/zip/encode layer for transferring the data to your Silverlight app.
Silverlight 3 isn't out yet, but close from the rumors. And this functionality is present in V3 (from what I hear).

What are the cons of a web based application

I am going to write a database application for the camp I work for. I am thinking about writing it in C# with a Windows GUI interface but using a browser as the application is seeming more and more appelaing for various reasons. What I am wondering is why someone would not choose to write an application as a web application. Ex. The back button can cause you some trouble. Are there other things that ayone can think of?
There are plenty of cons:
Speed and responsiveness tend to be significantly worse
Complicated UI widgets (such as tree controls) are harder to do
Rendering graphics of any kind is pretty tricky, 3D graphics is even harder
You have to mess around with logins
A centralised server means clients always need network access
Security restrictions may cause you trouble
Browser incompatibilities can cause a lot of extra work
UI conventions are less well-defined on the web - users may find it harder to use
Client-side storage is limited
The question is.. do enough of those apply to your project to make web the wrong choice?
One thing that was not mentioned here is the level of complexity and knowledge required to generate a good web application. The problem being unless you are doing something very simple, there is no "Single" knowledge or technology that goes into these applications.
For example if you were to write an application for some client server platform.. you may develop in Java or C++. For a complex web application you may have to have expertise in Java, Java Script, HTML, Flash, CSS, Ajax, SQL, J2EE.. etc. Also the components of a web based application are also more numerous, Web Application Server, HTTP Server, Database, Browser.. are tipical components but there could be more.. a client server app is tipical just what it says.. a client application and a Server application. My experience and personal preference is not web based .. web based is great for many things. But even though I am an IT Architect for a leading company that is completely emersed in Web Apps as the solution for everything... The cons are many still.. I do thing the technology will evolve and the cons will go away over time though.
Essentially the real limitations are only through of the platform, being the browser. If you have to account for all browsers in current use that can be a pain due to varying degrees of standards in each of them.
If have control of the which browser to use, that is everyone is on computers that you control on site, and say you install firefox on all of them, you could then leverage the latest Javascript and CSS standards to their fullest in your content delivery.
[edit] You could also look into options like the adobe integrated runtime or "AIR" as an option allowing you to code the front-end with traditional browser based options like xhtml/css/javascript, flash/flex and have the backend hooked up to your database online, only also providing functionality of a traditional desktop app at the same time.
The biggest difference and drawback I see with web applications is state management. Since the web is, by nature, stateless every thing you want to maintain has to be sent back and forth from the server with every request and response. How to efficiently store and retrieve it in a matter with respect to page size and performance is hard to do at times. Also the fact that there is no real standard (at least not that everyone adheres to) for browsers makes consistency really..........fun.
You need to have a network access to the server that you are going to have the web application on (if there are going to be multiple users for the application - which is typically the case).
Actually, there are more pros than cons - if you can give some details about your application, we could help a little more...
It completely depends on the requirements of your project. For the most part, there isn't much web applications cannot do these days. Admittedly, certain applications do belong on the desktop as browsers (while currently advancing, and rapidly), still are not quite there yet. From the advent of applications such as Google Docs, Gmail
There isn't much you -cannot- do on the web. If you're creating a World of Warcraft competitor however, the web is most certainly not the optimal solution. Again, unfortunately we'd need more insight on the application you're building for the camp. The best part about the web is that anyone with a browser can use your application.
Web applications delegate processing to a remote machine. Depending on the amount of processing, this can be a con. Consider a photo editor that's a web app.
Web applications also can't deal with a whole lot of data going back and forth to and from a client. You can watch video online.. when it's compressed. It will be awhile before we see any web-based video editing software.
Browser compatibility is also a hassle. You can't control the look-and-feel of the application 100%.
Vaibhav has a good point. What's your application?
A major one is down time for migrations... users will not expect the application to be down, ever, but realistically it will have to be down for major upgrades. When doing this with a desktop application, the user (or end-user systems admin) is in control of when upgrades happen; with an online app, they're not.
For applications which have large data, performance can be a major problem as you're storing a large number of users' data centrally, which means the IO performance will not be as good as it would be if you gave them all a laptop.
In general scalability gives problems for a server-based app. Desktop applications scale really well.
You can do an awful lot with a web-based app, but it is a lot easier to do certain things with a thick client:
Performance: You get simple access to the full power of the client's CPU.
Responsiveness: Interactivity is fast and easy.
Graphics: You can easily use graphics libraries such as DirectX and OpenGL to create fast impressive graphics.
Work with local files
Peer-to-peer
Deciding whether a web application is a good approach depends on what you are trying to achieve. However here are some more general cons of web applications:
Real integration with desktop apps (e.g. Outlook) is impossible
Drag and drop between your app and the desktop / other running apps
With a web application, there are more privacy concerns, when you are storing user data on your servers. You have to make sure that you don't loose/disclose it and your users have to be comfortable with the idea of storing that data on your servers.
Apart from that, there are many security problems, like Man-in-the-middle attacks, XSS or SQL injections.
You also need to make sure that you have enough computing power and bandwidth at hand.
"Ex. The back button can cause you some trouble."
You'll have to be specific on this. A lot of people make fundamental mistakes in their web applications and introduce bugs in how they handle transactions. If you do not use "Redirect after Post" (also known as Post-Redirect-Get, PRG design), then you've created a bug which appears as a problem with the back button.
A blanket statement that the back button in trouble is unlikely to be true. A specific example would clarify your specific question on this.
The back button really is not that much of an issue if you design your application correctly. You can use AJAX to manipulate parts of the current page, without adding items into the browser history (since the page itself wont change).
The biggest issue with designing web applications has to do with state, and the challenges that need to be programmed around. With a desktop application, state is easy to handle, you can leave a database connection opened, lock the record and wait for the user to make the changes and commit. With a web application, you could lock the record...but then what if the user closes the browser? These things must be overcome in the design of your application.
When designing a web application, make sure that each trip to the server "stands alone" and provides a complete answer. Always re-initialize your variables before performing any work and never assume anything. One of the challenges I ran into once was pulling "pages" of grid data back to the user. In a real busy system, with record additions/modifications happening in real time, the user navigation from page to page would vary greatly, sometimes even resulting in viewing the same set of a few records as new additions were added in-front of the query.

Resources