ORMi 1.0.2
See the version list below for details.
dotnet add package ORMi --version 1.0.2
NuGet\Install-Package ORMi -Version 1.0.2
<PackageReference Include="ORMi" Version="1.0.2" />
paket add ORMi --version 1.0.2
#r "nuget: ORMi, 1.0.2"
// 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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
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 | 172,282 | 10/18/2021 |
3.1.1 | 4,061 | 1/2/2021 |
3.1.0 | 454 | 12/2/2020 |
3.0.0 | 1,690 | 11/27/2020 |
2.7.0 | 483 | 11/4/2020 |
2.6.0 | 442 | 11/2/2020 |
2.5.8 | 877 | 6/17/2020 |
2.5.7 | 2,854 | 4/6/2020 |
2.5.6 | 923 | 3/31/2020 |
2.5.5 | 1,506 | 10/23/2019 |
2.5.4.3 | 1,026 | 9/24/2019 |
2.5.4.2 | 294 | 9/20/2019 |
2.5.3 | 345 | 8/10/2019 |
2.5.1.2 | 566 | 7/1/2019 |
2.5.0 | 606 | 6/24/2019 |
2.0.0 | 653 | 4/8/2019 |
1.5.0 | 585 | 4/5/2019 |
1.4.2 | 712 | 2/11/2019 |
1.4.1 | 696 | 1/17/2019 |
1.4.0 | 722 | 1/1/2019 |
1.3.4.2 | 698 | 11/30/2018 |
1.3.4 | 683 | 10/25/2018 |
1.3.3 | 855 | 8/14/2018 |
1.3.2 | 911 | 7/16/2018 |
1.3.1 | 906 | 6/27/2018 |
1.3.0 | 944 | 6/25/2018 |
1.2.2 | 890 | 6/19/2018 |
1.2.1 | 872 | 6/17/2018 |
1.0.2 | 883 | 6/13/2018 |
1.0.1 | 1,076 | 6/12/2018 |
MIT License Add