1. Why are web pages used for real-time monitoring?
LZ recently bought a house in Wuxi. Although she works in Shanghai, the housing prices in Shanghai are too high and unbearable, so she chose Wuxi, which is acceptable, as a place to settle down. Friends who have bought a house may know the process of buying a house. One very important step in buying a house is that it requires commercial housing filing. To put it simply, when you buy a house, you can check the registration status of your house at the government commercial housing filing website. If the developer has already registered and is still selling this house, it must be a one-bedroom sale. And a very important point is that only by preparing for the case can we proceed to the next bank loan. As the bank interest is getting higher and higher, the earlier the registration, the better the loan is, the better it is. Therefore, it is particularly important to know the filing status of your house purchase as quickly as possible.
Of course, you can also check your filing status at the website every day. Obviously, this is not the way a programmer is, nor is it the way a .Net programmer is. The programmer's approach is to honestly notify the program to the mobile phone once the registration is completed. By the way, I would like to complain that the website for filing is really slow.
2. Choose Windows Service, Form (winform), Web or Console Program?
Of course, the most suitable one is definitely Windows service, Winform and web are definitely OK. The console program is not necessarily the most suitable, but development is definitely the fastest. After comprehensive consideration, it was a very small monitoring project and it only took one or two months, or one or two days, so it was not so complicated. Moreover, the Windows service had to be installed on the server. The most important thing is that the console is the fastest to develop and the easiest to deploy, so I finally chose the console program.
3. Analyze the requirements
1. The filing situation needs to be checked every few minutes, so System.Timers.Timer is required. Of course, if it is a very robust or complete project, it is recommended to use Quartz.NET. Of course, you can choose Topshelf, Hangfire, FluentScheduler, etc.
2. Because you need to check the registration status of the website, obtain the html of the registration web page, and then determine whether the html contains the word "for sale". If not, it means that the registration has been filed. System.Net.WebClient is required. There are more search websites under .net. The most basic ones are HttpWebRequest, HttpClient, or RestSharp, which are all good choices.
3. Because real-time notifications are required, Alibaba Cloud's SMS notification was selected. Because other projects are used, they can directly copy the code to use it. Of course, there are also many notifications, such as emails, apps, etc. Of course we don't need to be that complicated.
4. Code module
Direct code, logic and code are simple.
class Program{ static System.Timers.Timer timer = null; static void Main(string[] args) { timer = new System.Timers.Timer(2 * 60 * 1000); timer.Elapsed += Timer_Elapsed; ; timer.Start(); Console.ReadKey(); } private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { WebClient client = new WebClient { Encoding = System.Text.Encoding.GetEncoding("utf-8") }; var html = client.DownloadString("http://www.xxxx.com/xxxx.html"); Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "..." + "Not signed."); if (html.IndexOf("For Sale") == -1) { if (timer != null) timer.Stop(); // Send 5 text messages for (int i = 0; i < 5; i++) { // Send SMSMessage.Send("152****7178", "SMS_92310001", new { name = "Emrys", status = "Congratulations, congratulations, the house has been signed for sale!" }); Thread.Sleep(5 * 1000); } } }}