Git Product home page Git Product logo

ormi's People

Contributors

anetre avatar chucker avatar ewisted avatar kevwkev avatar nicoriff avatar ssewell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ormi's Issues

System.Management compatibility

Getting some "ORMi 3.1.1 requires System.Management (= 4.6.0) but version System.Management 5.0.0 was resolved"

Possible to lift the supported version for System.Management?

Best regards

Adding caching and performance improvements to the mapping and reflection

An immediate performance improvement would be to cache the PropertyInfo and setter as a delegate and the attributes for the target POCO, like how HyperDescriptor or FastMember or Fasterflect and the ORM Entity Framework does it.

I'm writing a library that is using some heavy hitting WMI queries and it's the mapping part that's adding a time delay. In my particular business case it goes from .002 to .05 for a particular operation. It's not bad from a human user perspective but it would be nice to keep it in the thousandths of a second range for the operation, because in my particular use case and code architecture I can't use an event watcher and have to run my operation in a tight blocking loop.

Although I don't know how to improve iterating over ManagementObjectCollection. That also adds a heavy delay but that's just WMI. Someone suggests using ManagementClass on MSDN. Also maybe analyzing the target POCO and removing irrelevant properties from the query automatically may be of some use, but the consumer can already handle that.

Implement IDisposable pattern in WMIWatcher class

The class WMIWatcher contains a field ManagementEventWatcher that is disposable.

It's possible change WMIWatcher to dispose the ManagementEventWatcher field and stop watcher for new events when the object WMIWatcher is finalized?

Plans to migrate to Microsoft.Management.Infrastructure namespace?

I love this project. It really makes WMI much easier to use in C#. However, I was wondering if there are any plans to migrate the project to start using the Microsoft.Management.Infrastructure namespace instead of System.Management. Here is what Microsoft has to say about the choice between the two:

System.Management was the original namespace that covered managed code for WMI. However, the underlying technology for System.Management is generally slower than, and does not scale as well as, Microsoft.Management.Infrastructure. As such, it is not recommended that you use System.Management for new projects.

https://docs.microsoft.com/en-us/previous-versions/hh872326(v=vs.85)

Conversion fails for Nullable ValueType

It seems Convert.ChangeType at L76 of TypeHelper chokes on a nullable value type when the value is null. Since a null value will result in default value of property anyway, we can do an early return out of _SetPropertyValue and not run into an InvalidCastException.

Property tested: IPConnectionMetric as unit? on NetworkAdapterConfiguration

StackTrace:

   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at ORMi.Helpers.TypeHelper.LoadObject(ManagementObject mo, Type t)
   at ORMi.WMIHelper.Query[T]()
   at UserQuery.Main()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Proposed fix @L76: Simplify to p.SetValue(o, a, null);

Is there a specific scenario that you're using Convert.ChangeType for? IMHO, if there's a mismatch of types between what WMI was expecting and what end-user wanted, end-user should be doing an explicit cast rather than the library.

It might be worth looking into a Converter attribute for more custom behaviour like going from a string IPAddress to IPAddress. I've done something similar in my powershell-converter repo for the same reason: Serialize & Deserialize

Thank you very much for your work. This makes working with WMI much more pleasant.

Can't run code on linux

If i publish app on linux server i get System.Management currently is only supported for Windows desktop applications.

Call static method without an instance

I may be reading the documentation incorrectly but in the example, for executing a static method you are using a namespace that has instances. I'm trying to call a static method on a WMI class that has only a single static method and nothing else. If I try to use helper.query, I don't get anything back since there are no instances so I don't have a way to make the method call. I know I'm missing something obvious but it escapes me at the moment.

Can't use async query with Helper

Hi and thank you for your work.
i try to use Ormi with async query like that:

[WMIClass("Win32_Processor")]
  public class Processor : WMIInstance
  {
      public string Name { get; set; }
      [WMIProperty("NumberOfCores")]
      public int Cores { get; set; }
      public string Description { get; set; }
  }

WMIHelper helper = new WMIHelper("root\\CimV2", host, account, password);
List<Processor> processors = await helper.QueryAsync<Processor>().ToList();
...

but i got Compiler Error CS1061 with msg like: Task<IEnumerable<Form1.Processor>> no definition for ToList()...
is anybody have a idea to fix that ?

Win32_Process create method

Can you help me with creating process with ORMi?
Something like this?

