public static IEnumerable <IWbemClassObject_DoNotMarshal> Get(string nameSpace, string strQuery) { strQuery = Regex.Replace(strQuery, "Win32", "UNIX", RegexOptions.IgnoreCase); strQuery = Regex.Replace(strQuery, "unix_", "UNIX_", RegexOptions.IgnoreCase); var tableName = GetClassNameFromQuery(strQuery); var doc = Document; if (doc != null) { XmlNode node = doc.SelectSingleNode(string.Format("//*/Namespace[@Name='{0}']/Class[@Name='{1}']", nameSpace, tableName)); if (node != null) { /* Look for static object MOF reference */ /* This is a dynamic object */ Type type = Type.GetType(node.Attributes["Type"].Value, false, true); if (type != null) { if (!type.IsClass) { throw new InvalidDataException("Invalid class"); } else if (type.IsAbstract) { //Find First Declarative Type in Derivation of {type} var fallbackNamespaceNode = node.Attributes["FallbackNamespace"]; var fallbackClassNode = node.Attributes["FallbackClass"]; if (fallbackClassNode != null) { string fallbackNamespace = nameSpace; if (fallbackNamespaceNode != null) { fallbackNamespace = fallbackNamespaceNode.Value; if (fallbackNamespace.Equals(nameSpace, StringComparison.OrdinalIgnoreCase) && fallbackNamespaceNode.Value.Equals(tableName, StringComparison.OrdinalIgnoreCase)) { throw new InvalidDataException("Circular Dependency failed on Abstract CMI Class"); } return(Get(nameSpace, fallbackNamespaceNode.Value)); } else { // Launch Declarative Type Discovery throw new InvalidDataException("Invalid class"); } } } else { IUnixWbemClassHandler handler = GetHandler(type); return(handler.Get(strQuery).Select(x => new UnixWbemClassObject((IUnixWbemClassHandler)x))); } } } } return(new IWbemClassObject_DoNotMarshal[0]); }
public static IUnixWbemClassHandler GetHandler(Type type) { if (type.IsAbstract) { MetaImplementationAttribute att = type.GetCustomAttribute <MetaImplementationAttribute>(true); if (att != null) { IUnixWbemClassHandler metaHandler = (IUnixWbemClassHandler)Activator.CreateInstance(att.ImplementationType, true); return(metaHandler); } } IUnixWbemClassHandler handler = (IUnixWbemClassHandler)Activator.CreateInstance(type, true); return(handler); }
public object Get(object nativeObj) { var obj = nativeObj as UnixMetaClass; Type targetType = Type.GetType(obj.ImplementationType, false, true); if (targetType != null) { IUnixWbemClassHandler targetHandler = WMIDatabaseFactory.GetHandler(targetType); foreach (var p in targetHandler.PropertyInfos) { RegisterProperty(p.Name, p.Type, p.Flavor); _prop.Add(p.Name, null); } foreach (var qualifierName in targetHandler.QualifierNames) { _qualifiers.Add(qualifierName, targetHandler.GetQualifier(qualifierName)); } foreach (var method in targetHandler.Methods) { AddMethod(method.Name, method); } } if (obj != null) { _prop.Add("__GENUS", 1); _prop.Add("__SERVER", System.Net.Dns.GetHostName().ToLower()); _prop.Add("__NAMESPACE", obj.Namespace); _prop.Add("__UID", obj.Id); _prop.Add("__CLASS", obj.ClassName); _prop.Add("__IMPLEMENTATION_TYPE", obj.ImplementationType); _prop.Add("__DERIVATION", GetDerivations(targetType)); _prop.Add("__PATH", string.Format("//{0}/{1}/{2}/{3}=\"{4}\"", _prop ["__SERVER"], _prop ["__NAMESPACE"], "META_CLASS", PathField, _prop [PathField])); _prop.Add("__RELATIVE_PATH", string.Format("{0}/{1}=\"{2}\"", _prop ["__CLASS"], PathField, _prop [PathField])); } return(this); }
public UnixWbemObjectQualifierSet (IUnixWbemClassHandler handler) { _handler = handler; }
public override IUnixWbemClassHandler InvokeMethod (string methodName, IUnixWbemClassHandler obj) { return base.InvokeMethod (methodName, obj); }
public override IUnixWbemClassHandler InvokeMethod(string methodName, IUnixWbemClassHandler obj) { return(base.InvokeMethod(methodName, obj)); }
internal UnixWbemClassObject (IUnixWbemClassHandler handler) { _handler = handler; }
public static UnixWbemClassObject ToManaged(IntPtr pUnk) { IUnixWbemClassHandler handler = (IUnixWbemClassHandler)Marshal.GetObjectForIUnknown(pUnk); return(new UnixWbemClassObject(handler)); }
internal UnixWbemClassObject(IUnixWbemClassHandler handler) { _handler = handler; }
/// <summary> /// Invokes the method. /// </summary> /// <returns> /// The method. /// </returns> /// <param name='obj'> /// Object. /// </param> public virtual IUnixWbemClassHandler InvokeMethod(string methodName, IUnixWbemClassHandler obj) { return(null); }
public UnixWbemObjectQualifierSet(IUnixWbemClassHandler handler) { _handler = handler; }
internal IUnixWbemClassHandler Format(IUnixWbemClassHandler obj) { return(obj.WithProperty("__RELATIVE_PATH", string.Format("{0}/{1}=\"{2}\"", obj.Properties ["__CLASS"], PathField, obj.Properties [PathField])) .WithProperty("__PATH", string.Format("//{0}/{1}/{2}/{3}=\"{4}\"", obj.Properties ["__SERVER"], obj.Properties ["__NAMESPACE"], obj.Properties ["__CLASS"], PathField, obj.Properties [PathField]))); }