Persistent Dataset for WPF Browser App? - c#

I am on a quest to find the best method to implement this data structure in my WPF c# .NET 4.0 web application.
App Details: This application will have many users at one time. I'm working with a database that has 2 tables linked together, both with <10k rows, but they will grow with time. One table will need to be checked for updates periodically.
Question:
I created a dataset to hold all information. My unit test shows it takes ~0.2 seconds to populate the dataset from the database. This is no time if the dataset will persist across the application. Can it persist across the application for many users?
The other method I can think of is using observable collections for the data and storing them in a singleton. Is there any method that I am missing here or something that will work better for me?

I think you're misunderstanding some really important concepts here. First of all, WPF is not ASP.Net, WPF applications do not "run at server". WPF applications run at the computer that executes them (I.E the client) regardless of being an XBAP that runs inside Internet Explorer.
Therefore, you cannot have such thing as a "singleton" shared between many instances of your WPF application because each instance will be run on a separate computer on its own process. There's no practical way to share memory between these instances.
Then, if you need a "Web Application", WPF might not be suitable for your project. WPF is not a web technology, it is a rich desktop application technology that does not depend on the crappy implementations of HTML or anything like that.
Now, if you need (or desire) the richness and awesomeness and ease of development WPF provides, you will have to implement a Client/Server application, possibly using WCF or any other communications technology to enable your rich Client to communicate with the Server.
The "Server" will be an application responsible for querying the data from the database, then possibly caching it in memory, and then sending it to the client. Usually a WCF Service application is enough for this, although depending on your requirements you may need to implement more layers on top of it.
Beside this, I don't think there is a good reason to send a WPF client 10k rows of information, so you will have to come up with some paging mechanism in order to send the data in "chunks" instead.
Please provide more details about what you need and I can give you more insight.

Related

How should I interact with a database from a desktop application without opening it to the whole world?

Basically, I have a new desktop application my team and I are working on that will run on Windows 7 desktops on our manufacturing floor. This program will be used fairly heavily as it gets introduced and will need to interact with our manufacturing database. I would estimate there will (eventually) be around 100 - 200 machines running this application at the same time.
We're lucky here, we get to do everything from scratch, so we define the database, any web services, the program design, and any interaction between the aforementioned.
As it is right now, our legacy applications just have direct access to a database, which is icky. We want to not do that with the new application.
So my question is, how do I do this? Vague, I know, but basically I have a lot at my disposal here, and I'm not entirely sure what the right direction to go is.
My initial thought, based on what I've perceived others doing, is to basically wall off the database by using webservices. i.e. all database interactions from the floor MUST occur through the webservices, providing a layer of security by doing much of the database logic behind closed doors. Webservice calls are then secured to individual users via Active Directory.
As I've found though, that has some implications of its own... We have to abstract the data before it reaches the application. There's still potential for malicious abuse by using webservice calls repeatedly to ruin or spam data. We've looked at Entity Framework and really like what it provides, but as best I can tell, that's going to be unavailable by the time we're at the application level in this instance.
It just seems like I can't come to a conclusion on what is "right". So, what is right?
WebServices sounds like a right approach. Implementing a SOA-oriented layer on the webservices layer gives you a lot of control over what happens to the data at the database server.
I don't quite share your doubts about repeated calls doing any damage - first you can have an audit log of every single call so that detecting possible misuses is obvious. But you also could implement a role based security so that web service methods are exposed to users in roles, which means that not everyone will be able to call just any method.
You could even secure your webservices with forms authentication so that authentication is done against any datasource, not only the active directory.
And last thing, the application itself could be published as a ClickOnce application so that it is downloaded and executed from the web page and it automatically updates itself just as you publish new versions.
If you need some technical guidance, I've blogged on that years ago:
http://netpl.blogspot.com/2008/02/clickonce-webservice-and-shared-forms.html
My suggestion since you are greenfield is to use an API wrapper approach with Servicestack.
Check out: http://www.servicestack.net/ServiceStack.Northwind/
Doing that you can use servicestack authentication, abstract away your db layer (because you could move to a different DB provider, change its location, provide queues for work items etc...) and in time perhaps move your whole infrastructure to an internal intranet app.
Plus Servicestack is incredibly fast, interoperable with almost any protocol you through at it, and provides for running it through MONO, so you are not stuck with a MS backend that could be very expensive.
My two cents. :)
First of all this question is not appropiate for StackOverflow, you might get close-votes really quickly.
Second, You may want to have a look at WCF RIA Services for this.
These will allow you to create basic CRUD operations for all your entities, and stuff like that.
I never used this myself, no I'm not sure what the potential issues might be.
Otherwise, Just do what we did:
Create generic (<T>) interfaces and services and contracts and everything. This will allow you to adapt your CRUD functionality in your Services, DAOs, ViewModels and such to any entity type.

