ORMi 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package ORMi --version 1.0.2
NuGet\Install-Package ORMi -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ORMi" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ORMi --version 1.0.2
#r "nuget: ORMi, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ORMi as a Cake Addin
#addin nuget:?package=ORMi&version=1.0.2

// Install ORMi as a Cake Tool
#tool nuget:?package=ORMi&version=1.0.2

ORMi (Object Relational Management Instrumentation)

ORMi is a quite simple Light-ORM to work with WMI (Windows Management Instrumentation). It handles WMI CRUD operations in a very easy way. ORMi does automatic mapping to model clases so you can easily work with WMI classes without having to worry about writing complex queries and handling WMI connections.

Getting Started

ORMi is available via NuGet. Also, you can always download the latest release on https://github.com/nicoriff/ORMi/releases/.

Once downloaded, you need to add the reference to the library on your project.

How to Use

ORMi is just too easy to work with. Let´s for example suppose we want to access 'root\CIMV2' namespace to get the some information about our computer proccesors. First of all, we need to use the library:

using ORMi;

Then, we´ll define the following class:

    [WMIClass("Win32_Processor")]
    public class Processor
    {
        public string Name { get; set; }

        [WMIProperty("NumberOfCores")]
        public int Cores { get; set; }

        public string Description { get; set; }
    }

ORMi has some custom attributes to map the model clases to WMI classes. WMI classes usually have tricky or non conventional names that you will for sure not want to use on your class. For solvig that problem ORMi just maps the class property name to the WMI property name. If you do not want to use the WMI property name then you can just specify the WMIProperty attribute ant put the name of the WMI property. The same run for class names. In that case you can make use of WMIClass.

Then if we want to get the machine processors you just do:


    WMIHelper helper = new WMIHelper("root\\CimV2");

    List<Processor> processors = helper.Query<Processor>().ToList();

For adding, updating and deleting instances we are going to use a custom namespace and classes. In this example the namespace is 'root\EmployeesSystem'. And we have the following class defined:

    [WMIClass("Lnl_Person")]
    public class Person
    {
        public string Lastname { get; set; }
        public string FirstName { get; set; }

        [WMIProperty( Name = "SSNO", SearchKey = true)]
        public string DocumentNumber { get; set; }

        [WMIProperty("PRIMARYSEGMENTID")]
        public int Segment { get; set; }
    }

Examples:

Add Instance:

	 Person person = new Person
	 {
	     FirstName = "John",
	     Lastname = "Doe",
	     DocumentNumber = "9995",
	     Segment = -1
	 };

	 helper.AddInstance(person);

Update Instance:

For the Update operation, the class must have the WmiProperty attribute declared with the SearchKey property properly set to true. This will use the property with the SearchKey to get the instance that is going to be updated. For example:

      Person person= helper.Query<Person>("SELECT * FROM Lnl_Cardholder WHERE LASTNAME = 'Doe'").SingleOrDefault();

      person.Lastname = "Doe Modified";

      helper.UpdateInstance(person);

In the above example, ORMi is going to look for the person with SSNO = 9995 and update that instance with the properties set on person instance.

Remove Instance:

As in the update operation, the removal works with the SearchKey property set or manually specifying a query. In both cases, the result will be removed:

	Person p = helper.Query<Person>("SELECT * FROM Lnl_Cardholder WHERE LASTNAME = 'Doe'").SingleOrDefault();
	helper.RemoveInstance(p);

Creating an WMI Event Watcher:

Creating a watcher is one of the simplest tasks in ORMi. Just declare the watcher specifying scope, query and the desired output type and that´s it!. Start receiving events!. In this example we are going to watch for new processes created on the system:

First, we define the class:

    [WMIClass("Win32_ProcessStartTrace")]
    public class Process
    {
        public string ProcessName { get; set; }
        public int ProcessID { get; set; }
    }

Then subscribe for events...

	WMIWatcher watcher = new WMIWatcher("root\\CimV2", "SELECT * FROM Win32_ProcessStartTrace", typeof(Process));
	watcher.WMIEventArrived += Watcher_WMIEventArrived;

Or if you have WMIClass attribute set:

	WMIWatcher watcher = new WMIWatcher("root\\CimV2", typeof(Process));
	watcher.WMIEventArrived += Watcher_WMIEventArrived;

And then, just handle the events...

    private static void Watcher_WMIEventArrived(object sender, WMIEventArgs e)
    {
        Process process = (Process)e.Object;

        Console.WriteLine("New Process: {0} (Pid: {1})", process.ProcessName, process.ProcessID.ToString());
    }
Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.2.0.1 104,182 10/18/2021
3.1.1 3,820 1/2/2021
3.1.0 423 12/2/2020
3.0.0 1,660 11/27/2020
2.7.0 449 11/4/2020
2.6.0 413 11/2/2020
2.5.8 846 6/17/2020
2.5.7 2,813 4/6/2020
2.5.6 893 3/31/2020
2.5.5 1,408 10/23/2019
2.5.4.3 983 9/24/2019
2.5.4.2 278 9/20/2019
2.5.3 328 8/10/2019
2.5.1.2 537 7/1/2019
2.5.0 572 6/24/2019
2.0.0 625 4/8/2019
1.5.0 555 4/5/2019
1.4.2 676 2/11/2019
1.4.1 667 1/17/2019
1.4.0 695 1/1/2019
1.3.4.2 664 11/30/2018
1.3.4 652 10/25/2018
1.3.3 820 8/14/2018
1.3.2 872 7/16/2018
1.3.1 874 6/27/2018
1.3.0 909 6/25/2018
1.2.2 861 6/19/2018
1.2.1 844 6/17/2018
1.0.2 848 6/13/2018
1.0.1 1,030 6/12/2018

MIT License Add