Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Nancy to build TaskManager2.0 Management system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use Nancy to build a TaskManager2.0 management system, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Some netizens contacted me to see if I could make a background management interface to facilitate the management of all the tasks in the system. Due to time and technical problems in version 1.0, a 3-minute read configuration file dynamic modification task was added, but generally speaking, it is still not intuitive and the operation is not convenient. Just recently came into contact with Owin, you can achieve their own host program to run Web site, without the need for IIS to run background Web, here is a demonstration of the results of clicking the console program to run. Recently, I have used this technology to implement a background management program in my spare time, which is the TaskManagerV2.0 version that the editor is going to talk about.

V2.0 upgrade description

There are four biggest changes in 2.0 compared to previous versions.

1. Background management program

The most obvious difference provides the background management program, when the user starts TaskManager, the user can enter the background management system through the browser to easily configure and manage all tasks, and easily check the latest run time and next run time of the task. Of course, the site address of the background hypervisor can also be configured by the user, which will be explained later.

two。 Diversified host program

V1.0 is based on Window service implementation, and V2.0 can be overloaded using console programs, Windows services, or traditional Web programs.

3. Task storage mode

All tasks of the system are stored in the database and are no longer stored in the xml configuration file with version 1.0.

4. Automatically start as a system administrator

Before the program starts, it will determine whether it is currently running in administrator mode, and if not, it will restart to run in administrator mode.

The most important change is that the Web management site does not require users to deploy in iis. It starts automatically when you start a console program or service.

Back to the top.

Cron expression

Cron expressions are used to specify the frequency of task execution. I have written an article on the online generator of Quartz Cron expressions, which you can use directly.

Back to the top.

The principle of open source TaskManagerV2.0 implementation

TaskManager is an open source task management system based on Quartz.NET and Nancy, which can be hosted by Window services or console programs. The background implementation of Web is implemented by Nancy Host. The next article will introduce this technology.

Introduction to the project structure:

The background management site is completely independent of window service and console program, and is loosely coupled. Let's take a look at how these two hosting services start the background site.

Window service

Protected override void OnStart (string [] args) {DebuggableAttribute att = System.Reflection.Assembly.GetExecutingAssembly () .GetCustomAttribute (); if (att.IsJITTrackingEnabled) {/ / Debug mode allows the thread to stop for 10s to facilitate attaching to the process debugging Thread.Sleep (10000);} / / configuration information reads ConfigInit.InitConfig () QuartzHelper.InitScheduler (); QuartzHelper.StartScheduler (); / / keep the web service running ThreadPool.QueueUserWorkItem ((o) = > {/ / startup site Startup.Start (SysConfig.WebPort);});}

When the window service starts, the startup interface provided by the Web program is called.

Console program

Static void Main (string [] args) {AdminRun.Run (); ConfigInit.InitConfig (); QuartzHelper.InitScheduler (); QuartzHelper.StartScheduler () Try {/ / launch site using (NancyHost host = Startup.Start (SysConfig.WebPort)) {/ / call the system's default browser Process.Start ("http://127.0.0.1:9000"); Console.WriteLine ("system listening site address: {0}", "http://127.0.0.1:9000"); Console.WriteLine (" Program started, press any key to exit "); Console.ReadLine () }} catch (Exception ex) {Console.WriteLine (ex.Message);} Console.Read ();} usage introduction

For the first time, you need to create a new database, execute the SQL merge script under the publisher, and modify the database connection in the config configuration file.

Using Windows services as carriers

Then we only need to know how to install the Windows service to use the platform. Considering that many people don't know how to install and uninstall the Windows service, I provided a gadget I wrote earlier to install and uninstall the Windows service. The source code is also included in TaskManager.

1. Run the Windows installation and uninstall tool

two。 Select TaskManger.exe- "install -" to run

After running successfully, you can find "scheduled Task Management Service" in system Management-"Service".

After running successfully, a Logs folder will be generated. At present, the system will record the execution log by task, which makes it convenient for users to check the execution of each task.

3. Browser opens http:// native IP:9000 to enter the background

Use the console program as the carrier

Click to run Ywdsoft.Test.exe

Introduction to the use of background management program

1. Custom site Port

Modify Config.config file. The default port is 9000.

two。 Edit interface how to fill in Cron expressions

It is also considered here that you can use the online Cron generator to generate the address http://tool.myscloud.cn, or you can use the Cron provided in the source code to deploy your own site.

3. Others can be explored on their own.

The above is how to use Nancy to build a TaskManager2.0 management system. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report