[WMIClass("Win32_Process")] public class Win32_Process : WMIInstance { public dynamic Create(string commandLine, string currentDirectory, dynamic data, dynamic result) { return WMIMethod.ExecuteMethod(this,commandLine,currentDirectory,data,result); } }

WMI cannot return the result, please help, thank you

I use WMI to get information on a remote computer, If use Administrator, both of the following queries can return data。

SELECT * FROM Win32_DiskDrive,
SELECT * FROM Win32_NTLogEvent

If use a non-Administrator account, the data can be returned first.The second one returns zero data, I guess it is the problem of the remote computer setting, but I don't know how to do it specifically. Please help me, thank you

Cannot access namespace "TerminalServices" remotely (Access Denied)

Hi,

This is what I try to do:

WMIHelper helper = new WMIHelper("root\CimV2\TerminalServices", "10.0.0.1", "contoso\user", "Hello");
List remoteApps = helper.Query().ToList();

System.Management.ManagementException
HResult=0x80131501
Message=Access denied
Source=System.Management
StackTrace:
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObjectSearcher.Get()
at ORMi.WMIHelper.QueryT

This is the cause of the issue:

To connect to the Root\CIMV2\TerminalServices namespace, the authentication level must include packet privacy. For C/C++ calls, this is an authentication level of RPC_C_AUTHN_LEVEL_PKT_PRIVACY.
https://docs.microsoft.com/en-us/windows/win32/termserv/win32-terminalservicesetting?redirectedfrom=MSDN

Can you support packet privacy scenario?

Thanks!

[BUG] Querying classes with property of type ManagementBaseObject[]

