WMI Series 8: Standardize your application

xiaoxiao2021-03-06  68

Standardize your own app

As we have learned to manage a variety of management objects, in the next section, we will learn to regulate your application, so that we will comply with WMI specification Tools such as Microsoft Application Center or Microsoft Operations Manager manage our app. This section will use the class object provided by the System.Management.instrumentation namespace to standardize the application.

Standardize the application method

In order to make our own application or the final published application product compliant with WMI specification, use management tools or programming clients to manage objects in these applications, so that these manageable objects are disclosed to WMI, making Register the WMI repository after installing and running the application. There are two ways of public management objects, and the management events and public data are disclosed.

Public management events. Regarding the definition and role of the event, the programmer can be manageable to make the application, the programmer can set some conditions in the application, and a management event will be triggered when these conditions are met, and then notify the event. The subscriber apps happened, these events are all kinds, or they can be insufficient disk space, or some important data in our own application is modified.

System.Management.instrumentation Namespace provides two classes for public management events:

n InstrumentationClass (InstrumentationType.event) Properties tag class to identify it as a management event;

n BaseEvent: From this class derived class to identify it as a management event rather than using properties, it is recommended to use this method.

After setting the event class, you want to trigger the event to call the instructionation.fire () method.

Public management data. Usually, it is not only an event trigger and notification, but also the management client may also need to access some of the data or even methods of the management object, so public management data is almost indispensable for WMI standardization applications. System.Management.instrumentation Namespaces also provide two ways to require public data:

n Use the InstrumentationClass (InstrumentationType.instance property to mark the class of the public data;

n Detects the class of public data from the Instance class.

Through the method of the above method, the most important task has been completed, and the rest is to register the WMI repository for this standardized application architecture. The architecture of the publishing application is essential for WMI standardized applications. Fortunately, the .NET framework provides our developers with standard program installation mechanisms, and can easily complete the architecture release.

The work we have to do is to customize the installation item for the application, install the custom installer in the default call program to complete the release of the architecture. This should be used to use the default management installer category provided in System.Management.Instrument, you only need to derive it, do not need to rewrite any implementation:

[System.componentmodel.runinstaller (TRUE)]

Public Class MyInstaller: defaultManagementProjectInstaller {}

Development example

Below I will give a specific application development instance, show the method of disclosed data and open events, and give the management client call, of course you can also in the Server Explorer WMI events and WMI classes see published WMI classes and query management events. *********************************************************** ***

// Application release

Using system;

Using system.management.instrument;

Using system.configuration.install;

Using system.collections;

/ / Specify the WMI namespace released by the application

[Assembly: Instrument ("root / default")]]

[System.componentmodel.runinstaller (TRUE)]

Public Class MyInstaller: defaultManagementProjectInstaller {}

Namespace InstrumentationMyapp

{

InstrumentationClass (InstrumentationType.event)]

Public Class EventClass, PUBLIC CLASS EventClass

{

Public evenetclass (int eventflag)

{

Eventflag = eventflag;

INSTRUMENTATION.FIRE (THIS);

}

Public int evenetflag;

Static void main (string [] args)

{

INT Eventflag = 100;

EventClass mybabyevt = new eventclass (eventflag);

Console.writeline ("EventClass Event Trigger");

UniqueClass myclass = new uniqueClass ();

Myclass.name = "unique";

Myclass.description = "this is unique";

Instrumentation.publish (myclass);

Console.writeline ("has been published in the data class");

Console.readline ();

// cancel release

Instrumentation.revoke (MyClass);

}

}

InstrumentationClass (InstrumentationType.instance)]

Public Class UniqueClass

{

Public String Name;

PUBLIC STRING DESCRIPTION;

// Since the collection class cannot be released, ignore the attribute

[Ignoremember]

Public system.collections.Arraylist Employeelist;

}

}

*********************************************************** ***

Newly built a blank C # project, enter the code described above, complete the application, to publish the application and test the results, and you need to make the installer. Follow these steps:

1) Add item-> New project, select the installation item, enter the project name;

2) Switch to the file system view, right-click below the application folder;

3) Select the main output in the output dialog;

4) Compilation and installation project;

转载请注明原文地址:https://www.9cbs.com/read-109228.html

New Post(0)