Building web UI

I have a working WinForms application, written in c#, which is divided in several layers (Data layer, Model, business logic, common layer, etc). I would like to allow users to use web browser also for data manipuolation. Do I need to make some kind of in-between layer, or I am safe with using business layer from Web forms? Also, what kind of MS technology should be used on the web layer, as I see that we can use both classic ASP.NET pages, Silverlight, or maybe something else? The application itself has several forms for entering data, and many, many different forms with charts and reports.
Thanks in advance.
It's hard to make a recommendation without knowing your existing app details. There's also no one right answer. Silverlight, ASP.net (MVC), Javascript/jquery/ajax are all good technologies that have their place and use. But, as you decide for yourself, here's some thoughts and things to consider.
A thick winform app is typically a fat client with local state. Your data model etc... may rely on state to be persisted across many requests in a fatter local process.
A thick winform app is typically used by the one user & process - unless you're coding concurrency, your app may not be thread safe.
A web process is shared by multiple users making requests - any shared state will need to consider concurrency and memory footprint.
You typically want the web process to hold less state and drive more of the client experience down to the client - thus the popularity in ajax, jquery etc... More javascript technologies.
Silverlight is closer to your winform process - it's hosted in the browser plug-in with the state and code being accessed by that one user. You will have to change the view layers to silverlight but you might be able to retain your model and data layers.
Running in a silverlight plug-in does have more restrictions (sandboxed) than a full winform app. http://msdn.microsoft.com/en-us/library/dd470128%28v=vs.95%29.aspx
Many folks like ASP.Net MVC - check it out.
Javascript approaches using ajax, jquery, etc... has gotten alot of momentum in recent years. Be aware that will be a bigger shift from your winform code which may be good or bad depending on how you look at it.

New application with multiple UI : WPF and Mobile website (asp.net)

