예제 #1
0
        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]);
        }
예제 #2
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);
        }
예제 #3
0
        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);
        }
예제 #4
0
		public UnixWbemObjectQualifierSet (IUnixWbemClassHandler handler)
		{
			_handler = handler;
		}
예제 #5
0
		public override IUnixWbemClassHandler InvokeMethod (string methodName, IUnixWbemClassHandler obj)
		{
			return base.InvokeMethod (methodName, obj);
		}
예제 #6
0
 public override IUnixWbemClassHandler InvokeMethod(string methodName, IUnixWbemClassHandler obj)
 {
     return(base.InvokeMethod(methodName, obj));
 }
예제 #7
0
		internal UnixWbemClassObject (IUnixWbemClassHandler handler)
		{
			_handler = handler;
		}
예제 #8
0
        public static UnixWbemClassObject ToManaged(IntPtr pUnk)
        {
            IUnixWbemClassHandler handler = (IUnixWbemClassHandler)Marshal.GetObjectForIUnknown(pUnk);

            return(new UnixWbemClassObject(handler));
        }
예제 #9
0
 internal UnixWbemClassObject(IUnixWbemClassHandler handler)
 {
     _handler = handler;
 }
예제 #10
0
 /// <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;
 }
예제 #12
0
 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])));
 }