Use windows service to update site maps

Source: Internet
Author: User

Due to the increasing number of accesses to the company's platform, the database of the company's projects has been down several times. To reduce the pressure on the database, I made adjustments to the company's projects last month. Extract news sections from a single site and database. Reduces the burden and pressure on the primary site and database.

However, the number of new news articles published in an online month is at least 500. Baidu only recorded about 70 items, which may be caused by no site map. But how do I regularly update the site map?

I tried to use the windows service to regularly update the site map.

================================ Enter the subject ============================ ================

First, you need to understand several questions.

1. The format of the Site Map indexed by Baidu.For details, see the link: View

Currently, I only use the site map in xml format to describe the site map in xml format.

Xml format:

Description of each label:

<Loc> www.example1.com </loc>. The value must be less than 256 bytes (required ). Format: <loc> your url </loc>

<Lastmod> 2010-01-01 </lastmod> date of the last modification to the file (optional ). Format: <lastmod> year-month-day </lastmod>

The frequency of possible changes on the <changefreq> always </changefreq> page (optional ).

Valid values: always, hourly, daily, weekly, monthly, yearly, and never

<Priority> 1.0 </priority> priority of the webpage. Valid values range from 0.0 to 1.0 (optional ). 0.0 has the lowest priority and 1.0 has the highest priority.

2. Frequency of site map update

Since the company's news updates are generally fixed. About 10-50 pieces of news are published every day. Therefore, I plan to update the site map at: 9: 00--19: 00 every 3 hours. I will not perform any operations at other times, reduce the burden on database queries.

Start writing windows Services.

1. Create a windows Service and give it a name

 

2. Add the installer

Double-click Service1.cs To Go To The view page, right-click, and select "add installer"

 

Added results.

 

ServiceInstaller1: service installation component. (Mainly used to set the service name, service description, whether the service is started or delayed, and how the service is started)

ServiceProcessInstaller1: service process installation component (the main User sets the Account type for running the service, such as User, LocalService, NetworkService, and LocalSystem)

Attribute settings of serviceInstaller1 (shortcut: F4 ):

 

Attribute description:

DelayedAutoStart: Set whether to start automatically

Description: Service Description

ServiceName: Service name

StartType: Start type. There are three types: Manual, Automatic, and Disabled)

ServiceProcessInstaller1 attribute settings (shortcut key F4 ):

Attribute description:

Account: The Account type of the running service. There are four types: User, LocalService, NetworkService, and LocalSystem.

I chose LocalSystem, which means that the current system can run.

3. Some misunderstandings that need to be paid attention to during timed triggering.

Timing trigger. You must remember the Timer component. Windows Services do not have the Timer control .... The Timer component is not triggered on a regular basis. You need to implement the Timer trigger event on your own. I have been stuck in this issue for a long time ....

In order to realize the controllability and modification of scheduled events. Added a configuration file. How to add configuration files

Windows Service Project -- Right-click -- add -- new item

 

Configuration File Settings:

 

4. Scheduled windows Service Code:

  =  Timer();                  OnStart(            aTimer.Elapsed += = = .Parse(PublicMethods.GetAppSettings()) * ;      .aTimer.Enabled =                                       aTimer_Tick(             (DateTime.Now.Hour >=  && DateTime.Now.Hour <= = 

Method for generating Baidu map (GetBaiDuSiteMap ):

= Path = Path. Combine (PublicMethods. getappsetde (XmlNode root = xmlDoc. SelectSingleNode (platform announcement List <IT_NEWS> platformnotice = (platformnotice! = & Platformnotice. count> & platformnotice []. newsId> (IT_NEWS platformNoticeNews = xmlDoc. createElement (= xmlDoc. createElement (= ++ platformNoticeNews. newsType ++ platformNoticeNews. newsId + = xmlDoc. createElement (= Convert. toDateTime (platformNoticeNews. newsCreateTime ). toString (= xmlDoc. createElement (= xmlDoc. createElement (=

=============== Code Completion ======================================

Install windows Services:

You need to write a batch for windows service installation and the batch for uninstallation, all of which are placed in the bin/Debug folder of the windows service project.

Install the service with the following code:

%SystemRoot%\Microsoft.NET\Framework\v4.= auto

Explanation:

GameTradingNewsService.exe is the name of the exe program in the binfile after the windows Service Project is compiled.
Net Start xxx is to enable the xxx Service
NPCgoNewsServices is a windows Service name (that is, the service name (serviceName attribute) set in the serviceInstaller1 attribute panel ))
SC config NPCgoNewsServices start = auto is to set the windows Service Startup Mode to automatic

Uninstalling the service unstall. bat code:
%SystemRoot%\Microsoft.NET\Framework\v4.\installutil.exe /u GameTradingNewsService.exe
GameTradingNewsService.exe is the name of the exe program in the binfile after the windows Service Project is compiled.

So far, a service is completely complete.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.