I am in the first step of the design of an application that would support two completely different UI, and I would like to do it with the minimum duplication of code.
The first UI would be a windows application (probably with WPF), that will be the most used, the second would be a web application accessed mainly through mobile devices.
Knowing that the WPF application have to work completely disconnected from the network
and that once in a while, it must be possible to synchronize the work done offline in a central server
Here is what I was thinking to do:
WPF version:
MVC style WPF application, SQL server compact/express on each workstation and entity framework for data access, organize so that the WPF model, the entity model, and the controllers are in a separate assembly.
In addition, we will need a SQL Server database to synchronize the work of everybody.
Web version:
This is where things get blurry in my mind:
If I do an asp.net MVC application, modify it so that it is mobile friendlier, do you think it is possible to reuse the model, entity model, controllers, validation, etc. ?
I am still in the early stage of the design, and I am not familiar with asp.net MVC, so if you have other solutions, that would help a lot.
Also I will create and post here a POC when I will have a good design, so that it can be reused.
I would suggest the following:
Build a Service Layer (http://martinfowler.com/eaaCatalog/serviceLayer.html) using TDD (http://en.wikipedia.org/wiki/Test-driven_development) to encapsulate the functionality of your application.
Build a remote facade (http://martinfowler.com/eaaCatalog/remoteFacade.html) on the service layer to service remote clients (WPF, Andriod, iPnone, WP7 etc etc)
Read up on MVVM and Prism4 (http://compositewpf.codeplex.com/) before starting the WPF app.
Build the ASP.NET to access the service layer directly/in process.
Hope this helps, good luck!
If you're developing in WPF then forget ASP for your web based code. Structure it using MVVM pattern.
It's not a vast step change to have the same WPF application switched to be browser based (that's part of the point for WPF), certainly far quicker than writing a second app. Have a look here for information about WPF (applications and browser).
What form of data transfer is required - have you considered MSMQ for passing data to the server. This then wouldn't care if there was a connection or not and once there is data would be transferred without any work on your part.

Should I use WPF or Windows Forms Application for my project in C#?

I am developing a Client-Server based application in which client application will access server database to store billing information. It will also have report generation facility. Windows Forms is good in document printing & I don't see such facility or controls in WPF. If I am wrong then please correct me.
I want database security, which DB should I use, SQL Server, MySQL or Oracle. I would like to use free DB but security is my priority.
Please suggest how I can implement a Client-Server architecture with multiple clients in C#?
Thank you Geeks!!!
Using WPF will allow you to deliver a more innovative User Experience. There's a decent high level overview of Working with Documents in WPF on MSDN.
Any database should be able to provide decent security. If you're using C#, I would recommend one of the versions of SQL Server (If SQL Server Express works for you...go for it).
Windows Communication Foundation (WCF).
Regarding 1.
WPF has a handy PrintDialog control with a PrintVisual method on it. This can be used to print any visual elements from a WPF controls hierarchy and may be able to satisfy your printing requirements.
I have developed many applications in WinForms and only a few in WPF, but I would lean very heavily in the WPF direction for any new development. It is very flexible and powerful.
1- WPF is awesome when you want to implement a windows application, and consider the freedom it gives and the separation of concern you can eventually get, I would say 100% go with WPF. There are many ways to control your printing procedure that some have been already explained in above.
2- For database, depending on your load and concurrency, you can choose a different database. Oracle is an awesome one, but probably the most expensive one. So, at the end you need to compare MySQL which is a fantastic db and at the same time free, and SQL server express edition which is a free version of the enterprise/professional version of Microsoft SQL server. Express edition is basically the limited edition of the same database, and if you need o expand your network and support, you might not be able to afford the fees of an enterprise solution. So one idea can be to stick to the best free database from the beginning if you foresee such a demand in the future. The security of these both databases are somehow in the same level, but you need to work on your network/server securities as well, because I found them harder to break.
3-Using Windows Communication Foundation (WCF) is very simple and easy especially when you want to use something like WPF. You basically create some data contracts and publish them, and that would be your communication end points. You basically call them, and deal with them as they are your local methods. Highly recommended. So what do you mean exactly by multiple clients? Does it mean different types of client (like web-based, mobile apps, etc.)? I also suggest taking a look at RESTful web services as it has the same kind of communication concepts. I just mentioned some names, so you can start reading something about each of them.
1 - Actually, WPF provides better/easier document/control printing that winforms does. Additionally, WPF still provides support for RDLC and other reporting solutions for printing & reporting. Asking if you should use WPF or WinForms is like asking if you should eat lemons or limes for vitamin C. Regardless of which one you use, you'll get where you're trying to go, but the flavor and experience will be wildly different.
2 - The database is not your security. The DB you choose will have little to no impact on your security. Personally, I would look at Active Directory and Domain security, and basically allowing the system to use the user's domain account and domain groups to control authentication and authorization.
3 -There are many possible solutions to a client-server framework, and each one has its own strengths and drawback, and then there's also the possibility of using webforms which you've not even touched upon.

ASP.NET and C# constant processing behind the site possible?

Imagine a site where the user logs in and can view their ip webcam (I can do this bit i believe). The problem is i want the site to do some processing on the images/video coming in even when the user is not logged in i.e run some motion detection algorithm and if there is motion log the incident in a database.
What would i need to learn about to implement this project? I want to use ASP.NET and C# so i assume:
Learn ASP.NET.
Learn C# (I'm a pretty competent desktop application developer).
mySQL database (Is this the best kind of database to use in this situation?).
I've not used ASP.NET before hence i have no idea what it can/can't do. I think i can get an ASP.NET site up and displaying a live feed but how do i implement the bit that is always running in the background processing stills from the live feed and logging the incidents?
Any help is appreciated. Thanks in advance.
You probably want to use something like a Windows Service to do the continuous processing. With the ASP.NET site talking to the database and displaying the feed.
ASP.NET is not really suited to doing background tasks.
MySQL should work fine and is free, so if this is not a work related task then it might be a good choice. I have a MySQL database here that contains close to 100GB of text. So it should handle what you are suggesting.
The the web site and database you're on the right track, ASP.Net and MySql will work just fine for the type of project you are describing. However, the processing bit doesn't fit very well into the ASP.net model.
I would recommend that you think about creating a Windows Service to do whatever processing you need to do. It sounds like you want your processor to work on remote video streams so you'll need to consider how you'll get those live streams to you service and how many concurrent streams you could realistically process.
Perhaps it may make sense to have a client application or service that your users would run locally which would ping your hosted service when it detected a movement? In that case you'll likely want to look at hosting a WCF service which can be done in IIS or any standalone application (such as the aforementioned Windows Service).

Categories