TaskHosting, hosting

Source: Internet
Author: User

TaskHosting, hosting
Origin

I often write some gadgets that I like to develop. These gadgets are mainly functional and do not require beautiful and personalized UIS. But at least ensure convenient use, so the most basic functions should be:

  • GUI (image User Interface)
  • Saving and reading program configurations (making it easier for users to operate on the GUI)
  • Automatic record of user habits (for example, window position and size when the last close)
  • Program crash capture and reporting
  • Real-time display of running logs (where is the current execution and what is the output)
  • Multi-thread management and scheduling framework

If every tool needs to COPY the code of the above functions, it will be a big pitfall to be maintained and encapsulated into library calls? Every tool needs to write the code that assembles the UI component once.

Think about it carefully. In fact, what I want to write is a small tool, which focuses on implementation functions.

Then I need a development framework that enables me to focus only on the implementation of functions (businesses) and simplify UI-related coding. It is best to implement a UI function with one line of code, this development framework is now ready. I will name it TaskHosting.

TaskHosting first Knowledge

Let's take a look at what it looks like ~ _~

Most of the uis on the TaskHosting interface can be customized. In most cases, you only need 2-3 lines of C # code to customize some UI functions, if you do not use WPF, you can also use WinForms to customize the UI (via WindowsFormsHost ).

Of course, our goal is not to care about the UI and focus on function implementation. Let's take a look at how to use it.

Start with Hello Word:

Run the program as follows:

How about it, isn't it easy?

Functions

Currently, TaskHosting provides the following functions:

  • Powerful log Functions
    • Real-time logs output to the UI can also be saved to files, databases, or even remote servers.
    • Program crash automatically records exceptions
    • Real-time logs can be filtered and displayed by log level (tracking, debugging, information, warning, error, and fatal)
    • Dedicated File and log analysis tools are available
  • Convenient configuration and access
    • Each task can have its own configuration file.
    • Automatic Reading and saving of configuration files
    • Configuration items can restrict data types and support drag and drop
    • Detailed description of configuration items
  • Automatic Recording of usage habits
    • Re-opening the software will restore the last selected task, window size, location, etc.
  • Crash capture and reporting
    • Automatically capture unprocessed exceptions and display a friendly error handling window
    • Unhandled exceptions can be automatically reported to servers, sent emails, or handled by users
  • Multi-thread scheduling framework
    • Optimized thread scheduling framework to maximize the use of system resources
    • Task determines whether to enable multithreading.
  • More features are still being improved...

The above functions can be customized flexibly. TaskHosting's goal is concise but not simple.

Design Concept

TaskHosting is a [task] Manager (inherited from Mondol. taskHosting. A Task class is a Task. Each Task corresponds to a function, such as a website collection Task and a data synchronization Task.

The class of the [task] comes from the class library project you wrote (hereinafter referred toPlug-ins), Each plug-in can contain multiple tasks.

 

Refer to the HelloWordTask class above. It inherits Mondol. TaskHosting. Task. Therefore, it is a Task and will be displayed in the [Task:] list in the future.

You can use the Task attribute to specify the Task name, whether multithreading is supported, and how to configure the class type.

Ubiquitous dependency Injection

Dependency injection is a simple concept. For example, ClassA depends on ClassB and ClassB depends on ClassC. The traditional hard coding method is to first generate ClassB and ClassC to create ClassA.

The dependency injection framework manages this dependency. When using this dependency, you do not need to care who depends on it. Instead, you only need to tell the framework that I need the ClassA instance and it will automatically create it for you.

Detailed dependency injection overview there are many articles on the Internet. You can just find them.

TaskHosting uses Autofac to manage dependencies between modules. TaskHosting supports three types of registration:

  • Code registration
    // Equivalent to the class to which the Main method of the program belongs (will be detailed later) internal class Initializer: IInitializer {public void ConfigureServices (ContainerBuilder builder) {// register builder in Autofac mode. registerType <Config> (). asSelf ();}}
  • Property Registration
    // Through Property Injection, you can specify whether the Singleton, Scope [Injection (AsType = typeof (Config), IsSingleInstance = true, Scope = InjectionScope. running)] class Config {// class implementation ...}
  • Automatic Registration
    All classes that implement the ITaskConfig interface are automatically registered as Singleton instances. For example:
    Class Config: Mondol. Configuration, ITaskConfig {// class implementation ...}

In addition to the types registered by the plug-in, the framework also registers some interfaces for the plug-in, for example:

  • IAppEnvironment // APP Environment
  • IEventManager // event manager
  • IImmediateLogger // real-time log output interface

For more interfaces, see Mondol. TaskHosting. Abstractions. dll Assembly. This Assembly contains all interface definitions, and the interfaces in it can be obtained through dependency injection in the future.

Summary

The above briefly introduces the concept and basic usage of TaskHosting, so that you can focus more on the development of functional services without worrying too much about the UI implementation details.

Some advanced usage methods and examples will be detailed in the future.

 

If you have any comments or questions during use, please feel free to send them to Q46029811.

The sample code mentioned above: Click to download

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.