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.
Related
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.
I am really new to the concept of RESTful Web APIs, please do not go hard on me but I just really cannot think a way of it.
So basically, what I cannot find a solution for that I cannot find a way to make my console application works without my manuel 'start' command so that DB can stay up to date so that in the meanwhile API would only be responsible for getting the data from DB or other CRUD operations.
I had a console application which can parse data from a website and store the necessary values to the database. Then in the same solution, I also created a Web API - MVC project and wrote CRUD operations for all entity data types. They both works without any problem, however unless I manually make the console application to run the code and update the DB, DB has old values so the get operations ended up with wrong values.
All I wanted to do is to somehow run the console application's code (might be at certain times) so that the DB can stay up to date.
Hope I did not ask in a confusing but if I do it is because I cannot figure it out and cannot understand the process.
Appreciate if someone can briefly explain me what I have to do.
Thanks !
What you're asking really isn't a programming question per se, but more of a scheduling question. You could turn your code into a service and install it, but that is really overkill for what you need. (Some people would argue that a windows service isn't appropriate for this since all it does is run at scheduled times and not wait to intercept information, but that is a whole other discussion).
What you need is a Scheduled Task in Windows: http://windows.microsoft.com/en-US/windows/schedule-task#1TC=windows-7
We have developed a Vehicle Tracking Application in MVC5 using EF6.
The app has a dashboard on which current status of vehicle is displayed i.e. Moving / Stopped/ etc.
To Load current status the dashboard view fires async ajax request(every 20 seconds) to fetch latest data.
Now, rather then making calls from client machine, I want that the client should automatically receive the update as soon as new data is available for its vehicle. It should not poll every 20 seconds.
I've read about SignalR, and tried implementing the Chat program. That's works well. But somehow, I'm unable to figure out "How to use it in my scenario?".
Also, I read about SQLDepedency to detect changes in DB, but again couldn't reach to a solution.
Will be glad, if someone can point me in right direction.
Thanks.
Some time ago I experimented with replacing polling with SignalR too. It was quite straightforward and I used mainly SignalR web as a source of information.
I remember I dealt with some serialization issues but it was more related to the message contract as we used a hierarchy of interfaces and implemented some inheritance in contracts (My question from that time).
Just a suggestion - plan well for scalability - how will your scenario work when you will have to scale out (if applicable) to multiple servers. For my high frequency messaging it was a no-go reason (My question from that time).
maysbe this link can help.
It is SOAP based but also express the fact taht you will have to implement a wbeservice like part on the device.
My assignment is to create an App for a Mobile Device (Like iphone/android/BB/etc..), the purpose of this app is to tell the users there is something new on the website and then show an list (inside the App) showing the latest updates.
The Company insisted I use ASP.NET/C#/Visual Studio and use the SOAP protocol.
I've started working with C# and then using the so called WCF.
I've already got some stuff working. (Like "consuming" the WCF from an Android App and getting data sent back).
My Question is what will be the best "Architecture" to work with for the Mobile App Development. I was thinking about have only 1 WCF and then call a general function like Do() (Or some other name :)) and then adding a soap header where u can define what u want the service todo. Like getting a record from the database, or ping , er something else, whatever the company may need in the future :)
How this would work:
The Client (Mobile App) would make a call to the WCF, and in the soap header is states, lets say, it wants to register the Phone with the Device ID. The WCF will receive the Soap Requests, extract the header and use some sort of switch to decide what it needs todo. Once it knows that to do the WCF will then, for example, access some local Classes to insert/retrieve Database data or do something else and when its done it will simply return what is needed. (Like an OK sign or data or something else.. :)).
Is this a right approach, cause how I am looking at this, it makes it very easy for changes on the back end without updating the App.
Sorry if this a retarded question, but I am new to WCF and Mobile App Development, and i'am trying to deliver a great product at the end of my internship. I was just wondering what sort of "Architecture" you guys suggest I would use for this sort of assignment.
EDIT
I already told them SOAP is too heavy for mobile development and shown them some graphs. But they insisted to use techniques they already know.
After doing some research I indeed think the contract based approach is the better way to go. But can you maybe answer a few questions regarding it?
-Can I have like one WCF file that gets "consumed" which holds all the different operations?
-Can I authenticate the client (With using Soap headers Required) at the beginning of the WCF and after that call the desired operation?
SOAP is generally regarded as a little too heavy for mobile development. Since users may incur data charges and generally have lower bandwidth, it would be preferable to take a REST/JSON approach. You can still use WCF to do this at the server.
You can use a generic operation (MessageAction="*") but you will then need to handle the serialisation/deserialistion of messages yourself. However, unless you have a pressing reason to do this I would suggest properly structured operations are the better way to go. They are much more maintainable. You can still make implementation changes at the server without affecting the client, as long as the message contract does not alter. The reality is that if you want to change the message or operation contracts you will have to make changes to the clients anyway. After considering this, the 'contract' based approach only has upsides and no real downsides.
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).