There is an unhandled case of mapping using the IWMIHelper : when the result contain an array of ManagementBaseObject.
I faced an error when I was querying "WmiMonitorListedSupportedSourceModes" (https://docs.microsoft.com/en-us/windows/win32/wmicoreprov/wmimonitorlistedsupportedsourcemodes). The class contain an array of "VideoModeDescriptor" but the mapping cannot be done in the "_SetPropertyValue" function because there isn't a case for "ManagementBaseObject[]".

.NET framework 4

Not working under .NET Fr. 4?? What? o_O?
Why you supports only 4.6.1?
If no any variants to resolve this problem, I just will write mine custom wmi-classes. If you can't use WMI on XP/old Win Server and Framework 4, for what this ORM?

Remote machine

Can ORMi access WMI remotely?

WmiLight code, as an example:

var cred = new NetworkCredential("USERNAME", "PASSWORD", "DOMAIN");

using (WmiConnection con = new WmiConnection(@"\\MACHINENAME\root\cimv2", cred, opt))
{
    foreach (WmiObject partition in con.CreateQuery("SELECT * FROM Win32_DiskPartition"))
    {
        Console.WriteLine(partition["Name"]);
    }
}

Method Name is incorrect

When attempting to use WMIMethod.ExecuteMethod with parameters. The wrong method name is selected and the calling method name is used instead.

 [WMIClass("Win32_NetworkAdapterConfiguration")]
    public class NetworkAdapterConfiguration
    {
        public string Caption { get; set; }
        public string Description { get; set; }

        public UInt32 InterfaceIndex { get; set; }

        public bool SetStatic(string ip, string netmask)
        {
            int retVal = WMIMethod.ExecuteMethod(this, new {IPAddress = new string[] {ip}, SubnetMask = new string[] {netmask}});

            if(retVal != 0)
                Console.WriteLine($"Failed to set network settings with error code {retVal}");

            return retVal == 0;
        }
    }
void SetupInterfaces(){
 var interfaces = helper.Query<NetworkAdapterConfiguration>()

foreach(var interface in interfaces){
    interface.SetStatic("123.123.123.123","255.255.255.0");
}
}

SetupInterface ends up being selected as the MethodName instead of SetStatic.

Issue with getting the property DelayedAutoStart on Win32_Service and Windows Server 2012R2

Hi!

Doing this crashes with an exception "Invalid Query" on Windows Server 2012R2 but works fine on Windows Server 2016:
servicesTask = _wmiHelper.QueryAsync();

Service look like this:

[WMIClass("Win32_Service")]
public class Service : WMIInstance
{
    public string Name { get; set; }
    public string DisplayName { get; set; }
    public string StartMode { get; set; }
    public string State { get; set; }
    public string Description { get; set; }
    public bool DelayedAutoStart { get; set; }
    public string StartName { get; set; }
    public string PathName { get; set; }
}

If I instead query like this servicesTask = _wmiHelper.QueryAsync("SELECT * FROM Win32_Service"); it works but the dynamic objects returned doesn't contain the property "DelayedAutoStart" running on Windows Server 2012R2 but running it in 2016 includes the property though. In Windows Server 2012R2 the services can be set to Automatic and with delayed start though.

BR

Knekten

System.InvalidCastException: Object must implement IConvertible

I ran across this exception when trying to query for a WMI object with other WMI objects as properties. The specific instance is Win32_UserProfile.

As you can see in the docs, it has properties of Win32_FolderRedirectionHealth. My first thought was to treat it like you would serializing an object from JSON, where you have the properties as follows-

[WMIClass(Name = "Win32_UserProfile", Namespace = "root\\CimV2")]
    public class UserProfile
    {
        public string SID { get; set; }
        public string LocalPath { get; set; }
        public bool Loaded { get; set; }
        [WMIProperty("refCount")]
        public uint RefCount { get; set; }
        public bool Special { get; set; }
        public bool RoamingConfigured { get; set; }
        public string RoamingPath { get; set; }
        public bool RoamingPreference { get; set; }
        public uint Status { get; set; }
        public DateTime LastUseTime { get; set; }
        public DateTime LastDownloadTime { get; set; }
        public DateTime LastUploadTime { get; set; }
        public byte HealthStatus { get; set; }
        public DateTime LastAttemptedProfileDownloadTime { get; set; }
        public DateTime LastAttemptedProfileUploadTime { get; set; }
        public DateTime LastBackgroundRegistryUploadTime { get; set; }
        public FolderRedirectionHealth AppDataRoaming { get; set; }
        public FolderRedirectionHealth Desktop { get; set; }
        public FolderRedirectionHealth StartMenu { get; set; }
        public FolderRedirectionHealth Documents { get; set; }
        public FolderRedirectionHealth Pictures { get; set; }
        public FolderRedirectionHealth Music { get; set; }
        public FolderRedirectionHealth Videos { get; set; }
        public FolderRedirectionHealth Favorites { get; set; }
        public FolderRedirectionHealth Contacts { get; set; }
        public FolderRedirectionHealth Downloads { get; set; }
        public FolderRedirectionHealth Links { get; set; }
        public FolderRedirectionHealth Searches { get; set; }
        public FolderRedirectionHealth SavedGames { get; set; }
    }

And for the properties model, it would look like this-

[WMIClass(Name = "Win32_FolderRedirectionHealth", Namespace = "root\\CimV2")]
    public class FolderRedirectionHealth
    {
        public string OfflineFileNameFolderGUID { get; set; }
        public bool Redirected { get; set; }
        public bool OfflineAccessEnabled { get; set; }
        public DateTime LastSuccessfulSyncTime { get; set; }
        public DateTime LastSyncTime { get; set; }
        public byte LastSyncStatus { get; set; }
        public byte HealthStatus { get; set; }
    }

Using this data model and passing UserProfile as a type parameter to QueryAsync results in the following exception-

System.InvalidCastException: Object must implement IConvertible.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType)
   at ORMi.Helpers.TypeHelper._SetPropertyValue(ManagementBaseObject mo, PropertyInfo p, Object o)
   at ORMi.Helpers.TypeHelper.LoadObject(ManagementObject mo, Type t)
   at ORMi.WMIHelper.QueryFirstOrDefault[T](String query)
   at ORMi.WMIHelper.<>c__DisplayClass28_0`1.<QueryFirstOrDefaultAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ORMi.WMIHelper.<QueryFirstOrDefaultAsync>d__28`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at servicedesk_tools.Services.Implementations.RemoteSessionService.<IsUserLoggedIn>d__1.MoveNext() in C:\Users\EricWi\Source\Repos\servicedesk-tools\servicedesk-tools\Services\Implementations\RemoteSessionService.cs:line 103
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at servicedesk_tools.UnitTests.RemoteSessionServiceIntegrationTests.<IsUserLoggedInSingleServerTest>d__3.MoveNext()

I've already forked the repo and fixed this with a little recursion, but I was wondering if this is a known issue or a design choice that this functionality was left out? Or is there a better way built in to handle this that I don't know about?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.