Пример #1
0
            public TypeInfo(EventSource source, SchemaNaming naming, Type t)
            {
                this.toWMI = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[t];
                this.toNET = (ConvertFuncToNET)InstrumentedAssembly.mapTypeToToNETFunc[t];
                this.t     = t;
                isSTA      = Thread.CurrentThread.ApartmentState == ApartmentState.STA;
                ManagementClass eventClass = new ManagementClass(naming.NamespaceName + ":" + ManagedNameAttribute.GetMemberName(t));
                PropertyInfo    prop       = typeof(ManagementBaseObject).GetProperty("WmiObject", BindingFlags.Instance | BindingFlags.NonPublic);

                ManagementObject evt = eventClass.CreateInstance();

                obj         = (IWbemClassObject_DoNotMarshal)prop.GetValue(evt, null);
                this.source = source;


                SetBatchSize(batchSize);

                IWbemClassObject_DoNotMarshal obj2;

                obj.Clone_(out obj2);
                xoa1[0] = (IWbemObjectAccess)obj2;
                oa1test = new ClassObjectArray(xoa1);

                writeDWORD1 = new WriteDWORD(xoa1[0].WriteDWORD_);
                writeQWORD1 = new WriteQWORD(xoa1[0].WriteQWORD_);

#if xxx
                string             code       = CodeSpit.Spit(t, xoa1[0]);
                CSharpCodeProvider provider   = new CSharpCodeProvider();
                ICodeCompiler      compiler   = provider.CreateCompiler();
                CompilerParameters parameters = new CompilerParameters();
                parameters.GenerateInMemory = true;

                parameters.ReferencedAssemblies.Add(t.Assembly.Location);
                parameters.ReferencedAssemblies.Add(typeof(WriteDWORD).Assembly.Location);
                parameters.ReferencedAssemblies.Add(typeof(Event).Assembly.Location);
                CompilerResults results = compiler.CompileAssemblyFromSource(parameters, code);
                foreach (CompilerError err in results.Errors)
                {
                    Console.WriteLine(err.ToString());
                }
                Type dynType = results.CompiledAssembly.GetType("Hack");

                MethodInfo doit = dynType.GetMethod("Func");

                managedToIWbem = (ManagedToIWbem)Delegate.CreateDelegate(typeof(ManagedToIWbem), doit);
#endif
            }
Пример #2
0
            public void SetBatchSize(int batchSize)
            {
                if (!WMICapabilities.MultiIndicateSupported)
                {
                    batchSize = 1;
                }
                lock (this)
                {
                    if (currentIndex > 0)
                    {
                        source.pSink.Indicate_(currentIndex, oatest.realPointer);
//                        Indicate(3, source.ipSink, currentIndex, oatest.realPointer);
                        currentIndex = 0;
                        lastFire     = Environment.TickCount;
                    }
                    if (batchSize > 1)
                    {
                        batchEvents    = true;
                        this.batchSize = batchSize;

                        xoa = new IWbemObjectAccess[batchSize];

                        writeDWORD = new WriteDWORD[batchSize];
                        writeQWORD = new WriteQWORD[batchSize];
                        IWbemClassObject_DoNotMarshal obj2;
                        for (int i = 0; i < batchSize; i++)
                        {
                            obj.Clone_(out obj2);
                            xoa[i]        = (IWbemObjectAccess)obj2;
                            writeDWORD[i] = new WriteDWORD(xoa[i].WriteDWORD_);
                            writeQWORD[i] = new WriteQWORD(xoa[i].WriteQWORD_);
                        }
                        oatest = new ClassObjectArray(xoa);
                    }
                    else
                    {
                        batchEvents = false;
                    }
                }
            }