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

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).

Related

Can asp.net Razor Pages maintain programmable threads?

I'm coming from building Web-Interfaces from scratch (without any Framework, just HTML/PHP/CSS/JS) and I now try to "evolve". I really like using C# for all my recent projects which is why I found out about ASP.NET and Razor Pages.
I'm not sure if I understand them correctly, can I see Razor Pages ASP.NET Web-Applications as an "Application" we're used to? Which means, can I implement parallel working processing code while the user browses the site?
As an example, i plan to create a web-interface which shows continuous input data from sensors via Networking. Would this be possible, e.g. with a Thread receiving and processing data and then showing on the Website?
If not, what would the preferred framework or solution be?
I find all the tutorials to be to complex to find an answer to this question quickly.
Yes that can be done but using some technologies.To do so you can use SignalR to Notify the clients with the updated changes
Signalr:is a library for ASP.NET developers that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data.
https://www.asp.net/signalr
Then You can use WebAPIs for SPA or Just rest calls so as use can use the system normally and the server responds to your method execution async.
https://www.asp.net/web-api

Combine .NET MVC website and Windows services

I am currently involved in a simple to medium complex IOT project. The main purpose of our application is gathering data from our devices and analyzing that data as well as calculating statistics.
On the server side we run a MVC application. Up until now we used Hangfire to schedule the calculations. Hangfire is an amazing tool for scheduling emails and other simple stuff, for more advanced things it's too slow. The calculations can take up a lot of time and are processor-intensive (we are trying to optimize them though), so we need to call them in a background task, a simple API call won't be enough.
I thought about splitting the application into multiple parts, the website, the core and a windows service.
The problem is, I never tried that before and I have no idea what the best practice is to achieve that kind of thing. I searched for examples and articles, but all I found were suggestions to use Hangfire and/or Quartz.NET.
Does anyone have any resources on what the best practice is to build a MVC application, a Windows service and how they could communicate (probably through a queue)? What is the best practice in such a situation?
Although there may be many different possible ways to connect a site with a windows service, I'd probably chose one of the following two, based on your statements:
Direct communication
One way of letting your site send data to your backend windows service would be to use WCF. The service would expose an endpoint. For simplicity's sake this could be a basicHttpBinding or a netTcpBinding. The choice should be made based on your specific requirements; if the data is small then basicHttp may be "sufficient".
The advantage of this approach is that there's relatively little overhead needed: You'll just have to setup the windows service (which you'll have to do anyway) and open a port for the WCF binding. The site acts as client, the service as server. There's nothing special with it, just because the client being a MVC site. You can take almost any WCF tutorial as a starting point.
Note that instead of WCF you could use another technology like .NET Remoting or even sockets just as well. Personally, I often use WCF because I'm quite used to it, but this choice is pretty opinion based.
Queued communication
If reliability and integrity is crucial for your project, then using a queue might be a good idea. Again: depending on your needs, there may come diffeent products into consideration. If you don't need much monitoring and out-of-the-box management goodies, then even a very simplistic technology like MSMQ may be sufficient.
If your demands to the aforementioned points are more relevant, then maybe you should look for something else. Just recently I got in touch with Service Bus for Windows Server (SBWS). It's the Azure Service Bus's little brother which can be used on premises locally on your windows server. The nice thing about it is, that it comes at no extra charge as it's already licensed with your windows server licence.
As with the first point: MSMQ and SBWS are just two examples. There may be a lot of other products like NServiceBus, ZeroMQ or others usable, you name it.

How to send automatic scheduled emails

There is an ASP.net C# web application through which we can get the recipient emails, time zone and their smtp server details in to the database.I have two requirements:
1. Consider a table in the database. When ever there is a change in the table, an email has to be sent. It is OK if we can constantly check the database every 5 minutes. It would be great if we can send it instantly but a delay is fine.
2. Sending emails automatically at 12 AM at their respective time zone.
I m familiar with C# programming. But kind of new to automatic scheduling stuff. This could sound like a basic question but it would be great if you can help. What is the best way to implement this - Web api or web services or WCF or windows services or combination of web api and task scheduler? Please let me know your thoughts. Also a small tip on how to implement this would be great.
You have an option of setting up trigger but I hate that approach as it will add overhead to your table tow insertion and not actually needed. I think you are in the right path by thinking about pooling. There is a nice little library in .net called hangfire which I find to be very useful to do scheduled task. It has pretty sophisticated reporting and almost all the time works really well. You can give it a try. But if you want to control things better writing a small windows service don't be that bad either. I think doing websevice either using webapi or wcf is a bit overkill here and might not fit purpose.

Persistent Dataset for WPF Browser App?

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.

Silverlight Application for the web - storing data on site

I've made a little game as an application for the web in silverlight using C#, and I simply would like to save the top ten scores of any of the users that go on it.
How can I write to a file and save it on my web hosting area? Is this possible?
I think this would be the best way, because I only need to store a name and score (csv file), and this would be extremely easy. I hope this is possible.
If not could someone point me in the rite direction of being able to do this with a database, I've created a template just incase using MySQL with the features provided from my web hosts. Is there any easy way to do it that way?
Thanks in advance,
Lloyd
You can add a small WCF service to your website with an ISaveScores interface. The SL app can connect to the WCF service to post scores, and the WCF service can then store the data however you want. If you use a csv file, make sure you handle locking properly, since it is very possible for multiple requests to happen simultaneously.
EDIT
Since the host is Linux, just create yourself a rest service or some other service that silverlight can post to in the same way. Silverlight can talk to pretty much any type of service, so use the same technique in your environment.
You could do it with a service as Brian suggested (although it sounds like you might not have windows hosting, so you may not be able to use WCF for it) which is probably the best way -- but if you wanted a simpler solution you could also do it with just a postback to a particular page setup for the purpose.
Write a quickee PHP page that looks for a name and score in POST data, and writes it to your MYSQL database. Call it from your SL app with a webrequest. Then you just need another simple page to query the DB and list the results.

Categories